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:
+75
-3
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user