Finish the rollout of account_id to all core data models

Schema:
- add account_id to tables it was missing from
- make account_id a required column everywhere
- add [account_id] indexes, or add `account_id` to existing indices

Models:
- add `belongs_to :account` to all models (default to using a domain
  model's account whenever possible)
- add account_id in all the necessary fixtures
- add account_id to insert_all hashes
- pass account_id to a few initialize calls

Miscellaneous:
- update the import script to set account_id

Note that I'm not adding account_id to the join tables primarily
because I couldn't think of an easy way to populate it without making
it a full Join model, and that was more work than I have time to take
on right now.
This commit is contained in:
Mike Dalessio
2025-11-13 21:48:30 -05:00
parent 5a7f08067a
commit fe6df7085f
42 changed files with 311 additions and 49 deletions
+10
View File
@@ -270,6 +270,7 @@ class Import
if old_activity_spike
activity_spikes_to_insert << {
id: generate_uuid,
account_id: account.id,
card_id: new_id,
created_at: old_activity_spike.created_at,
updated_at: old_activity_spike.updated_at
@@ -280,6 +281,7 @@ class Import
if old_engagement
engagements_to_insert << {
id: generate_uuid,
account_id: account.id,
card_id: new_id,
status: old_engagement.status,
created_at: old_engagement.created_at,
@@ -291,6 +293,7 @@ class Import
if old_goldness
goldnesses_to_insert << {
id: generate_uuid,
account_id: account.id,
card_id: new_id,
created_at: old_goldness.created_at,
updated_at: old_goldness.updated_at
@@ -301,6 +304,7 @@ class Import
if old_not_now
not_nows_to_insert << {
id: generate_uuid,
account_id: account.id,
card_id: new_id,
user_id: old_not_now.user_id ? mapping[:users][old_not_now.user_id] : nil,
created_at: old_not_now.created_at,
@@ -311,6 +315,7 @@ class Import
old_card.assignments.each do |old_assignment|
assignments_to_insert << {
id: generate_uuid,
account_id: account.id,
card_id: new_id,
assignee_id: mapping[:users][old_assignment.assignee_id],
assigner_id: mapping[:users][old_assignment.assigner_id],
@@ -323,6 +328,7 @@ class Import
if old_closure
closures_to_insert << {
id: generate_uuid,
account_id: account.id,
card_id: new_id,
user_id: old_closure.user_id ? mapping[:users][old_closure.user_id] : nil,
created_at: old_closure.created_at,
@@ -442,6 +448,7 @@ class Import
accesses_to_insert << {
id: new_id,
account_id: account.id,
board_id: mapping[:boards][old_access.board_id],
user_id: mapping[:users][old_access.user_id],
involvement: old_access.involvement,
@@ -701,6 +708,7 @@ class Import
ActiveStorage::VariantRecord.find_or_create_by!(
id: new_variant_blob.id,
account_id: account.id,
blob_id: new_blob.id,
variation_digest: old_variant_record.variation_digest
)
@@ -772,6 +780,7 @@ class Import
watches_to_insert << {
id: new_id,
account_id: account.id,
user_id: mapping[:users][old_watch.user_id],
card_id: mapping[:cards][old_watch.card_id],
watching: old_watch.watching,
@@ -800,6 +809,7 @@ class Import
pins_to_insert << {
id: new_id,
account_id: account.id,
user_id: mapping[:users][old_pin.user_id],
card_id: mapping[:cards][old_pin.card_id],
created_at: old_pin.created_at,