52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
|
|
"""Add db_api_users table
|
||
|
|
|
||
|
|
Revision ID: 0005
|
||
|
|
Revises: 0004
|
||
|
|
Create Date: 2026-04-02
|
||
|
|
"""
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import Sequence, Union
|
||
|
|
|
||
|
|
import sqlalchemy as sa
|
||
|
|
from alembic import op
|
||
|
|
from sqlalchemy.dialects import postgresql
|
||
|
|
|
||
|
|
revision: str = "0005"
|
||
|
|
down_revision: Union[str, None] = "0004"
|
||
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
||
|
|
depends_on: Union[str, Sequence[str], None] = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
op.execute("CREATE TYPE db_permission_level AS ENUM ('read_only', 'modify', 'full')")
|
||
|
|
op.create_table(
|
||
|
|
"db_api_users",
|
||
|
|
sa.Column(
|
||
|
|
"id",
|
||
|
|
postgresql.UUID(as_uuid=True),
|
||
|
|
primary_key=True,
|
||
|
|
server_default=sa.text("gen_random_uuid()"),
|
||
|
|
),
|
||
|
|
sa.Column("username", sa.Text, nullable=False, unique=True),
|
||
|
|
sa.Column(
|
||
|
|
"permission_level",
|
||
|
|
postgresql.ENUM("read_only", "modify", "full", name="db_permission_level", create_type=False),
|
||
|
|
nullable=False,
|
||
|
|
),
|
||
|
|
sa.Column("description", sa.Text),
|
||
|
|
sa.Column("is_active", sa.Boolean, nullable=False, server_default="TRUE"),
|
||
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("NOW()")),
|
||
|
|
sa.Column("last_used_at", sa.DateTime(timezone=True)),
|
||
|
|
)
|
||
|
|
op.create_index(
|
||
|
|
"idx_db_api_users_username",
|
||
|
|
"db_api_users",
|
||
|
|
[sa.text("LOWER(username)")],
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
op.drop_table("db_api_users")
|
||
|
|
op.execute("DROP TYPE IF EXISTS db_permission_level")
|