first commit

This commit is contained in:
2025-11-30 00:07:24 +01:00
commit b5e642aecb
78 changed files with 15162 additions and 0 deletions

View 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 ###

View File

@ -0,0 +1,42 @@
"""Add Client model
Revision ID: d0b3ddd682f3
Revises: 8ee9394b7cd5
Create Date: 2025-11-27 07:58:56.011042
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd0b3ddd682f3'
down_revision = '8ee9394b7cd5'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('oidc_clients',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('client_id', sa.String(length=48), nullable=False),
sa.Column('client_secret_hash', sa.String(length=128), nullable=True),
sa.Column('client_name', sa.String(length=120), nullable=False),
sa.Column('redirect_uris', sa.Text(), nullable=False),
sa.Column('allowed_scopes', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('oidc_clients', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_oidc_clients_client_id'), ['client_id'], unique=True)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('oidc_clients', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_oidc_clients_client_id'))
op.drop_table('oidc_clients')
# ### end Alembic commands ###

View File

@ -0,0 +1,28 @@
"""Add client_id to access_tokens table
Revision ID: keettxs5w17k
Revises: d0b3ddd682f3
Create Date: 2025-11-28 12:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'keettxs5w17k'
down_revision = 'd0b3ddd682f3'
branch_labels = None
depends_on = None
def upgrade():
# Add client_id column to access_tokens table
op.add_column('access_tokens', sa.Column('client_id', sa.String(length=128), nullable=True))
op.create_index(op.f('ix_access_tokens_client_id'), 'access_tokens', ['client_id'], unique=False)
def downgrade():
# Remove client_id column from access_tokens table
op.drop_index(op.f('ix_access_tokens_client_id'), table_name='access_tokens')
op.drop_column('access_tokens', 'client_id')