Spaces:
Sleeping
Sleeping
File size: 1,444 Bytes
8f23197 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | const pool = require('./config');
const migrate3 = async () => {
const client = await pool.connect();
try {
console.log('๐ Starting database migration (migrate3)...');
await client.query('BEGIN');
// Standalone Jama entries (overall party receipts) - not linked to bills
await client.query(`
CREATE TABLE IF NOT EXISTS party_jama_entries (
id VARCHAR(50) PRIMARY KEY,
party_id VARCHAR(50) NOT NULL REFERENCES parties(id) ON DELETE CASCADE,
entry_date DATE NOT NULL DEFAULT CURRENT_DATE,
amount DECIMAL(12, 2) NOT NULL,
note VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
`);
await client.query(`
CREATE INDEX IF NOT EXISTS idx_party_jama_entries_party_id
ON party_jama_entries(party_id)
`);
await client.query(`
CREATE INDEX IF NOT EXISTS idx_party_jama_entries_entry_date
ON party_jama_entries(entry_date)
`);
await client.query('COMMIT');
console.log('โ
migrate3 completed successfully!');
} catch (error) {
await client.query('ROLLBACK');
console.error('โ migrate3 failed:', error);
throw error;
} finally {
client.release();
await pool.end();
}
};
migrate3().catch(err => {
console.error('Fatal error:', err);
process.exit(1);
});
|