Adds users.can_cover_l1, accounts.l1_seats_purchased, subscriptions.l1_seat_limit, audit_logs.acting_as. Rotates the users.account_role CHECK constraint to include 'l1_tech' (was: 'owner', 'admin', 'engineer', 'viewer'). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
"""add_l1_columns
|
|
|
|
Revision ID: a8186f22506d
|
|
Revises: b269a1add160
|
|
Create Date: 2026-05-28 16:15:40.900535
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = 'a8186f22506d'
|
|
down_revision: Union[str, None] = 'b269a1add160'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.add_column(
|
|
'users',
|
|
sa.Column('can_cover_l1', sa.Boolean(), nullable=False, server_default='false'),
|
|
)
|
|
op.add_column(
|
|
'accounts',
|
|
sa.Column('l1_seats_purchased', sa.Integer(), nullable=False, server_default='0'),
|
|
)
|
|
op.add_column(
|
|
'subscriptions',
|
|
sa.Column('l1_seat_limit', sa.Integer(), nullable=True),
|
|
)
|
|
op.add_column(
|
|
'audit_logs',
|
|
sa.Column('acting_as', sa.String(30), nullable=True),
|
|
)
|
|
|
|
# Rotate account_role CHECK constraint to include 'l1_tech'
|
|
op.drop_constraint('ck_users_account_role_enum', 'users', type_='check')
|
|
op.create_check_constraint(
|
|
'ck_users_account_role_enum',
|
|
'users',
|
|
"account_role IN ('owner', 'admin', 'engineer', 'l1_tech', 'viewer')",
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
# Reverse the constraint rotation first
|
|
op.drop_constraint('ck_users_account_role_enum', 'users', type_='check')
|
|
op.create_check_constraint(
|
|
'ck_users_account_role_enum',
|
|
'users',
|
|
"account_role IN ('owner', 'admin', 'engineer', 'viewer')",
|
|
)
|
|
op.drop_column('audit_logs', 'acting_as')
|
|
op.drop_column('subscriptions', 'l1_seat_limit')
|
|
op.drop_column('accounts', 'l1_seats_purchased')
|
|
op.drop_column('users', 'can_cover_l1')
|