WIP: Define and seed an invitation model #224
@ -20,7 +20,7 @@
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (wedding_id => weddings.id)
|
||||
# fk_rails_... (wedding_id => weddings.id) ON DELETE => cascade
|
||||
#
|
||||
class Expense < ApplicationRecord
|
||||
acts_as_tenant :wedding
|
||||
|
@ -25,7 +25,7 @@
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (parent_id => groups.id)
|
||||
# fk_rails_... (wedding_id => weddings.id)
|
||||
# fk_rails_... (wedding_id => weddings.id) ON DELETE => cascade
|
||||
#
|
||||
class Group < ApplicationRecord
|
||||
acts_as_tenant :wedding
|
||||
|
@ -6,28 +6,32 @@
|
||||
#
|
||||
# Table name: guests
|
||||
#
|
||||
# id :uuid not null, primary key
|
||||
# name :string
|
||||
# phone :string
|
||||
# status :integer default("considered")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# group_id :uuid
|
||||
# wedding_id :uuid not null
|
||||
# id :uuid not null, primary key
|
||||
# name :string
|
||||
# phone :string
|
||||
# status :integer default("considered")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# group_id :uuid
|
||||
# invitation_id :uuid
|
||||
# wedding_id :uuid not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_guests_on_group_id (group_id)
|
||||
# index_guests_on_wedding_id (wedding_id)
|
||||
# index_guests_on_group_id (group_id)
|
||||
# index_guests_on_invitation_id (invitation_id)
|
||||
# index_guests_on_wedding_id (wedding_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (group_id => groups.id)
|
||||
# fk_rails_... (wedding_id => weddings.id)
|
||||
# fk_rails_... (invitation_id => invitations.id)
|
||||
# fk_rails_... (wedding_id => weddings.id) ON DELETE => cascade
|
||||
#
|
||||
class Guest < ApplicationRecord
|
||||
acts_as_tenant :wedding
|
||||
belongs_to :group, optional: true
|
||||
belongs_to :invitation, optional: true
|
||||
|
||||
enum :status, {
|
||||
considered: 0,
|
||||
|
23
app/models/invitation.rb
Normal file
23
app/models/invitation.rb
Normal file
@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: invitations
|
||||
#
|
||||
# id :uuid not null, primary key
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# wedding_id :uuid not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_invitations_on_wedding_id (wedding_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (wedding_id => weddings.id) ON DELETE => cascade
|
||||
#
|
||||
class Invitation < ApplicationRecord
|
||||
acts_as_tenant :wedding
|
||||
has_many :guests, dependent: :nullify
|
||||
end
|
@ -24,7 +24,7 @@
|
||||
#
|
||||
# fk_rails_... (guest_id => guests.id)
|
||||
# fk_rails_... (tables_arrangement_id => tables_arrangements.id) ON DELETE => cascade
|
||||
# fk_rails_... (wedding_id => weddings.id)
|
||||
# fk_rails_... (wedding_id => weddings.id) ON DELETE => cascade
|
||||
#
|
||||
class Seat < ApplicationRecord
|
||||
acts_as_tenant :wedding
|
||||
|
@ -20,7 +20,7 @@
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (wedding_id => weddings.id)
|
||||
# fk_rails_... (wedding_id => weddings.id) ON DELETE => cascade
|
||||
#
|
||||
class TablesArrangement < ApplicationRecord
|
||||
acts_as_tenant :wedding
|
||||
|
@ -32,7 +32,7 @@
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (wedding_id => weddings.id)
|
||||
# fk_rails_... (wedding_id => weddings.id) ON DELETE => cascade
|
||||
#
|
||||
class User < ApplicationRecord
|
||||
acts_as_tenant :wedding
|
||||
|
@ -2,4 +2,8 @@
|
||||
|
||||
ActsAsTenant.configure do |config|
|
||||
config.require_tenant = !Rails.env.test?
|
||||
end
|
||||
end
|
||||
|
||||
Rails.application.console do
|
||||
ActsAsTenant.current_tenant = Wedding.first
|
||||
end
|
||||
|
10
db/migrate/20250127183547_create_invitations.rb
Normal file
10
db/migrate/20250127183547_create_invitations.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class CreateInvitations < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :invitations, id: :uuid do |t|
|
||||
t.references :wedding, null: false, foreign_key: { on_delete: :cascade }, type: :uuid
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_reference :guests, :invitation, foreign_key: true, type: :uuid
|
||||
end
|
||||
end
|
@ -0,0 +1,8 @@
|
||||
class FixCascadingWeddingDeletion < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
[:expenses, :groups, :guests, :seats, :tables_arrangements, :users].each do |table|
|
||||
remove_foreign_key table, column: :wedding_id
|
||||
add_foreign_key table, :weddings, on_delete: :cascade
|
||||
end
|
||||
end
|
||||
end
|
25
db/schema.rb
generated
25
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_01_26_091823) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_01_27_190131) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_catalog.plpgsql"
|
||||
|
||||
@ -63,10 +63,19 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_26_091823) do
|
||||
t.integer "status", default: 0
|
||||
t.string "name"
|
||||
t.uuid "wedding_id", null: false
|
||||
t.uuid "invitation_id"
|
||||
t.index ["group_id"], name: "index_guests_on_group_id"
|
||||
t.index ["invitation_id"], name: "index_guests_on_invitation_id"
|
||||
t.index ["wedding_id"], name: "index_guests_on_wedding_id"
|
||||
end
|
||||
|
||||
create_table "invitations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "wedding_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["wedding_id"], name: "index_invitations_on_wedding_id"
|
||||
end
|
||||
|
||||
create_table "seats", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "guest_id", null: false
|
||||
t.uuid "tables_arrangement_id", null: false
|
||||
@ -239,22 +248,24 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_26_091823) do
|
||||
t.index ["slug"], name: "index_weddings_on_slug", unique: true
|
||||
end
|
||||
|
||||
add_foreign_key "expenses", "weddings"
|
||||
add_foreign_key "expenses", "weddings", on_delete: :cascade
|
||||
add_foreign_key "group_affinities", "groups", column: "group_a_id"
|
||||
add_foreign_key "group_affinities", "groups", column: "group_b_id"
|
||||
add_foreign_key "groups", "groups", column: "parent_id"
|
||||
add_foreign_key "groups", "weddings"
|
||||
add_foreign_key "groups", "weddings", on_delete: :cascade
|
||||
add_foreign_key "guests", "groups"
|
||||
add_foreign_key "guests", "weddings"
|
||||
add_foreign_key "guests", "invitations"
|
||||
add_foreign_key "guests", "weddings", on_delete: :cascade
|
||||
add_foreign_key "invitations", "weddings", on_delete: :cascade
|
||||
add_foreign_key "seats", "guests"
|
||||
add_foreign_key "seats", "tables_arrangements", on_delete: :cascade
|
||||
add_foreign_key "seats", "weddings"
|
||||
add_foreign_key "seats", "weddings", on_delete: :cascade
|
||||
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"
|
||||
add_foreign_key "users", "weddings"
|
||||
add_foreign_key "tables_arrangements", "weddings", on_delete: :cascade
|
||||
add_foreign_key "users", "weddings", on_delete: :cascade
|
||||
end
|
||||
|
@ -3,11 +3,6 @@
|
||||
NUMBER_OF_GUESTS = 50
|
||||
|
||||
ActsAsTenant.without_tenant do
|
||||
TablesArrangement.delete_all
|
||||
Expense.delete_all
|
||||
Guest.delete_all
|
||||
Group.delete_all
|
||||
|
||||
Wedding.delete_all
|
||||
end
|
||||
|
||||
@ -66,7 +61,8 @@ ActsAsTenant.with_tenant(wedding) do
|
||||
name: Faker::Name.name,
|
||||
phone: Faker::PhoneNumber.cell_phone,
|
||||
group: groups.sample,
|
||||
status: Guest.statuses.keys.sample
|
||||
status: Guest.statuses.keys.sample,
|
||||
invitation: (Invitation.create!(wedding:) if rand > 0.1),
|
||||
)
|
||||
end
|
||||
|
||||
|
7
spec/factories/invitations.rb
Normal file
7
spec/factories/invitations.rb
Normal file
@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :invitation do
|
||||
wedding
|
||||
end
|
||||
end
|
7
spec/models/invitation_spec.rb
Normal file
7
spec/models/invitation_spec.rb
Normal file
@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Invitation do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user