Spaces:
Sleeping
Sleeping
File size: 1,355 Bytes
9eab1a6 | 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 | const pool = require('./config');
const resetDatabase = async () => {
const client = await pool.connect();
try {
console.log('π Resetting database...');
await client.query('BEGIN');
// Drop all tables in reverse order of dependencies
await client.query('DROP TABLE IF EXISTS payments CASCADE');
await client.query('DROP TABLE IF EXISTS expenses CASCADE');
await client.query('DROP TABLE IF EXISTS transaction_items CASCADE');
await client.query('DROP TABLE IF EXISTS transactions CASCADE');
await client.query('DROP TABLE IF EXISTS lots CASCADE');
await client.query('DROP TABLE IF EXISTS mirchi_types CASCADE');
await client.query('DROP TABLE IF EXISTS parties CASCADE');
await client.query('COMMIT');
console.log('β
Database reset completed!');
console.log('π‘ Run "npm run migrate" to recreate tables');
console.log('π‘ Run "npm run seed" to populate with sample data');
} catch (error) {
await client.query('ROLLBACK');
console.error('β Reset failed:', error);
throw error;
} finally {
client.release();
await pool.end();
}
};
resetDatabase().catch(err => {
console.error('Fatal error:', err);
process.exit(1);
});
|