fix: critical boolean compatibility for PostgreSQL/SQLite
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.
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
* Handles differences between PostgreSQL and SQLite
|
||||
*/
|
||||
|
||||
const { db } = require('../database/db');
|
||||
// Note: Requiring db here creates circular dependency
|
||||
// db should be passed as parameter or required where needed
|
||||
|
||||
/**
|
||||
* Get database client type
|
||||
@@ -58,10 +59,11 @@ function addDays(date, days) {
|
||||
|
||||
/**
|
||||
* Get date extraction SQL that works on both databases
|
||||
* @param {object} db - Knex database instance
|
||||
* @param {string} column - Column name
|
||||
* @returns {object} Knex raw query
|
||||
*/
|
||||
function dateExtractSQL(column) {
|
||||
function dateExtractSQL(db, column) {
|
||||
if (isPostgreSQL()) {
|
||||
return db.raw(`DATE(${column})`);
|
||||
} else {
|
||||
@@ -72,10 +74,11 @@ function dateExtractSQL(column) {
|
||||
|
||||
/**
|
||||
* Get database size query
|
||||
* @param {object} db - Knex database instance
|
||||
* @param {string} dbName - Database name
|
||||
* @returns {Promise<number>} Size in bytes
|
||||
*/
|
||||
async function getDatabaseSize(dbName) {
|
||||
async function getDatabaseSize(db, dbName) {
|
||||
if (isPostgreSQL()) {
|
||||
const result = await db.raw('SELECT pg_database_size(?) as size', [dbName]);
|
||||
return result.rows[0]?.size || 0;
|
||||
|
||||
Reference in New Issue
Block a user