mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-12 01:39:47 +02:00
ANALYSE APPROFONDIE effectuée du problème de décalage horaire. PROBLÈME IDENTIFIÉ: La migration utilisait 'AT TIME ZONE UTC' au lieu de 'Europe/Paris' ce qui causait une mauvaise interprétation des anciennes données. CORRECTIONS APPLIQUÉES: 1. Migration timezone (scripts/migrate-calendar-timezone.js): - Ligne 61: UTC → Europe/Paris pour start_time - Ligne 69: UTC → Europe/Paris pour end_time - Les anciennes données en heure locale sont correctement converties 2. API calendar events (routes/calendar.routes.js): - Ajout de all_day dans le SELECT (ligne 348) - Permettra détection correcte événements toute la journée 3. Script de diagnostic (scripts/diagnose-calendar-timezone.js): - Vérifie timezone PostgreSQL - Affiche format des dates stockées - Compare UTC vs Europe/Paris - Détecte si TIMESTAMPTZ appliqué - Identifie événements avec mauvais timezone - Recommandations de correction UTILISATION DIAGNOSTIC: docker exec notes-todo-app node scripts/diagnose-calendar-timezone.js Le script affichera: - Timezone serveur PostgreSQL - Format des colonnes (TIMESTAMPTZ vs TIMESTAMP) - Exemples de dates (brut, UTC, Paris) - Format renvoyé par driver Node.js - Recommandations si problème détecté SOLUTION FINALE: Après rebuild Docker: 1. La migration supprimera les anciens événements 2. Convertira avec bon timezone (Europe/Paris) 3. Resync Google Calendar récupérera bonnes dates 4. Les heures seront enfin correctes! Fichiers modifiés: - scripts/migrate-calendar-timezone.js (Europe/Paris) - routes/calendar.routes.js (all_day ajouté) - scripts/diagnose-calendar-timezone.js (nouveau)
104 lines
3.1 KiB
JavaScript
Executable File
104 lines
3.1 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
// Migration: Convertir calendar_events TIMESTAMP → TIMESTAMPTZ
|
|
// + Supprimer les données existantes et forcer resynchronisation
|
|
const { Pool } = require('pg');
|
|
|
|
const DATABASE_URL = process.env.DATABASE_URL;
|
|
|
|
if (!DATABASE_URL) {
|
|
console.error('❌ DATABASE_URL non définie');
|
|
process.exit(1);
|
|
}
|
|
|
|
async function migrate() {
|
|
const pool = new Pool({ connectionString: DATABASE_URL });
|
|
|
|
try {
|
|
console.log('\n🔄 Migration: calendar_events TIMESTAMP → TIMESTAMPTZ\n');
|
|
|
|
const client = await pool.connect();
|
|
|
|
// Vérifier le type actuel
|
|
const check = await client.query(`
|
|
SELECT column_name, data_type
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'calendar_events'
|
|
AND column_name IN ('start_time', 'end_time')
|
|
`);
|
|
|
|
console.log('📊 Types actuels:');
|
|
check.rows.forEach(row => {
|
|
console.log(` ${row.column_name}: ${row.data_type}`);
|
|
});
|
|
|
|
// Si déjà TIMESTAMPTZ, skip
|
|
const alreadyMigrated = check.rows.every(row =>
|
|
row.data_type.includes('timestamp with time zone') ||
|
|
row.data_type === 'timestamptz'
|
|
);
|
|
|
|
if (alreadyMigrated) {
|
|
console.log('\n✅ Migration déjà effectuée, rien à faire');
|
|
client.release();
|
|
await pool.end();
|
|
return;
|
|
}
|
|
|
|
console.log('\n🔄 Conversion en cours...');
|
|
|
|
await client.query('BEGIN');
|
|
|
|
// SUPPRIMER toutes les données existantes pour éviter les problèmes de timezone
|
|
console.log(' 🗑️ Suppression des événements existants (seront resynchronisés)');
|
|
const deleteResult = await client.query('DELETE FROM calendar_events');
|
|
console.log(` ✅ ${deleteResult.rowCount} événements supprimés`);
|
|
|
|
// Convertir start_time
|
|
await client.query(`
|
|
ALTER TABLE calendar_events
|
|
ALTER COLUMN start_time TYPE TIMESTAMPTZ
|
|
USING start_time AT TIME ZONE 'Europe/Paris'
|
|
`);
|
|
console.log(' ✅ start_time → TIMESTAMPTZ');
|
|
|
|
// Convertir end_time
|
|
await client.query(`
|
|
ALTER TABLE calendar_events
|
|
ALTER COLUMN end_time TYPE TIMESTAMPTZ
|
|
USING end_time AT TIME ZONE 'Europe/Paris'
|
|
`);
|
|
console.log(' ✅ end_time → TIMESTAMPTZ');
|
|
|
|
await client.query('COMMIT');
|
|
|
|
// Vérifier après migration
|
|
const verify = await client.query(`
|
|
SELECT column_name, data_type
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'calendar_events'
|
|
AND column_name IN ('start_time', 'end_time')
|
|
`);
|
|
|
|
console.log('\n📊 Types après migration:');
|
|
verify.rows.forEach(row => {
|
|
console.log(` ${row.column_name}: ${row.data_type}`);
|
|
});
|
|
|
|
console.log('\n✅ Migration terminée avec succès!');
|
|
console.log('');
|
|
console.log('⚠️ IMPORTANT: Resynchronisez Google Calendar pour récupérer');
|
|
console.log(' vos événements avec les bonnes heures.');
|
|
console.log('');
|
|
|
|
client.release();
|
|
await pool.end();
|
|
|
|
} catch (error) {
|
|
console.error('\n❌ Erreur lors de la migration:', error.message);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
migrate();
|