diff --git a/app/models/expense.rb b/app/models/expense.rb index 6da98af..5601c30 100644 --- a/app/models/expense.rb +++ b/app/models/expense.rb @@ -10,8 +10,18 @@ # pricing_type :enum default("fixed"), not null # created_at :datetime not null # updated_at :datetime not null +# wedding_id :uuid not null +# +# Indexes +# +# index_expenses_on_wedding_id (wedding_id) +# +# Foreign Keys +# +# fk_rails_... (wedding_id => weddings.id) # class Expense < ApplicationRecord + acts_as_tenant :wedding enum :pricing_type, fixed: 'fixed', per_person: 'per_person' diff --git a/app/models/group.rb b/app/models/group.rb index fe11e0b..5056b28 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -12,17 +12,22 @@ # created_at :datetime not null # updated_at :datetime not null # parent_id :uuid +# wedding_id :uuid not null # # Indexes # -# index_groups_on_name (name) UNIQUE -# index_groups_on_parent_id (parent_id) +# index_groups_on_name (name) UNIQUE +# index_groups_on_parent_id (parent_id) +# index_groups_on_wedding_id (wedding_id) # # Foreign Keys # # fk_rails_... (parent_id => groups.id) +# fk_rails_... (wedding_id => weddings.id) # class Group < ApplicationRecord + acts_as_tenant :wedding + validates :name, uniqueness: true validates :name, :order, presence: true diff --git a/app/models/guest.rb b/app/models/guest.rb index 40c41be..8983c66 100644 --- a/app/models/guest.rb +++ b/app/models/guest.rb @@ -11,16 +11,20 @@ # created_at :datetime not null # updated_at :datetime not null # group_id :uuid not null +# wedding_id :uuid not null # # Indexes # -# index_guests_on_group_id (group_id) +# index_guests_on_group_id (group_id) +# index_guests_on_wedding_id (wedding_id) # # Foreign Keys # # fk_rails_... (group_id => groups.id) +# fk_rails_... (wedding_id => weddings.id) # class Guest < ApplicationRecord + acts_as_tenant :wedding belongs_to :group enum :status, { diff --git a/app/models/seat.rb b/app/models/seat.rb index 1f3769c..3f13629 100644 --- a/app/models/seat.rb +++ b/app/models/seat.rb @@ -10,18 +10,22 @@ # updated_at :datetime not null # guest_id :uuid not null # tables_arrangement_id :uuid not null +# wedding_id :uuid not null # # Indexes # # index_seats_on_guest_id (guest_id) # index_seats_on_tables_arrangement_id (tables_arrangement_id) +# index_seats_on_wedding_id (wedding_id) # # Foreign Keys # # fk_rails_... (guest_id => guests.id) # fk_rails_... (tables_arrangement_id => tables_arrangements.id) ON DELETE => cascade +# fk_rails_... (wedding_id => weddings.id) # class Seat < ApplicationRecord + acts_as_tenant :wedding belongs_to :guest belongs_to :table_arrangement end diff --git a/app/models/tables_arrangement.rb b/app/models/tables_arrangement.rb index 6e2f621..3080e49 100644 --- a/app/models/tables_arrangement.rb +++ b/app/models/tables_arrangement.rb @@ -9,8 +9,18 @@ # name :string not null # created_at :datetime not null # updated_at :datetime not null +# wedding_id :uuid not null +# +# Indexes +# +# index_tables_arrangements_on_wedding_id (wedding_id) +# +# Foreign Keys +# +# fk_rails_... (wedding_id => weddings.id) # class TablesArrangement < ApplicationRecord + acts_as_tenant :wedding has_many :seats has_many :guests, through: :seats diff --git a/db/migrate/20241130185731_add_wedding_id_to_models.rb b/db/migrate/20241130185731_add_wedding_id_to_models.rb new file mode 100644 index 0000000..bf505b5 --- /dev/null +++ b/db/migrate/20241130185731_add_wedding_id_to_models.rb @@ -0,0 +1,7 @@ +class AddWeddingIdToModels < ActiveRecord::Migration[8.0] + def change + [:expenses, :guests, :seats, :tables_arrangements, :groups].each do |table| + add_reference table, :wedding, type: :uuid, null: false, foreign_key: true + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 436f67b..fd07a1b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2024_11_30_182228) do +ActiveRecord::Schema[8.0].define(version: 2024_11_30_185731) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -26,6 +26,8 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_182228) do t.enum "pricing_type", default: "fixed", null: false, enum_type: "pricing_types" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.uuid "wedding_id", null: false + t.index ["wedding_id"], name: "index_expenses_on_wedding_id" end create_table "groups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -36,8 +38,10 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_182228) do t.datetime "updated_at", null: false t.uuid "parent_id" t.string "color" + t.uuid "wedding_id", null: false t.index ["name"], name: "index_groups_on_name", unique: true t.index ["parent_id"], name: "index_groups_on_parent_id" + t.index ["wedding_id"], name: "index_groups_on_wedding_id" end create_table "guests", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -47,7 +51,9 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_182228) do t.uuid "group_id", null: false t.integer "status", default: 0 t.string "name" + t.uuid "wedding_id", null: false t.index ["group_id"], name: "index_guests_on_group_id" + t.index ["wedding_id"], name: "index_guests_on_wedding_id" end create_table "seats", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -56,8 +62,10 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_182228) do t.integer "table_number" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.uuid "wedding_id", null: false t.index ["guest_id"], name: "index_seats_on_guest_id" t.index ["tables_arrangement_id"], name: "index_seats_on_tables_arrangement_id" + t.index ["wedding_id"], name: "index_seats_on_wedding_id" end create_table "solid_queue_blocked_executions", force: :cascade do |t| @@ -186,6 +194,8 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_182228) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "name", null: false + t.uuid "wedding_id", null: false + t.index ["wedding_id"], name: "index_tables_arrangements_on_wedding_id" end create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -216,14 +226,19 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_182228) do t.index ["slug"], name: "index_weddings_on_slug", unique: true end + add_foreign_key "expenses", "weddings" add_foreign_key "groups", "groups", column: "parent_id" + add_foreign_key "groups", "weddings" add_foreign_key "guests", "groups" + add_foreign_key "guests", "weddings" add_foreign_key "seats", "guests" add_foreign_key "seats", "tables_arrangements", on_delete: :cascade + add_foreign_key "seats", "weddings" add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "tables_arrangements", "weddings" end