From 00ee8876c15a83daa7299a76fe8ce8428726653f Mon Sep 17 00:00:00 2001 From: hsiegeln <37154749+hsiegeln@users.noreply.github.com> Date: Sun, 5 Apr 2026 02:55:43 +0200 Subject: [PATCH] fix: move DB seeding from bootstrap script to Java ApplicationRunner The bootstrap script runs before cameleer-saas (Flyway), so tenant tables don't exist yet. Moved DB seeding to BootstrapDataSeeder ApplicationRunner which runs after Flyway migrations complete. Reads bootstrap JSON and creates tenant/environment/license if missing. Co-Authored-By: Claude Opus 4.6 (1M context) --- docker/logto-bootstrap.sh | 40 +----- .../saas/config/BootstrapDataSeeder.java | 123 ++++++++++++++++++ 2 files changed, 126 insertions(+), 37 deletions(-) create mode 100644 src/main/java/net/siegeln/cameleer/saas/config/BootstrapDataSeeder.java diff --git a/docker/logto-bootstrap.sh b/docker/logto-bootstrap.sh index 8ac1e58..304f590 100644 --- a/docker/logto-bootstrap.sh +++ b/docker/logto-bootstrap.sh @@ -359,42 +359,7 @@ if [ -n "$ADMIN_USER_ID" ] && [ "$ADMIN_USER_ID" != "null" ]; then fi # ============================================================ -# PHASE 7: Seed cameleer_saas database -# ============================================================ - -log "Seeding cameleer_saas database..." -pgpass - -# Insert tenant (idempotent via ON CONFLICT) -TENANT_UUID=$(psql -h "$PG_HOST" -U "$PG_USER" -d "$PG_DB_SAAS" -t -A -c " - INSERT INTO tenants (id, name, slug, tier, status, logto_org_id, created_at, updated_at) - VALUES (gen_random_uuid(), '$TENANT_NAME', '$TENANT_SLUG', 'LOW', 'ACTIVE', '$ORG_ID', NOW(), NOW()) - ON CONFLICT (slug) DO UPDATE SET logto_org_id = EXCLUDED.logto_org_id - RETURNING id; -") -log "Tenant ID: $TENANT_UUID" - -# Insert default environment -psql -h "$PG_HOST" -U "$PG_USER" -d "$PG_DB_SAAS" -c " - INSERT INTO environments (id, tenant_id, slug, display_name, bootstrap_token, status, created_at, updated_at) - VALUES (gen_random_uuid(), '$TENANT_UUID', 'default', 'Default', '$BOOTSTRAP_TOKEN', 'ACTIVE', NOW(), NOW()) - ON CONFLICT (tenant_id, slug) DO NOTHING; -" >/dev/null 2>&1 -log "Default environment seeded." - -# Insert license -psql -h "$PG_HOST" -U "$PG_USER" -d "$PG_DB_SAAS" -c " - INSERT INTO licenses (id, tenant_id, tier, features, limits, issued_at, expires_at, token, created_at) - SELECT gen_random_uuid(), '$TENANT_UUID', 'LOW', - '{\"topology\": true, \"lineage\": false, \"correlation\": false, \"debugger\": false, \"replay\": false}'::jsonb, - '{\"max_agents\": 3, \"retention_days\": 7, \"max_environments\": 1}'::jsonb, - NOW(), NOW() + INTERVAL '365 days', 'bootstrap-license', NOW() - WHERE NOT EXISTS (SELECT 1 FROM licenses WHERE tenant_id = '$TENANT_UUID'); -" >/dev/null 2>&1 -log "License seeded." - -# ============================================================ -# PHASE 8: Configure cameleer3-server OIDC +# PHASE 7: Configure cameleer3-server OIDC # ============================================================ SERVER_HEALTHY=$(curl -sf "${SERVER_ENDPOINT}/api/v1/health" 2>/dev/null && echo "yes" || echo "no") @@ -459,8 +424,9 @@ cat > "$BOOTSTRAP_FILE" <