DecisionTree/migrations/add_site_config_table.py

36 lines
1.4 KiB
Python

from app import app, db
from models import SiteConfig
def upgrade_database():
"""Add SiteConfig table for site settings"""
with app.app_context():
# Check if table already exists
with db.engine.connect() as conn:
result = conn.execute(db.text("SELECT name FROM sqlite_master WHERE type='table' AND name='site_config'"))
table_exists = result.fetchone() is not None
if not table_exists:
# Create the site_config table
conn.execute(db.text("""
CREATE TABLE site_config (
id INTEGER PRIMARY KEY AUTOINCREMENT,
key VARCHAR(64) NOT NULL UNIQUE,
value VARCHAR(255),
description VARCHAR(255)
)
"""))
print("Created site_config table")
# Add default settings
conn.execute(db.text("""
INSERT INTO site_config (key, value, description)
VALUES ('registration_enabled', 'true', 'Controls whether user registration is enabled')
"""))
print("Added default site settings")
conn.commit()
print("Database migration for site configuration completed successfully")
if __name__ == "__main__":
upgrade_database()