Fix migrations that can no longer be applied

The migrations could no longer be applied on an empty database, mainly
because they referred to models that no longer existed. Replaced the
model references with direct table access that will always be correct at
the time the migration is applied.

Also removed conflicting indexes in table renames.
This commit is contained in:
Kevin McConnell
2024-10-02 13:47:05 +01:00
parent 53b61c0752
commit 13f5952336
4 changed files with 4 additions and 7 deletions
@@ -1,9 +1,6 @@
class RenameOrganizationsToAccounts < ActiveRecord::Migration[8.0]
def change
rename_table :organizations, :accounts
add_index :accounts, :name, unique: true
rename_column :users, :organization_id, :account_id
add_index :users, :account_id
end
end
@@ -7,7 +7,5 @@ class CreateProjects < ActiveRecord::Migration[8.0]
t.timestamps
end
Account.first.projects.create! name: "Writebook", creator: User.first
end
end
@@ -4,7 +4,8 @@ class AddProjectToBubbles < ActiveRecord::Migration[8.0]
t.references :project, null: true
end
Bubble.update_all project_id: Project.first.id
execute "update bubbles set project_id = (select id from projects limit 1)"
change_column_null :bubbles, :project_id, false
end
end
@@ -4,7 +4,8 @@ class AddAccountToTags < ActiveRecord::Migration[8.0]
t.references :account, null: true
end
Tag.update_all account_id: Account.first.id
execute "update tags set account_id = (select id from accounts limit 1)"
change_column_null :tags, :account_id, false
end
end