mirror of
https://github.com/we-promise/sure.git
synced 2026-06-06 19:29:03 +00:00
* fix(migrations): scope admin-backfill to a MigrationUser model (#1716) `bin/rails db:migrate` on an empty database aborts at `20240520074309_add_admin_role_to_current_users.rb` because `User.update_all` loads the production User class, which declares `enum :ui_layout` for a column added by a much later migration (`20251030140000_add_ui_layout_to_users`). The enum macro then raises `Undeclared attribute type for enum 'ui_layout' in User` and every subsequent migration is skipped, leaving the DB in a partial state. Apply the same MigrationUser pattern already used by `AddUiLayoutToUsers` — a migration-scoped subclass of `ApplicationRecord` with only the table name set, so it doesn't load the production enum declarations. Closes #1716 * fix(migrations): inherit MigrationUser from ActiveRecord::Base, not ApplicationRecord (#1716) @jjmata + @JSONbored both flagged that the nested MigrationUser inherited from ApplicationRecord, which can pull in concerns / callbacks / default scopes added to ApplicationRecord in the future and re-introduce the exact loading problem this migration is meant to avoid. Switch to ActiveRecord::Base — the idiomatic Rails pattern for migration-only models — and extend the inline comment to record the rationale. --------- Co-authored-by: jeffrey701 <jeffrey701@users.noreply.github.com>
16 lines
652 B
Ruby
16 lines
652 B
Ruby
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
|
|
MigrationUser.update_all(role: "admin")
|
|
end
|
|
end
|