Co se změnilo:

app_templates je teď jediný source of truth.
Detail služby načítá šablony přes is_enabled = 1.
Vytvoření služby načítá šablony přes is_enabled = 1 AND create_enabled = 1.
Select hodnoty používají app_templates.id, takže fastapi odpovídá existující službě microsoft-365-service.
Při vytvoření služby se z vybrané šablony nastaví template, runtime, language, container_port a health_url.
Neznámá šablona se zobrazí jako Neznámá šablona a detail nespadne.
Hardcoded python-fastapi / seznam šablon byl odstraněn.
This commit is contained in:
JiriUhlir
2026-06-03 09:02:36 +02:00
parent 786d055f6b
commit 54c86702d2
3 changed files with 135 additions and 15 deletions
+75 -3
View File
@@ -82,14 +82,26 @@ def get_app(app_id: str):
return dict(row) if row else None
def get_app_templates():
def get_app_templates(create_enabled: bool = False):
run_migrations()
con = get_connection()
create_filter = "AND create_enabled = 1" if create_enabled else ""
rows = con.execute(
"""
SELECT name, runtime, description
f"""
SELECT
id,
name,
runtime,
language,
description,
default_port,
default_health_path,
COALESCE(is_enabled, 1) AS is_enabled,
COALESCE(create_enabled, 0) AS create_enabled
FROM app_templates
WHERE COALESCE(is_enabled, 1) = 1
{create_filter}
ORDER BY name
"""
).fetchall()
@@ -98,6 +110,66 @@ def get_app_templates():
return [dict(row) for row in rows]
def get_app_template(template_id: str, create_enabled: bool = False):
run_migrations()
con = get_connection()
create_filter = "AND COALESCE(create_enabled, 0) = 1" if create_enabled else ""
row = con.execute(
f"""
SELECT
id,
name,
runtime,
language,
description,
default_port,
default_health_path,
COALESCE(is_enabled, 1) AS is_enabled,
COALESCE(create_enabled, 0) AS create_enabled
FROM app_templates
WHERE id = ?
AND COALESCE(is_enabled, 1) = 1
{create_filter}
""",
(template_id,),
).fetchone()
con.close()
return dict(row) if row else None
def update_app_template_metadata(app_id: str, metadata: dict):
run_migrations()
con = get_connection()
con.execute(
"""
UPDATE apps
SET name = ?,
template = ?,
runtime = ?,
language = ?,
health_url = ?,
container_port = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
""",
(
metadata.get("name") or None,
metadata.get("template") or None,
metadata.get("runtime") or None,
metadata.get("language") or None,
metadata.get("health_url") or None,
metadata.get("container_port"),
app_id,
),
)
con.commit()
con.close()
def update_app_metadata(app_id: str, metadata: dict):
run_migrations()
con = get_connection()
+18 -1
View File
@@ -88,9 +88,15 @@ def run_migrations():
con.execute(
"""
CREATE TABLE IF NOT EXISTS app_templates (
name TEXT PRIMARY KEY,
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
runtime TEXT,
language TEXT,
description TEXT,
default_port INTEGER,
default_health_path TEXT,
is_enabled INTEGER NOT NULL DEFAULT 1,
create_enabled INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
)
@@ -125,8 +131,15 @@ def run_migrations():
"""
)
for statement in (
"ALTER TABLE app_templates ADD COLUMN id TEXT",
"ALTER TABLE app_templates ADD COLUMN name TEXT",
"ALTER TABLE app_templates ADD COLUMN runtime TEXT",
"ALTER TABLE app_templates ADD COLUMN language TEXT",
"ALTER TABLE app_templates ADD COLUMN description TEXT",
"ALTER TABLE app_templates ADD COLUMN default_port INTEGER",
"ALTER TABLE app_templates ADD COLUMN default_health_path TEXT",
"ALTER TABLE app_templates ADD COLUMN is_enabled INTEGER NOT NULL DEFAULT 1",
"ALTER TABLE app_templates ADD COLUMN create_enabled INTEGER NOT NULL DEFAULT 0",
"ALTER TABLE app_templates ADD COLUMN created_at TEXT",
"ALTER TABLE app_templates ADD COLUMN updated_at TEXT",
"ALTER TABLE app_variables ADD COLUMN created_at TEXT",
@@ -136,6 +149,10 @@ def run_migrations():
con.execute(statement)
except Exception:
pass
try:
con.execute("UPDATE app_templates SET id = name WHERE id IS NULL OR id = ''")
except Exception:
pass
con.execute("CREATE INDEX IF NOT EXISTS idx_app_variables_app_id ON app_variables(app_id)")
con.execute("CREATE INDEX IF NOT EXISTS idx_service_incidents_status_started ON service_incidents(status, started_at)")
con.execute("CREATE INDEX IF NOT EXISTS idx_service_incidents_service_started ON service_incidents(service_id, started_at)")