80 lines
3.1 KiB
Python
80 lines
3.1 KiB
Python
"""Initial tables
|
|||
|
|
|
||
|
|
Revision ID: 28e3c8078830
|
||
|
|
Revises:
|
||
|
|
Create Date: 2026-10-12 05:03:16.492862
|
||
|
|
|
||
|
|
"""
|
||
|
|
from typing import Sequence, Union
|
||
|
|
|
||
|
|
from alembic import op
|
||
|
|
import sqlalchemy as sa
|
||
|
|
|
||
|
|
|
||
|
|
# revision identifiers, used by Alembic.
|
||
|
|
revision: str = '28e3c8078830'
|
||
|
|
down_revision: Union[str, None] = None
|
||
|
|
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('oauth_clients',
|
||
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
|
sa.Column('client_id', sa.String(length=64), nullable=False),
|
||
|
|
sa.Column('name', sa.String(length=255), nullable=False),
|
||
|
|
sa.Column('is_confidential', sa.Boolean(), nullable=False),
|
||
|
|
sa.Column('redirect_uris', sa.JSON(), nullable=False),
|
||
|
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
|
sa.PrimaryKeyConstraint('id')
|
||
|
|
)
|
||
|
|
with op.batch_alter_table('oauth_clients', schema=None) as batch_op:
|
||
|
|
batch_op.create_index(batch_op.f('ix_oauth_clients_client_id'), ['client_id'], unique=True)
|
||
|
|
|
||
|
|
op.create_table('users',
|
||
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
|
sa.Column('email', sa.String(length=255), nullable=False),
|
||
|
|
sa.Column('hashed_password', sa.String(length=255), nullable=False),
|
||
|
|
sa.Column('is_active', sa.Boolean(), nullable=False),
|
||
|
|
sa.Column('is_admin', sa.Boolean(), nullable=False),
|
||
|
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
|
sa.PrimaryKeyConstraint('id')
|
||
|
|
)
|
||
|
|
with op.batch_alter_table('users', schema=None) as batch_op:
|
||
|
|
batch_op.create_index(batch_op.f('ix_users_email'), ['email'], unique=True)
|
||
|
|
|
||
|
|
op.create_table('audit_events',
|
||
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
|
sa.Column('event_type', sa.String(length=100), nullable=False),
|
||
|
|
sa.Column('actor_id', sa.Integer(), nullable=True),
|
||
|
|
sa.Column('client_id', sa.String(length=64), nullable=True),
|
||
|
|
sa.Column('ip', sa.String(length=45), nullable=True),
|
||
|
|
sa.Column('user_agent', sa.String(length=512), nullable=True),
|
||
|
|
sa.Column('metadata_json', sa.JSON(), nullable=True),
|
||
|
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
|
sa.ForeignKeyConstraint(['actor_id'], ['users.id'], ),
|
||
|
|
sa.PrimaryKeyConstraint('id')
|
||
|
|
)
|
||
|
|
with op.batch_alter_table('audit_events', schema=None) as batch_op:
|
||
|
|
batch_op.create_index(batch_op.f('ix_audit_events_event_type'), ['event_type'], unique=False)
|
||
|
|
|
||
|
|
# ### end Alembic commands ###
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
||
|
|
with op.batch_alter_table('audit_events', schema=None) as batch_op:
|
||
|
|
batch_op.drop_index(batch_op.f('ix_audit_events_event_type'))
|
||
|
|
|
||
|
|
op.drop_table('audit_events')
|
||
|
|
with op.batch_alter_table('users', schema=None) as batch_op:
|
||
|
|
batch_op.drop_index(batch_op.f('ix_users_email'))
|
||
|
|
|
||
|
|
op.drop_table('users')
|
||
|
|
with op.batch_alter_table('oauth_clients', schema=None) as batch_op:
|
||
|
|
batch_op.drop_index(batch_op.f('ix_oauth_clients_client_id'))
|
||
|
|
|
||
|
|
op.drop_table('oauth_clients')
|
||
|
|
# ### end Alembic commands ###
|