diff --git a/complete_schema.sql b/complete_schema.sql index 0827fba..b246e8c 100644 --- a/complete_schema.sql +++ b/complete_schema.sql @@ -612,17 +612,29 @@ WHERE -- Purpose: Grant full CRUDS access to Admin Policy for all 13 new tables -- Author: Spark Overlord -- Note: This runs automatically during fresh install to unlock new collections +-- Note: Silently skips if directus_policies doesn't exist (first boot before Directus bootstrap) -- =================================================================================== DO $$ DECLARE - admin_policy_id UUID := ( - SELECT id FROM directus_policies - WHERE name = 'Administrator' - LIMIT 1 - ); + admin_policy_id UUID; + table_exists BOOLEAN; BEGIN - -- Skip if no Administrator policy found (will be created by Directus on first boot) + -- Check if directus_policies table exists (it won't on first boot before Directus runs) + SELECT EXISTS ( + SELECT FROM information_schema.tables + WHERE table_schema = 'public' AND table_name = 'directus_policies' + ) INTO table_exists; + + IF NOT table_exists THEN + RAISE NOTICE '⏭️ Skipping permissions grant - directus_policies table not yet created (will be created by Directus bootstrap)'; + RETURN; + END IF; + + -- Get Administrator policy ID + SELECT id INTO admin_policy_id FROM directus_policies WHERE name = 'Administrator' LIMIT 1; + + -- Skip if no Administrator policy found IF admin_policy_id IS NULL THEN RAISE NOTICE '⚠️ Administrator policy not found. Permissions will need to be set manually in Directus.'; RETURN; diff --git a/start.sh b/start.sh index bf7ad3c..ea3b05c 100755 --- a/start.sh +++ b/start.sh @@ -8,8 +8,15 @@ DB_READY=false MAX_RETRIES=30 RETRY_COUNT=0 +# === Fallback for missing env vars (prevents 'role root does not exist') === +DB_USER="${DB_USER:-postgres}" +DB_HOST="${DB_HOST:-postgresql}" +DB_DATABASE="${DB_DATABASE:-directus}" +DB_PASSWORD="${DB_PASSWORD:-Idk@2026lolhappyha232}" + # === Wait for PostgreSQL === echo "📡 Waiting for PostgreSQL to be ready..." +echo "📡 Using DB_USER=$DB_USER, DB_HOST=$DB_HOST, DB_DATABASE=$DB_DATABASE" until [ $DB_READY = true ] || [ $RETRY_COUNT -eq $MAX_RETRIES ]; do if PGPASSWORD="$DB_PASSWORD" psql -h "$DB_HOST" -U "$DB_USER" -d "$DB_DATABASE" -c '\q' 2>/dev/null; then DB_READY=true