🔧 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:
@@ -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;
|
||||
|
||||
7
start.sh
7
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
|
||||
|
||||
Reference in New Issue
Block a user