Register apps before queued deployment
This commit is contained in:
+107
@@ -174,6 +174,113 @@ def update_app_template_metadata(app_id: str, metadata: dict):
|
||||
con.close()
|
||||
|
||||
|
||||
def upsert_created_app(app_id: str, metadata: dict):
|
||||
run_migrations()
|
||||
con = get_connection()
|
||||
|
||||
values = (
|
||||
metadata.get("name") or app_id,
|
||||
metadata.get("language") or None,
|
||||
metadata.get("version") or "1.0.0",
|
||||
metadata.get("status") or "created",
|
||||
metadata.get("memory") or None,
|
||||
metadata.get("cpus") or None,
|
||||
metadata.get("description") or None,
|
||||
metadata.get("owner") or None,
|
||||
metadata.get("template") or None,
|
||||
metadata.get("runtime") or None,
|
||||
metadata.get("repository_url") or None,
|
||||
metadata.get("repository_name") or app_id,
|
||||
metadata.get("default_branch") or "main",
|
||||
metadata.get("health_url") or None,
|
||||
metadata.get("container_port"),
|
||||
1 if metadata.get("is_public") else 0,
|
||||
1 if metadata.get("is_enabled") else 0,
|
||||
)
|
||||
|
||||
try:
|
||||
cur = con.execute(
|
||||
"""
|
||||
UPDATE apps
|
||||
SET name = ?,
|
||||
language = ?,
|
||||
version = ?,
|
||||
status = ?,
|
||||
memory = ?,
|
||||
cpus = ?,
|
||||
description = ?,
|
||||
owner = ?,
|
||||
template = ?,
|
||||
runtime = ?,
|
||||
repository_url = ?,
|
||||
repository_name = ?,
|
||||
default_branch = ?,
|
||||
health_url = ?,
|
||||
container_port = ?,
|
||||
is_public = ?,
|
||||
is_enabled = ?,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?
|
||||
""",
|
||||
(*values, app_id),
|
||||
)
|
||||
|
||||
if cur.rowcount == 0:
|
||||
con.execute(
|
||||
"""
|
||||
INSERT INTO apps (
|
||||
id,
|
||||
name,
|
||||
language,
|
||||
version,
|
||||
status,
|
||||
memory,
|
||||
cpus,
|
||||
updated_at,
|
||||
description,
|
||||
owner,
|
||||
template,
|
||||
runtime,
|
||||
repository_url,
|
||||
repository_name,
|
||||
default_branch,
|
||||
health_url,
|
||||
container_port,
|
||||
is_public,
|
||||
is_enabled
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
app_id,
|
||||
values[0],
|
||||
values[1],
|
||||
values[2],
|
||||
values[3],
|
||||
values[4],
|
||||
values[5],
|
||||
values[6],
|
||||
values[7],
|
||||
values[8],
|
||||
values[9],
|
||||
values[10],
|
||||
values[11],
|
||||
values[12],
|
||||
values[13],
|
||||
values[14],
|
||||
values[15],
|
||||
values[16],
|
||||
),
|
||||
)
|
||||
|
||||
con.commit()
|
||||
except Exception:
|
||||
con.rollback()
|
||||
raise
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
|
||||
def update_app_metadata(app_id: str, metadata: dict):
|
||||
run_migrations()
|
||||
con = get_connection()
|
||||
|
||||
Reference in New Issue
Block a user