diff --git a/db/migrate/20250928180837_create_promotion_codes.rb b/db/migrate/20250928180837_create_promotion_codes.rb index e5ae43f..95e25ec 100644 --- a/db/migrate/20250928180837_create_promotion_codes.rb +++ b/db/migrate/20250928180837_create_promotion_codes.rb @@ -1,7 +1,7 @@ class CreatePromotionCodes < ActiveRecord::Migration[8.0] def change create_table :promotion_codes do |t| - t.string :code, null: false, unique: true + t.string :code, null: false t.integer :discount_amount_cents, null: false, default: 0 t.datetime :expires_at t.boolean :active, default: true, null: false @@ -11,6 +11,7 @@ class CreatePromotionCodes < ActiveRecord::Migration[8.0] t.datetime :updated_at, null: false end + # Unique index for code add_index :promotion_codes, :code, unique: true end end diff --git a/db/schema.rb b/db/schema.rb index 08ebc4a..c47b075 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_09_11_063815) do +ActiveRecord::Schema[8.0].define(version: 2025_09_28_181311) do create_table "events", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| t.string "name", null: false t.string "slug", null: false @@ -25,15 +25,24 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_11_063815) do t.decimal "longitude", precision: 10, scale: 6, null: false t.boolean "featured", default: false, null: false t.bigint "user_id", null: false + t.boolean "allow_booking_during_event", default: false, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.boolean "allow_booking_during_event", default: false, null: false t.index ["featured"], name: "index_events_on_featured" t.index ["latitude", "longitude"], name: "index_events_on_latitude_and_longitude" t.index ["state"], name: "index_events_on_state" t.index ["user_id"], name: "index_events_on_user_id" end + create_table "order_promotion_codes", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| + t.bigint "order_id", null: false + t.bigint "promotion_code_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["order_id"], name: "index_order_promotion_codes_on_order_id" + t.index ["promotion_code_id"], name: "index_order_promotion_codes_on_promotion_code_id" + end + create_table "orders", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| t.bigint "user_id", null: false t.bigint "event_id", null: false @@ -51,6 +60,18 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_11_063815) do t.index ["user_id"], name: "index_orders_on_user_id" end + create_table "promotion_codes", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| + t.string "code", null: false + t.integer "discount_amount_cents", default: 0, null: false + t.datetime "expires_at" + t.boolean "active", default: true, null: false + t.integer "usage_limit" + t.integer "uses_count", default: 0, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["code"], name: "index_promotion_codes_on_code", unique: true + end + create_table "ticket_types", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| t.string "name" t.text "description" @@ -104,4 +125,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_11_063815) do t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + + add_foreign_key "order_promotion_codes", "orders" + add_foreign_key "order_promotion_codes", "promotion_codes" end