-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_db.js
More file actions
38 lines (31 loc) · 1 KB
/
Copy pathmigrate_db.js
File metadata and controls
38 lines (31 loc) · 1 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
const mysql = require('mysql2/promise');
const fs = require('fs');
const path = require('path');
async function runMigration() {
const config = {
host: '172.29.0.11',
port: 3306,
user: process.argv[2],
password: process.argv[3],
database: 'ods_db',
multipleStatements: true
};
try {
console.log('Connecting to MySQL Server...');
const connection = await mysql.createConnection(config);
console.log('Connected! Reading migration script...');
const sql = fs.readFileSync(path.join(__dirname, 'migration_v2.sql'), 'utf8');
console.log('Executing migration...');
await connection.query(sql);
console.log('Migration completed successfully!');
await connection.end();
} catch (err) {
console.error('Error:', err.message);
process.exit(1);
}
}
if (process.argv.length < 4) {
console.log('Usage: node migrate_db.js <user> <password>');
process.exit(1);
}
runMigration();