Matchu
b8a8cb9b20
Idk if this used to be different or what, but it looks like the current behavior is: if you delete a closet list, it'll leave the hangers present, but Classic DTI would not show them anywhere; but Impress 2020 (until recently) would crash about it. Now, we use `dependent: :destroy` to delete the hangers when you delete the list (which I think makes sense, and is different than what I decided in the past but that's ok, and is what the current behavior *looks* like to people!), and we add a migration that deletes orphaned hangers. The migration also outputs the deleted hangers as JSON, for us to hold onto in case we made a mistake! I'm also backing up the database in advance of running this migration, just in case we gotta roll back HARD!
12 lines
400 B
Ruby
12 lines
400 B
Ruby
class DeleteOrphanedClosetHangers < ActiveRecord::Migration[7.0]
|
|
def up
|
|
orphaned_hangers = ClosetHanger.left_outer_joins(:list).
|
|
where("closet_hangers.list_id IS NOT NULL").where("closet_lists.id IS NULL")
|
|
puts orphaned_hangers.to_json
|
|
orphaned_hangers.delete_all
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration, "The orphaned hangers are already gone!"
|
|
end
|
|
end
|