Store new apps in database

This commit is contained in:
2026-05-28 08:44:35 +02:00
parent 2b0b30a6ec
commit 0459fe28cd
+56 -14
View File
@@ -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-id> [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"