first commit
This commit is contained in:
110
migrations/versions/8ee9394b7cd5_initial_migration.py
Normal file
110
migrations/versions/8ee9394b7cd5_initial_migration.py
Normal file
@ -0,0 +1,110 @@
|
||||
"""Initial migration
|
||||
|
||||
Revision ID: 8ee9394b7cd5
|
||||
Revises:
|
||||
Create Date: 2025-11-27 07:53:31.360614
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '8ee9394b7cd5'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('users',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('username', sa.String(length=80), nullable=False),
|
||||
sa.Column('password_hash', sa.String(length=128), nullable=False),
|
||||
sa.Column('email', sa.String(length=120), nullable=False),
|
||||
sa.Column('name', sa.String(length=120), nullable=False),
|
||||
sa.Column('preferred_username', sa.String(length=80), nullable=False),
|
||||
sa.Column('is_admin', sa.Boolean(), nullable=True),
|
||||
sa.Column('role', sa.String(length=50), nullable=True),
|
||||
sa.Column('permissions', sa.Text(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('email')
|
||||
)
|
||||
with op.batch_alter_table('users', schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f('ix_users_username'), ['username'], unique=True)
|
||||
|
||||
op.create_table('access_tokens',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('token', sa.String(length=128), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.Column('scope', sa.String(length=256), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('expires_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('revoked', sa.Boolean(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
with op.batch_alter_table('access_tokens', schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f('ix_access_tokens_token'), ['token'], unique=True)
|
||||
|
||||
op.create_table('audit_logs',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('timestamp', sa.DateTime(), nullable=False),
|
||||
sa.Column('action', sa.String(length=100), nullable=False),
|
||||
sa.Column('username', sa.String(length=80), nullable=True),
|
||||
sa.Column('user_id', sa.Integer(), nullable=True),
|
||||
sa.Column('ip_address', sa.String(length=45), nullable=True),
|
||||
sa.Column('user_agent', sa.Text(), nullable=True),
|
||||
sa.Column('details', sa.Text(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
with op.batch_alter_table('audit_logs', schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f('ix_audit_logs_action'), ['action'], unique=False)
|
||||
batch_op.create_index(batch_op.f('ix_audit_logs_timestamp'), ['timestamp'], unique=False)
|
||||
batch_op.create_index(batch_op.f('ix_audit_logs_username'), ['username'], unique=False)
|
||||
|
||||
op.create_table('authorization_codes',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('code', sa.String(length=128), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.Column('client_id', sa.String(length=128), nullable=False),
|
||||
sa.Column('redirect_uri', sa.String(length=512), nullable=False),
|
||||
sa.Column('scope', sa.String(length=256), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('expires_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('used', sa.Boolean(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
with op.batch_alter_table('authorization_codes', schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f('ix_authorization_codes_code'), ['code'], unique=True)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('authorization_codes', schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f('ix_authorization_codes_code'))
|
||||
|
||||
op.drop_table('authorization_codes')
|
||||
with op.batch_alter_table('audit_logs', schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f('ix_audit_logs_username'))
|
||||
batch_op.drop_index(batch_op.f('ix_audit_logs_timestamp'))
|
||||
batch_op.drop_index(batch_op.f('ix_audit_logs_action'))
|
||||
|
||||
op.drop_table('audit_logs')
|
||||
with op.batch_alter_table('access_tokens', schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f('ix_access_tokens_token'))
|
||||
|
||||
op.drop_table('access_tokens')
|
||||
with op.batch_alter_table('users', schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f('ix_users_username'))
|
||||
|
||||
op.drop_table('users')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user