Spaces:
Running
Running
File size: 834 Bytes
1fe073f |
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 |
// Script to initialize the database
const fs = require('fs');
const path = require('path');
const db = require('../config/db');
async function initDB() {
try {
// Read the SQL file
const sql = fs.readFileSync(path.join(__dirname, '../migrations/init.sql'), 'utf8');
// Split the SQL into individual statements
const statements = sql.split(';').filter(stmt => stmt.trim() !== '');
// Execute each statement
for (const statement of statements) {
if (statement.trim() !== '') {
await db.query(statement);
console.log('Executed:', statement.trim().substring(0, 50) + '...');
}
}
console.log('Database initialized successfully!');
} catch (error) {
console.error('Error initializing database:', error);
} finally {
process.exit(0);
}
}
initDB(); |