This commit is contained in:
2026-03-31 10:55:40 -04:00
parent 702fc2cd91
commit d94268f2b9
4 changed files with 189 additions and 31 deletions
+26 -17
View File
@@ -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():