WMS_MAIN/script/check_tables.cjs
liufumingren 9c2b254206 1
Co-authored-by: Copilot <copilot@github.com>
2026-05-11 08:44:27 +08:00

22 lines
978 B
JavaScript

(async () => {
try {
const configs = require('../database/config.js');
const env = process.env.NODE_ENV || 'development';
const cfg = configs[env];
if (!cfg) {
console.error('NO_CONFIG_FOR_ENV');
process.exit(2);
}
const mysql = require('mysql2/promise');
const conn = await mysql.createConnection({ host: cfg.host, user: cfg.username, password: cfg.password, database: cfg.database, port: cfg.port || 3306 });
const [rows] = await conn.execute("SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = ? AND TABLE_NAME IN (?,?)", [cfg.database, 'wms_wave_strategy', 'wms_picking_strategy']);
const exists = { wms_wave_strategy: false, wms_picking_strategy: false };
for (const r of rows) { exists[r.TABLE_NAME] = true; }
console.log(JSON.stringify({ env, database: cfg.database, exists }));
await conn.end();
} catch (err) {
console.error('ERROR', err.message);
process.exit(3);
}
})();