fix: auto-correct PostgreSQL boolean types at Docker startup

Automatically fixes INTEGER->BOOLEAN type mismatches when Docker starts.
This resolves the 500 error on /api/notes without manual intervention.

Changes:
- scripts/fix-postgres-boolean-types.sql: Idempotent SQL script that
  detects INTEGER columns that should be BOOLEAN and converts them
  (0→FALSE, 1→TRUE) for all affected tables

- docker-entrypoint.sh: Executes the boolean correction script
  automatically after migrations and before starting the server

The script corrects these columns:
  • users.is_admin
  • notes.archived
  • note_todos.completed, note_todos.priority
  • global_todos.completed, global_todos.priority
  • rss_feeds.enabled
  • calendar_events.all_day

The correction is idempotent and runs on every container restart,
ensuring data integrity even after database migrations.

Fixes: Notes not displaying due to boolean type mismatch
This commit is contained in:
Claude committed 2025-11-28 16:42:31 +00:00
1 parent 1687f1fa2c
commit b661f7f2f6
2 files changed
+114

No files matched your search

+23
View File
@@ -83,6 +83,29 @@ echo ""
echo "🔄 Migration des timezones du calendrier..."
node scripts/migrate-calendar-timezone.js 2>/dev/null || echo " ℹ️ Migration timezone déjà effectuée ou non nécessaire"
echo ""
echo "🔧 Correction des types booléens PostgreSQL..."
# Exécuter le script SQL de correction des types booléens
if [ -f "/app/scripts/fix-postgres-boolean-types.sql" ]; then
# Extraire les informations de connexion depuis DATABASE_URL
PGHOST=$(echo $DATABASE_URL | sed -n 's/.*@\([^:]*\):.*/\1/p')
PGPORT=$(echo $DATABASE_URL | sed -n 's/.*:\([0-9]*\)\/.*/\1/p')
PGUSER=$(echo $DATABASE_URL | sed -n 's/.*\/\/\([^:]*\):.*/\1/p')
PGPASSWORD=$(echo $DATABASE_URL | sed -n 's/.*:\/\/[^:]*:\([^@]*\)@.*/\1/p')
PGDATABASE=$(echo $DATABASE_URL | sed -n 's/.*\/\([^?]*\).*/\1/p')
export PGHOST PGPORT PGUSER PGPASSWORD PGDATABASE
# Exécuter le script SQL
if psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDATABASE" -f /app/scripts/fix-postgres-boolean-types.sql > /dev/null 2>&1; then
echo " ✅ Types booléens corrigés"
else
echo " ℹ️ Correction des types booléens déjà effectuée ou non nécessaire"
fi
else
echo " ⚠️ Script de correction non trouvé"
fi
echo ""
echo "========================================"
echo "🚀 Démarrage du serveur NoteFlow..."