From 6465c3d1f81ce443beb68dab56fac7f1974b8ead Mon Sep 17 00:00:00 2001 From: cawcenter Date: Sun, 14 Dec 2025 15:05:35 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20FIX:=20Prevent=20'role=20root=20?= =?UTF-8?q?does=20not=20exist'=20PostgreSQL=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit start.sh: - Added fallback defaults for DB_USER, DB_HOST, DB_DATABASE, DB_PASSWORD - Ensures psql always uses 'postgres' user even if env vars missing - Added debug logging to show which credentials are being used complete_schema.sql: - Permissions Protocol now checks if directus_policies table exists first - Silently skips on first boot (before Directus creates its tables) - Prevents SQL errors during fresh install --- complete_schema.sql | 24 ++++++++++++++++++------ start.sh | 7 +++++++ 2 files changed, 25 insertions(+), 6 deletions(-) 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