45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
|
|
"""create_roles_table
|
||
|
|
|
||
|
|
Revision ID: 714cc11a59c4
|
||
|
|
Revises: f90ee7806a25
|
||
|
|
Create Date: 2026-05-31 10:35:56.717393
|
||
|
|
|
||
|
|
"""
|
||
|
|
from typing import Sequence, Union
|
||
|
|
|
||
|
|
from alembic import op
|
||
|
|
import sqlalchemy as sa
|
||
|
|
|
||
|
|
|
||
|
|
# revision identifiers, used by Alembic.
|
||
|
|
revision: str = '714cc11a59c4'
|
||
|
|
down_revision: Union[str, None] = 'f90ee7806a25'
|
||
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
||
|
|
depends_on: Union[str, Sequence[str], None] = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
||
|
|
op.create_table('roles',
|
||
|
|
sa.Column('id', sa.String(length=36), nullable=False),
|
||
|
|
sa.Column('account_id', sa.String(length=36), nullable=False),
|
||
|
|
sa.Column('name', sa.String(length=100), nullable=False),
|
||
|
|
sa.Column('description', sa.String(length=500), nullable=True),
|
||
|
|
sa.Column('permissions', sa.JSON(), nullable=False),
|
||
|
|
sa.ForeignKeyConstraint(['account_id'], ['accounts.id'], ondelete='CASCADE'),
|
||
|
|
sa.PrimaryKeyConstraint('id')
|
||
|
|
)
|
||
|
|
with op.batch_alter_table('users', schema=None) as batch_op:
|
||
|
|
batch_op.create_foreign_key('fk_users_role_id_roles', 'roles', ['role_id'], ['id'], ondelete='SET NULL')
|
||
|
|
|
||
|
|
# ### end Alembic commands ###
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
||
|
|
with op.batch_alter_table('users', schema=None) as batch_op:
|
||
|
|
batch_op.drop_constraint(None, type_='foreignkey')
|
||
|
|
|
||
|
|
op.drop_table('roles')
|
||
|
|
# ### end Alembic commands ###
|