04/17 Init migration

This commit is contained in:
Nguyen LTS
2026-04-17 16:43:23 -04:00
parent b0a475642d
commit 6f4a7e47da
5 changed files with 246 additions and 0 deletions
@@ -0,0 +1,58 @@
"""add audit_log tables; fix sharing_public_key type
Revision ID: 71d7158dd3b9
Revises:
Create Date: 2026-04-17 16:42:10.867960
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '71d7158dd3b9'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('audit_logs',
sa.Column('id', mysql.INTEGER(unsigned=True), autoincrement=True, nullable=False),
sa.Column('user_id', mysql.INTEGER(unsigned=True), nullable=False),
sa.Column('action', sa.String(length=64), nullable=False),
sa.Column('resource_type', sa.String(length=64), nullable=False),
sa.Column('resource_id', mysql.INTEGER(unsigned=True), nullable=True),
sa.Column('detail', sa.String(length=512), nullable=True),
sa.Column('ip_address', sa.String(length=45), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
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_created_at'), ['created_at'], unique=False)
batch_op.create_index(batch_op.f('ix_audit_logs_user_id'), ['user_id'], unique=False)
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.alter_column('sharing_public_key',
existing_type=mysql.TEXT(),
type_=sa.String(length=128),
existing_nullable=True)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.alter_column('sharing_public_key',
existing_type=sa.String(length=128),
type_=mysql.TEXT(),
existing_nullable=True)
with op.batch_alter_table('audit_logs', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_audit_logs_user_id'))
batch_op.drop_index(batch_op.f('ix_audit_logs_created_at'))
op.drop_table('audit_logs')
# ### end Alembic commands ###