Files
Hotel-Booking/Backend/alembic/versions/96c23dad405d_add_system_settings_table.py
Iliyan Angelov 0c59fe1173 updates
2025-11-17 18:26:30 +02:00

61 lines
2.1 KiB
Python

"""add_system_settings_table
Revision ID: 96c23dad405d
Revises: 59baf2338f8a
Create Date: 2025-11-17 11:51:28.369031
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '96c23dad405d'
down_revision = '59baf2338f8a'
branch_labels = None
depends_on = None
def upgrade() -> None:
# Create system_settings table (if it doesn't exist)
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)
# Add currency column to users table (if it doesn't exist)
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'))
# ### end Alembic commands ###
def downgrade() -> None:
# Drop currency column from users table
try:
op.drop_column('users', 'currency')
except Exception:
# Column might not exist, skip
pass
# Drop system_settings table
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')
# ### end Alembic commands ###