2026-05-31 20:36:42 +00:00
|
|
|
"""create_roles_table
|
|
|
|
|
|
|
|
|
|
Revision ID: 714cc11a59c4
|
|
|
|
|
Revises: f90ee7806a25
|
|
|
|
|
Create Date: 2026-05-31 10:35:56.717393
|
|
|
|
|
|
|
|
|
|
"""
|
2026-06-10 21:31:41 +00:00
|
|
|
|
2026-05-31 20:36:42 +00:00
|
|
|
from typing import Sequence, Union
|
|
|
|
|
|
|
|
|
|
from alembic import op
|
|
|
|
|
import sqlalchemy as sa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
2026-06-10 21:31:41 +00:00
|
|
|
revision: str = "714cc11a59c4"
|
|
|
|
|
down_revision: Union[str, None] = "f90ee7806a25"
|
2026-05-31 20:36:42 +00:00
|
|
|
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! ###
|
2026-06-10 21:31:41 +00:00
|
|
|
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"),
|
2026-05-31 20:36:42 +00:00
|
|
|
)
|
2026-06-10 21:31:41 +00:00
|
|
|
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"
|
|
|
|
|
)
|
2026-05-31 20:36:42 +00:00
|
|
|
|
|
|
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade() -> None:
|
|
|
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
2026-06-10 21:31:41 +00:00
|
|
|
with op.batch_alter_table("users", schema=None) as batch_op:
|
|
|
|
|
batch_op.drop_constraint(None, type_="foreignkey")
|
2026-05-31 20:36:42 +00:00
|
|
|
|
2026-06-10 21:31:41 +00:00
|
|
|
op.drop_table("roles")
|
2026-05-31 20:36:42 +00:00
|
|
|
# ### end Alembic commands ###
|