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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user