-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_data.js
More file actions
20 lines (20 loc) · 1.15 KB
/
Copy pathinit_data.js
File metadata and controls
20 lines (20 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const { Client } = require('ssh2');
const conn = new Client();
conn.on('ready', () => {
const sql = [
// 1. users表加phone列(如无)
"ALTER TABLE users ADD COLUMN IF NOT EXISTS phone VARCHAR(20) DEFAULT NULL",
// 2. 插入测试设备(devices为空)
"INSERT IGNORE INTO devices (id,name,model,location,price_per_hour,status) VALUES (1,'Bambu Lab X1C','X1C Carbon','实验室A区',15.00,'idle')",
"INSERT IGNORE INTO devices (id,name,model,location,price_per_hour,status) VALUES (2,'Creality Ender 3 V2','Ender 3 V2','实验室B区',10.00,'idle')",
"INSERT IGNORE INTO devices (id,name,model,location,price_per_hour,status) VALUES (3,'Bambu Lab P1S','P1S','Room 101',20.00,'idle')",
// 3. 查看结果
"SELECT id,name,model,location,status FROM devices"
].join('; ');
conn.exec(`mysql -u root -pBp!8989699 3d_printing -e "${sql}"`, (err, stream) => {
let d = '';
stream.on('data', c => d += c);
stream.stderr.on('data', c => process.stderr.write('' + c));
stream.on('close', () => { console.log(d); conn.end(); });
});
}).connect({ host: '8.148.178.127', port: 22, username: 'root', password: 'Lcqyxql99!' });