From e71d81c05d9fcb9e1b063cc254b14dd51a7a4b58 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Sun, 23 Nov 2025 17:13:20 +0100 Subject: [PATCH 1/2] feat: Add automatic database schema migrations for tracking timestamps, priority, and in-progress fields, executed at startup. --- docker-entrypoint.sh | 4 ++++ scripts/auto-migrate.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b30abcc..5954de5 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -75,6 +75,10 @@ else echo "✅ PostgreSQL contient déjà des données ($HAS_DATA utilisateurs)" fi +echo "" +echo "🔄 Vérification des migrations de schéma..." +node scripts/auto-migrate.js + 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" diff --git a/scripts/auto-migrate.js b/scripts/auto-migrate.js index fc85faa..ab25009 100644 --- a/scripts/auto-migrate.js +++ b/scripts/auto-migrate.js @@ -167,6 +167,20 @@ async function autoMigrate() { await client.query(`ALTER TABLE note_todos ADD COLUMN priority BOOLEAN DEFAULT FALSE`); } + // Migration 3: Champ in_progress pour les tâches globales + logger.info(' Vérification: champ in_progress pour global_todos...'); + + const globalTodosInProgressExists = await client.query(` + SELECT column_name + FROM information_schema.columns + WHERE table_name='global_todos' AND column_name='in_progress' + `); + + if (globalTodosInProgressExists.rows.length === 0) { + logger.info(' → Ajout du champ in_progress à global_todos'); + await client.query('ALTER TABLE global_todos ADD COLUMN in_progress INTEGER DEFAULT 0'); + } + // Créer les index pour performance await client.query(`CREATE INDEX IF NOT EXISTS idx_global_todos_priority ON global_todos(priority DESC, created_at DESC)`); await client.query(`CREATE INDEX IF NOT EXISTS idx_note_todos_priority ON note_todos(priority DESC, position)`); From 2703e80afab98b48c334f13ad595eba50e612061 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Sun, 23 Nov 2025 17:28:55 +0100 Subject: [PATCH 2/2] feat: Add PostgreSQL database connection, custom type parsers, and initial schema definition for all application tables. --- config/database.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/config/database.js b/config/database.js index 39f6973..cd4cbd2 100644 --- a/config/database.js +++ b/config/database.js @@ -12,7 +12,7 @@ const timezoneLogger = require('../services/timezone-logger'); // - 1184 = TIMESTAMP WITH TIME ZONE (TIMESTAMPTZ) // Parser pour TIMESTAMPTZ (1184) -types.setTypeParser(1184, function(stringValue) { +types.setTypeParser(1184, function (stringValue) { if (!stringValue) return null; const originalValue = stringValue; @@ -38,7 +38,7 @@ types.setTypeParser(1184, function(stringValue) { // mais PostgreSQL les retourne sans fuseau horaire. // Exemple: Google envoie "2025-11-17T10:20:00+01:00" → PG stocke "2025-11-17 10:20:00" // On doit interpréter cette heure comme UTC (car PG a converti lors de l'insertion) -types.setTypeParser(1114, function(stringValue) { +types.setTypeParser(1114, function (stringValue) { if (!stringValue) return null; // PostgreSQL retourne "YYYY-MM-DD HH:MM:SS" sans fuseau horaire @@ -108,6 +108,7 @@ async function initDatabase() { content TEXT, image_filename TEXT, archived BOOLEAN DEFAULT FALSE, + archived_at TIMESTAMP, priority INTEGER DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP @@ -121,7 +122,10 @@ async function initDatabase() { note_id INTEGER NOT NULL REFERENCES notes(id) ON DELETE CASCADE, text TEXT NOT NULL, completed BOOLEAN DEFAULT FALSE, - position INTEGER DEFAULT 0 + priority BOOLEAN DEFAULT FALSE, + position INTEGER DEFAULT 0, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + completed_at TIMESTAMP ) `); @@ -132,7 +136,10 @@ async function initDatabase() { user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, text TEXT NOT NULL, completed BOOLEAN DEFAULT FALSE, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + priority BOOLEAN DEFAULT FALSE, + in_progress INTEGER DEFAULT 0, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + completed_at TIMESTAMP ) `);