88919fa0d3
Fixed boolean value handling differences between databases: - SQLite stores booleans as 0/1, PostgreSQL as true/false - Add formatBoolean() calls to critical queries that were failing Files fixed: - adminEvents.js: Fixed status filters and archive queries - adminDashboard.js: Fixed active/archived event counts - expirationChecker.js: Fixed expiration checking queries - dbCompat.js: Updated to avoid circular dependency Added migration 024 to: - Enable foreign keys for SQLite (PRAGMA foreign_keys = ON) - Document boolean compatibility requirements This fixes queries returning 0 results in SQLite when checking boolean columns like is_active, is_archived. Critical for proper event management and expiration handling. Note: 23 more boolean comparisons remain to be fixed in other files.
29 lines
882 B
JavaScript
29 lines
882 B
JavaScript
/**
|
|
* Fix boolean compatibility issues between PostgreSQL and SQLite
|
|
* This migration updates the database configuration and existing data
|
|
*/
|
|
|
|
exports.up = async function(knex) {
|
|
const isPostgres = knex.client.config.client === 'pg';
|
|
|
|
if (!isPostgres) {
|
|
// Enable foreign keys for SQLite
|
|
await knex.raw('PRAGMA foreign_keys = ON');
|
|
|
|
// Note: SQLite stores booleans as 0/1
|
|
// No data migration needed as Knex handles this automatically
|
|
// But queries must use formatBoolean() helper
|
|
|
|
console.log('SQLite boolean compatibility check:');
|
|
console.log('- SQLite stores booleans as 0/1');
|
|
console.log('- All boolean comparisons should use formatBoolean() helper');
|
|
console.log('- Foreign keys enabled');
|
|
}
|
|
|
|
return Promise.resolve();
|
|
};
|
|
|
|
exports.down = async function(knex) {
|
|
// No rollback needed
|
|
return Promise.resolve();
|
|
}; |