mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-12 01:39:47 +02:00
feat: add scripts to fix PostgreSQL boolean data type issues
Added tools to resolve the 500 error when notes don't display due to boolean type mismatches between SQLite (0/1) and PostgreSQL (TRUE/FALSE). New files: - scripts/fix-boolean-data.js: Converts INTEGER columns to BOOLEAN type and migrates existing 0/1 data to FALSE/TRUE - scripts/README-FIXES.md: Instructions for running the fix script Improved: - scripts/migrate-sqlite-to-postgres.js: Now automatically converts 0/1 to FALSE/TRUE for known boolean columns during migration This resolves issues where: - Migrated data contains INTEGER values (0/1) instead of BOOLEAN - SQL queries using "completed = TRUE" fail to match rows - API endpoints return 500 errors To fix an existing database, run: node scripts/fix-boolean-data.js
This commit is contained in:
3 files changed
+172
-1
No files matched your search
@@ -69,6 +69,16 @@ function getSqliteData(tableName) {
|
||||
});
|
||||
}
|
||||
|
||||
// Colonnes booléennes connues (pour conversion 0/1 → FALSE/TRUE)
|
||||
const BOOLEAN_COLUMNS = {
|
||||
users: ['is_admin'],
|
||||
notes: ['archived'],
|
||||
note_todos: ['completed', 'priority'],
|
||||
global_todos: ['completed', 'priority'],
|
||||
rss_feeds: ['enabled'],
|
||||
calendar_events: ['all_day']
|
||||
};
|
||||
|
||||
/**
|
||||
* Insérer les données dans PostgreSQL
|
||||
*/
|
||||
@@ -80,6 +90,7 @@ async function insertPostgresData(tableName, rows) {
|
||||
|
||||
const client = await pgPool.connect();
|
||||
let inserted = 0;
|
||||
const booleanCols = BOOLEAN_COLUMNS[tableName] || [];
|
||||
|
||||
try {
|
||||
await client.query('BEGIN');
|
||||
@@ -87,10 +98,18 @@ async function insertPostgresData(tableName, rows) {
|
||||
for (const row of rows) {
|
||||
// Convertir les noms de colonnes et valeurs
|
||||
const columns = Object.keys(row);
|
||||
const values = Object.values(row).map(val => {
|
||||
const values = columns.map((col, idx) => {
|
||||
const val = Object.values(row)[idx];
|
||||
|
||||
// Convertir les valeurs SQLite vers PostgreSQL
|
||||
if (val === null) return null;
|
||||
if (typeof val === 'boolean') return val;
|
||||
|
||||
// Convertir les colonnes booléennes: 0/1 → FALSE/TRUE
|
||||
if (booleanCols.includes(col) && (val === 0 || val === 1)) {
|
||||
return val === 1;
|
||||
}
|
||||
|
||||
if (typeof val === 'number') return val;
|
||||
// Dates
|
||||
if (typeof val === 'string' && /^\d{4}-\d{2}-\d{2}/.test(val)) {
|
||||
|
||||
Reference in new issue
Block a user