Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix(migrations): scope admin-backfill to a MigrationUser model (#1716) (#1871)

Jeff1e818e5c6d49
diff --git a/db/migrate/20240520074309_add_admin_role_to_current_users.rb b/db/migrate/20240520074309_add_admin_role_to_current_users.rb
index 9dcdd67d26..02764e946f 100644
--- a/db/migrate/20240520074309_add_admin_role_to_current_users.rb
+++ b/db/migrate/20240520074309_add_admin_role_to_current_users.rb
@@ -1,5 +1,15 @@
class AddAdminRoleToCurrentUsers < ActiveRecord::Migration[7.2]
+ # Scope to the migration so loading the production User model — which declares
+ # enums for columns added by later migrations (e.g. ui_layout) — does not
+ # abort a fresh `db:migrate` run on an empty database. Inherit from
+ # ActiveRecord::Base (not ApplicationRecord) so any future concerns,
+ # callbacks, or default scopes added to ApplicationRecord cannot re-introduce
+ # the same loading problem this migration is meant to avoid.
+ class MigrationUser < ActiveRecord::Base
+ self.table_name = "users"
+ end
+
def up
- User.update_all(role: "admin")
+ MigrationUser.update_all(role: "admin")
end
end