Update
This commit is contained in:
@@ -29,23 +29,32 @@ depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
'system_settings',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('key', sa.String(100), nullable=False),
|
||||
sa.Column('value', sa.String(500), nullable=False),
|
||||
sa.Column('description', sa.String(256), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
op.create_index('ix_system_settings_key', 'system_settings', ['key'], unique=True)
|
||||
|
||||
# Seed the default: registration is open on fresh installs.
|
||||
op.execute(
|
||||
"INSERT INTO system_settings (key, value, description, updated_at) "
|
||||
"VALUES ('registration_enabled', 'true', "
|
||||
"'Allow new users to self-register via /auth/register', NOW())"
|
||||
)
|
||||
# Guard: db.create_all() on first startup already creates this table.
|
||||
# Only create it if it doesn't exist so the migration is idempotent.
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
if 'system_settings' not in inspector.get_table_names():
|
||||
op.create_table(
|
||||
'system_settings',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('key', sa.String(100), nullable=False),
|
||||
sa.Column('value', sa.String(500), nullable=False),
|
||||
sa.Column('description', sa.String(256), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
op.create_index('ix_system_settings_key', 'system_settings', ['key'], unique=True)
|
||||
op.execute(
|
||||
"INSERT INTO system_settings (key, value, description, updated_at) "
|
||||
"VALUES ('registration_enabled', 'true', "
|
||||
"'Allow new users to self-register via /auth/register', NOW())"
|
||||
)
|
||||
# If the table already exists (created by db.create_all), ensure the
|
||||
# index exists — create_all does not create named Alembic indexes.
|
||||
else:
|
||||
existing_indexes = [idx['name'] for idx in inspector.get_indexes('system_settings')]
|
||||
if 'ix_system_settings_key' not in existing_indexes:
|
||||
op.create_index('ix_system_settings_key', 'system_settings', ['key'], unique=True)
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
Reference in New Issue
Block a user