From 0459fe28cdc6753d11b548909bdaf27f77e1ff25 Mon Sep 17 00:00:00 2001 From: Jiri Uhlir Date: Thu, 28 May 2026 08:44:35 +0200 Subject: [PATCH] Store new apps in database --- scripts/new-python-app.sh | 70 +++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/scripts/new-python-app.sh b/scripts/new-python-app.sh index 6c3c527..652f971 100755 --- a/scripts/new-python-app.sh +++ b/scripts/new-python-app.sh @@ -7,24 +7,21 @@ source "$CONFIG_FILE" APP_ID="${1:-}" APP_NAME="${2:-$APP_ID}" +DB_FILE="/opt/appfactory/data/appfactory/appfactory.db" +TEMPLATE_DIR="$WORKSPACE_DIR/python-fastapi-template" +TARGET_DIR="$WORKSPACE_DIR/$APP_ID" +TOOLS_DIR="$WORKSPACE_DIR/appfactory-tools" + if [ -z "$APP_ID" ]; then echo "Usage: ./new-python-app.sh [app-name]" exit 1 fi -TEMPLATE_DIR="$WORKSPACE_DIR/python-fastapi-template" -TARGET_DIR="$WORKSPACE_DIR/$APP_ID" - -safe_chown() { - local target="$1" - local uid - local gid - - uid="${APP_UID:-$(stat -c '%u' "$WORKSPACE_DIR")}" - gid="${APP_GID:-$(stat -c '%g' "$WORKSPACE_DIR")}" - - chown -R "$uid:$gid" "$target" || true -} +if [ ! -f "$DB_FILE" ]; then + echo "Missing database: $DB_FILE" + echo "Run: $TOOLS_DIR/scripts/init-appfactory-db.sh" + exit 1 +fi if [ ! -d "$TEMPLATE_DIR" ]; then echo "Template not found: $TEMPLATE_DIR" @@ -110,7 +107,52 @@ git add . git commit -m "Initial $APP_NAME" git push -u origin main -safe_chown "$TARGET_DIR" +echo "Saving app to database..." + +python3 - "$DB_FILE" "$APP_ID" "$APP_NAME" <<'PY' +import sqlite3 +import sys + +db_file = sys.argv[1] +app_id = sys.argv[2] +app_name = sys.argv[3] + +con = sqlite3.connect(db_file) + +con.execute( + """ + INSERT INTO apps ( + id, + name, + language, + version, + status + ) + VALUES (?, ?, ?, ?, ?) + ON CONFLICT(id) DO UPDATE SET + name = excluded.name, + language = excluded.language, + version = excluded.version, + status = excluded.status, + updated_at = CURRENT_TIMESTAMP + """, + ( + app_id, + app_name or app_id, + "python", + "1.0.0", + "created", + ), +) + +con.commit() +con.close() +PY + +"$TOOLS_DIR/scripts/generate-catalog.sh" +"$TOOLS_DIR/scripts/generate-apps-compose.sh" +"$TOOLS_DIR/scripts/generate-caddyfile.sh" +"$TOOLS_DIR/scripts/generate-apps-page.sh" echo "" echo "DONE"