Spaces:
Running
Running
| // 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(); |