2026-07-03 19:50:08 +00:00
|
|
|
"""T10: Add role_id FK column to users table (references roles.id).
|
|
|
|
|
|
|
|
|
|
Revision ID: 0005_user_role_fk
|
|
|
|
|
Revises: 0004_ai_workflows
|
|
|
|
|
Create Date: 2026-07-03
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import Sequence, Union
|
|
|
|
|
|
|
|
|
|
from alembic import op
|
|
|
|
|
import sqlalchemy as sa
|
|
|
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
|
|
|
|
|
|
revision: str = "0005_user_role_fk"
|
|
|
|
|
down_revision: Union[str, None] = "0004_ai_workflows"
|
|
|
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
|
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade() -> None:
|
2026-07-31 18:20:09 +02:00
|
|
|
op.execute("ALTER TABLE users ADD COLUMN IF NOT EXISTS role_id UUID REFERENCES roles(id) ON DELETE SET NULL")
|
|
|
|
|
op.execute("CREATE INDEX IF NOT EXISTS ix_users_role_id ON users (role_id)")
|
2026-07-03 19:50:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade() -> None:
|
|
|
|
|
op.drop_index("ix_users_role_id", table_name="users")
|
|
|
|
|
op.drop_column("users", "role_id")
|