diff --git a/app/models/user.rb b/app/models/user.rb index d338416..43c3a9e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,6 +18,7 @@ # unlock_token :string # created_at :datetime not null # updated_at :datetime not null +# wedding_id :uuid not null # # Indexes # @@ -25,8 +26,15 @@ # index_users_on_email (email) UNIQUE # index_users_on_reset_password_token (reset_password_token) UNIQUE # index_users_on_unlock_token (unlock_token) UNIQUE +# index_users_on_wedding_id (wedding_id) +# +# Foreign Keys +# +# fk_rails_... (wedding_id => weddings.id) # class User < ApplicationRecord + acts_as_tenant :wedding + devise :database_authenticatable, :registerable, :recoverable, :validatable, :confirmable, :lockable end diff --git a/db/migrate/20241130185731_add_wedding_id_to_models.rb b/db/migrate/20241130185731_add_wedding_id_to_models.rb index c57fff4..63e5c32 100644 --- a/db/migrate/20241130185731_add_wedding_id_to_models.rb +++ b/db/migrate/20241130185731_add_wedding_id_to_models.rb @@ -2,7 +2,7 @@ class AddWeddingIdToModels < ActiveRecord::Migration[8.0] def change - [:expenses, :guests, :seats, :tables_arrangements, :groups].each do |table| + [:expenses, :guests, :seats, :tables_arrangements, :groups, :users].each do |table| add_reference table, :wedding, type: :uuid, null: false, foreign_key: true end end diff --git a/db/schema.rb b/db/schema.rb index fd07a1b..d70dbfa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,5 +1,3 @@ -# Copyright (C) 2024 Manuel Bustillo - # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -212,10 +210,12 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_185731) do t.datetime "locked_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.uuid "wedding_id", null: false t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true + t.index ["wedding_id"], name: "index_users_on_wedding_id" end create_table "weddings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -241,4 +241,5 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_185731) do 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" + add_foreign_key "users", "weddings" end diff --git a/db/seeds.rb b/db/seeds.rb index 5e9886a..206f7da 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -71,10 +71,11 @@ ActsAsTenant.with_tenant(Wedding.create!(slug: :default, date: 1.year.from_now)) 'red'.paint.palette.triad(as: :hex).zip(Group.roots).each { |(color, group)| group.update!(color: color.paint.desaturate(40)) } Group.roots.each(&:colorize_children) + + User.create!( + email: 'development@example.com', + confirmed_at: Time.zone.now, + password: 'supersecretpassword', + password_confirmation: 'supersecretpassword', + ) end -User.create!( - email: 'development@example.com', - confirmed_at: Time.zone.now, - password: 'supersecretpassword', - password_confirmation: 'supersecretpassword', -) \ No newline at end of file