fix: move DB seeding from bootstrap script to Java ApplicationRunner
All checks were successful
CI / build (push) Successful in 40s
CI / docker (push) Successful in 33s
SonarQube Analysis / sonarqube (push) Successful in 1m21s

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) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-05 02:55:43 +02:00
parent 827e388349
commit 00ee8876c1
2 changed files with 126 additions and 37 deletions

View File

@@ -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" <<EOF
"tradAppId": "$TRAD_ID",
"apiResourceIndicator": "$API_RESOURCE_INDICATOR",
"organizationId": "$ORG_ID",
"tenantName": "$TENANT_NAME",
"tenantSlug": "$TENANT_SLUG",
"tenantId": "$TENANT_UUID",
"bootstrapToken": "$BOOTSTRAP_TOKEN",
"platformAdminUser": "$SAAS_ADMIN_USER",
"tenantAdminUser": "$TENANT_ADMIN_USER"
}