Add default config for templates

parent 63ca5331
......@@ -2001,6 +2001,85 @@ class Migration_026_AddExtractionStatsTable(DatabaseMigration):
logger.error(f"Failed to drop extraction_stats table: {e}")
return False
class Migration_027_AddDefaultIntroTemplatesConfig(DatabaseMigration):
"""Add default intro templates configuration for Qt player"""
def __init__(self):
super().__init__("027", "Add default intro templates configuration for Qt player")
def up(self, db_manager) -> bool:
"""Add default intro templates configuration to game_config table"""
try:
with db_manager.engine.connect() as conn:
# Check if intro_templates_config already exists
result = conn.execute(text("""
SELECT COUNT(*) FROM game_config WHERE config_key = 'intro_templates_config'
"""))
exists = result.scalar() > 0
if not exists:
# Create default intro templates configuration
default_config = {
"templates": [
{
"name": "fixtures",
"show_time": "00:15"
},
{
"name": "match",
"show_time": "00:15"
}
],
"default_show_time": "00:15",
"rotating_time": "05:00"
}
import json
config_json = json.dumps(default_config)
conn.execute(text("""
INSERT INTO game_config
(config_key, config_value, value_type, description, is_system, created_at, updated_at)
VALUES (:config_key, :config_value, :value_type, :description, :is_system, datetime('now'), datetime('now'))
"""), {
'config_key': 'intro_templates_config',
'config_value': config_json,
'value_type': 'string',
'description': 'Default intro templates configuration for Qt player START_INTRO messages',
'is_system': True
})
logger.info("Added default intro templates configuration")
else:
logger.info("Intro templates configuration already exists")
conn.commit()
logger.info("Default intro templates configuration migration completed successfully")
return True
except Exception as e:
logger.error(f"Failed to add default intro templates configuration: {e}")
return False
def down(self, db_manager) -> bool:
"""Remove default intro templates configuration"""
try:
with db_manager.engine.connect() as conn:
# Remove the intro templates configuration
conn.execute(text("""
DELETE FROM game_config WHERE config_key = 'intro_templates_config'
"""))
conn.commit()
logger.info("Default intro templates configuration removed")
return True
except Exception as e:
logger.error(f"Failed to remove default intro templates configuration: {e}")
return False
# Registry of all migrations in order
MIGRATIONS: List[DatabaseMigration] = [
Migration_001_InitialSchema(),
......@@ -2029,6 +2108,7 @@ MIGRATIONS: List[DatabaseMigration] = [
Migration_024_AddResultOptionsTable(),
Migration_025_AddResultOptionModel(),
Migration_026_AddExtractionStatsTable(),
Migration_027_AddDefaultIntroTemplatesConfig(),
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment