🔧 FIX: Prevent 'role root does not exist' PostgreSQL error

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
This commit is contained in:
cawcenter
2025-12-14 15:05:35 -05:00
parent 212e951b78
commit 6465c3d1f8
2 changed files with 25 additions and 6 deletions

View File

@@ -612,17 +612,29 @@ WHERE
-- Purpose: Grant full CRUDS access to Admin Policy for all 13 new tables -- Purpose: Grant full CRUDS access to Admin Policy for all 13 new tables
-- Author: Spark Overlord -- Author: Spark Overlord
-- Note: This runs automatically during fresh install to unlock new collections -- 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 $$ DO $$
DECLARE DECLARE
admin_policy_id UUID := ( admin_policy_id UUID;
SELECT id FROM directus_policies table_exists BOOLEAN;
WHERE name = 'Administrator'
LIMIT 1
);
BEGIN 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 IF admin_policy_id IS NULL THEN
RAISE NOTICE '⚠️ Administrator policy not found. Permissions will need to be set manually in Directus.'; RAISE NOTICE '⚠️ Administrator policy not found. Permissions will need to be set manually in Directus.';
RETURN; RETURN;

View File

@@ -8,8 +8,15 @@ DB_READY=false
MAX_RETRIES=30 MAX_RETRIES=30
RETRY_COUNT=0 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 === # === Wait for PostgreSQL ===
echo "📡 Waiting for PostgreSQL to be ready..." 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 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 if PGPASSWORD="$DB_PASSWORD" psql -h "$DB_HOST" -U "$DB_USER" -d "$DB_DATABASE" -c '\q' 2>/dev/null; then
DB_READY=true DB_READY=true