wip: order checkout
This commit is contained in:
@@ -8,6 +8,8 @@ class CreateTicketTypes < ActiveRecord::Migration[8.0]
|
||||
t.datetime :sale_start_at
|
||||
t.datetime :sale_end_at
|
||||
t.integer :minimum_age
|
||||
t.boolean :requires_id, default: false, null: false
|
||||
|
||||
t.references :event, null: false, foreign_key: false
|
||||
|
||||
t.timestamps
|
||||
|
||||
20
db/migrate/20250823170409_create_orders.rb
Normal file
20
db/migrate/20250823170409_create_orders.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class CreateOrders < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :orders do |t|
|
||||
t.references :user, null: false, foreign_key: true
|
||||
t.references :event, null: false, foreign_key: true
|
||||
t.string :status, null: false, default: 'draft'
|
||||
t.integer :total_amount_cents, null: false, default: 0
|
||||
t.integer :payment_attempts, null: false, default: 0
|
||||
t.timestamp :expires_at
|
||||
t.timestamp :last_payment_attempt_at
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
# Indexes for performance
|
||||
add_index :orders, [:user_id, :status], name: 'idx_orders_user_status'
|
||||
add_index :orders, [:event_id, :status], name: 'idx_orders_event_status'
|
||||
add_index :orders, :expires_at, name: 'idx_orders_expires_at'
|
||||
end
|
||||
end
|
||||
@@ -9,30 +9,13 @@ class CreateTickets < ActiveRecord::Migration[8.0]
|
||||
t.string :first_name
|
||||
t.string :last_name
|
||||
|
||||
# Implemented to "temporize" tickets
|
||||
# If a ticket is not paid in time, it is removed from the database
|
||||
#
|
||||
t.string :stripe_session_id
|
||||
t.timestamp :expires_at
|
||||
t.integer :payment_attempts, default: 0
|
||||
t.timestamp :last_payment_attempt_at
|
||||
|
||||
t.references :user, null: true, foreign_key: false
|
||||
t.references :ticket_type, null: false, foreign_key: false
|
||||
# Tickets belong to orders (orders handle payment logic)
|
||||
t.references :order, null: false, foreign_key: true
|
||||
t.references :ticket_type, null: false, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :tickets, :qr_code, unique: true
|
||||
add_index :tickets, :user_id unless index_exists?(:tickets, :user_id)
|
||||
add_index :tickets, :ticket_type_id unless index_exists?(:tickets, :ticket_type_id)
|
||||
|
||||
# Add indexes for better performance
|
||||
# add_index :tickets, :first_name unless index_exists?(:tickets, :first_name)
|
||||
# add_index :tickets, :last_name unless index_exists?(:tickets, :last_name)
|
||||
#
|
||||
# add_index :tickets, :stripe_session_id, unique: true
|
||||
# add_index :tickets, [ :status, :expires_at ]
|
||||
# add_index :tickets, [ :user_id, :status ]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
class AddRequiresIdToTicketTypes < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :ticket_types, :requires_id, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
||||
31
db/schema.rb
generated
31
db/schema.rb
generated
@@ -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_08_31_184955) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_09_02_003043) 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
|
||||
@@ -33,6 +33,23 @@ ActiveRecord::Schema[8.0].define(version: 2025_08_31_184955) do
|
||||
t.index ["user_id"], name: "index_events_on_user_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
|
||||
t.integer "total_amount_cents", default: 0, null: false
|
||||
t.string "status", default: "draft", null: false
|
||||
t.integer "payment_attempts", default: 0, null: false
|
||||
t.datetime "expires_at"
|
||||
t.datetime "last_payment_attempt_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["event_id", "status"], name: "index_orders_on_event_id_and_status"
|
||||
t.index ["event_id"], name: "index_orders_on_event_id"
|
||||
t.index ["expires_at"], name: "index_orders_on_expires_at"
|
||||
t.index ["user_id", "status"], name: "index_orders_on_user_id_and_status"
|
||||
t.index ["user_id"], name: "index_orders_on_user_id"
|
||||
end
|
||||
|
||||
create_table "ticket_types", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.text "description"
|
||||
@@ -56,17 +73,13 @@ ActiveRecord::Schema[8.0].define(version: 2025_08_31_184955) do
|
||||
t.string "status", default: "draft"
|
||||
t.string "first_name"
|
||||
t.string "last_name"
|
||||
t.string "stripe_session_id"
|
||||
t.timestamp "expires_at"
|
||||
t.integer "payment_attempts", default: 0
|
||||
t.timestamp "last_payment_attempt_at"
|
||||
t.bigint "user_id"
|
||||
t.bigint "ticket_type_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.bigint "order_id", null: false
|
||||
t.index ["order_id"], name: "index_tickets_on_order_id"
|
||||
t.index ["qr_code"], name: "index_tickets_on_qr_code", unique: true
|
||||
t.index ["ticket_type_id"], name: "index_tickets_on_ticket_type_id"
|
||||
t.index ["user_id"], name: "index_tickets_on_user_id"
|
||||
end
|
||||
|
||||
create_table "users", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
|
||||
@@ -83,4 +96,8 @@ ActiveRecord::Schema[8.0].define(version: 2025_08_31_184955) 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 "orders", "events"
|
||||
add_foreign_key "orders", "users"
|
||||
add_foreign_key "tickets", "orders"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user