from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import mysql revision = '96c23dad405d' down_revision = '59baf2338f8a' branch_labels = None depends_on = None def upgrade() -> None: from sqlalchemy import inspect bind = op.get_bind() inspector = inspect(bind) tables = inspector.get_table_names() if 'system_settings' not in tables: op.create_table('system_settings', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('key', sa.String(length=100), nullable=False), sa.Column('value', sa.Text(), nullable=False), sa.Column('description', sa.Text(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('updated_by_id', sa.Integer(), nullable=True), sa.ForeignKeyConstraint(['updated_by_id'], ['users.id']), sa.PrimaryKeyConstraint('id')) op.create_index(op.f('ix_system_settings_id'), 'system_settings', ['id'], unique=False) op.create_index(op.f('ix_system_settings_key'), 'system_settings', ['key'], unique=True) columns = [col['name'] for col in inspector.get_columns('users')] if 'currency' not in columns: op.add_column('users', sa.Column('currency', sa.String(length=3), nullable=False, server_default='VND')) def downgrade() -> None: try: op.drop_column('users', 'currency') except Exception: pass op.drop_index(op.f('ix_system_settings_key'), table_name='system_settings') op.drop_index(op.f('ix_system_settings_id'), table_name='system_settings') op.drop_table('system_settings')