-- ECR-013B AccountLifecycle / UserStatus CREATE TABLE IF NOT EXISTS account_state_transitions ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), user_id uuid NOT NULL REFERENCES users(id), from_status varchar(32) NOT NULL, to_status varchar(32) NOT NULL, admin_id uuid NOT NULL REFERENCES admin_accounts(id), reason text NOT NULL DEFAULT '', created_at timestamptz NOT NULL DEFAULT now() ); CREATE INDEX IF NOT EXISTS idx_account_state_transitions_user ON account_state_transitions(user_id, created_at DESC); INSERT INTO admin_role_permissions(role_id, code) SELECT r.id, 'admin.users.status.write' FROM admin_roles r WHERE r.name = 'super_admin' ON CONFLICT DO NOTHING;