Update db.js
This commit is contained in:
18
server/db.js
18
server/db.js
@@ -108,12 +108,28 @@ const initDb = async () => {
|
|||||||
iban VARCHAR(50),
|
iban VARCHAR(50),
|
||||||
paypal_client_id VARCHAR(255),
|
paypal_client_id VARCHAR(255),
|
||||||
default_monthly_quota DECIMAL(10, 2) DEFAULT 100.00,
|
default_monthly_quota DECIMAL(10, 2) DEFAULT 100.00,
|
||||||
|
due_day INT DEFAULT 10,
|
||||||
image VARCHAR(255),
|
image VARCHAR(255),
|
||||||
created_at ${TIMESTAMP_TYPE} DEFAULT CURRENT_TIMESTAMP
|
created_at ${TIMESTAMP_TYPE} DEFAULT CURRENT_TIMESTAMP
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// Migration for condos... (omitted for brevity, assume handled)
|
// Migration for condos due_day
|
||||||
|
try {
|
||||||
|
let hasDueDay = false;
|
||||||
|
if (DB_CLIENT === 'postgres') {
|
||||||
|
const [cols] = await connection.query("SELECT column_name FROM information_schema.columns WHERE table_name='condos'");
|
||||||
|
hasDueDay = cols.some(c => c.column_name === 'due_day');
|
||||||
|
} else {
|
||||||
|
const [cols] = await connection.query("SHOW COLUMNS FROM condos");
|
||||||
|
hasDueDay = cols.some(c => c.Field === 'due_day');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasDueDay) {
|
||||||
|
console.log('Migrating: Adding due_day to condos...');
|
||||||
|
await connection.query("ALTER TABLE condos ADD COLUMN due_day INT DEFAULT 10");
|
||||||
|
}
|
||||||
|
} catch(e) { console.warn("Condo migration warning:", e.message); }
|
||||||
|
|
||||||
// 2. Families Table
|
// 2. Families Table
|
||||||
await connection.query(`
|
await connection.query(`
|
||||||
|
|||||||
Reference in New Issue
Block a user