246_account_protection_roles.sql 512 B

1234567891011
  1. -- Preserve every existing account policy: new defaults are applied at the
  2. -- common account creation boundary; missing old flags retain legacy meaning.
  3. -- Promote the oldest active administrator only when no live super-admin exists.
  4. UPDATE users SET role = 'super_admin', updated_at = NOW()
  5. WHERE id = (
  6. SELECT id FROM users
  7. WHERE role = 'admin' AND status = 'active' AND deleted_at IS NULL
  8. ORDER BY id LIMIT 1
  9. ) AND NOT EXISTS (
  10. SELECT 1 FROM users WHERE role = 'super_admin' AND deleted_at IS NULL
  11. );