Files
fizzy/db/migrate/20251129175717_promote_first_admin_to_owner.rb
T
Mike Dalessio edf6b53469 Introduce an "owner" role, and prevent it from being administered
to prevent the owner from being demoted or kicked out.

ref: https://app.fizzy.do/5986089/cards/3213
2025-11-29 14:13:29 -05:00

15 lines
367 B
Ruby

class PromoteFirstAdminToOwner < ActiveRecord::Migration[8.2]
def up
Account.find_each do |account|
next if account.users.exists?(role: :owner)
first_admin = account.users.where(role: :admin).order(:created_at).first
first_admin&.update!(role: :owner)
end
end
def down
User.where(role: :owner).update_all(role: :admin)
end
end