-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_db.js
More file actions
41 lines (33 loc) · 1.15 KB
/
Copy pathsetup_db.js
File metadata and controls
41 lines (33 loc) · 1.15 KB
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
const mysql = require('mysql2/promise');
const fs = require('fs');
const path = require('path');
async function setupDatabase() {
const config = {
host: '172.29.0.11',
port: 3306,
user: process.argv[2],
password: process.argv[3],
multipleStatements: true
};
try {
console.log('Connecting to MySQL Server...');
const connection = await mysql.createConnection(config);
console.log('Connected! Reading schema...');
const schemaSql = fs.readFileSync(path.join(__dirname, 'schema.sql'), 'utf8');
console.log('Executing schema...');
await connection.query(schemaSql);
console.log('Database setup completed successfully!');
console.log('Created DB: ods_db');
console.log('Created Tables: users, orders');
console.log('Default Admin: admin / admin123');
await connection.end();
} catch (err) {
console.error('Error:', err.message);
process.exit(1);
}
}
if (process.argv.length < 4) {
console.log('Usage: node setup_db.js <user> <password>');
process.exit(1);
}
setupDatabase();