:orders do |t| # 外部キー t.references :user, null: false, foreign_key: true t.references :product, null: false, foreign_key: true # 基本情報 t.string :status, null: false, default: 'pending' t.integer :quantity, null: false # 金額情報 t.decimal :unit_price, precision: 10, scale: 2, null: false t.decimal :total_amount, precision: 10, scale: 2, null: false # タイムスタンプ t.timestamps end # インデックス add_index :orders, :status add_index :orders, [:user_id, :created_at] end end