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

38 lines
1.8 KiB
JavaScript

'use strict';
(async () => {
try {
const cfg = require('../database/config.js').production;
const mysql = require('mysql2/promise');
const conn = await mysql.createConnection({
host: cfg.host,
user: cfg.username || cfg.user,
password: cfg.password,
database: cfg.database,
port: cfg.port || 3306,
});
const migrationName = '20260507100000-create-wms_order_wave_strategy_match.js';
const schema = cfg.database;
const [metaRows] = await conn.query('SELECT name FROM SequelizeMeta WHERE name = ? LIMIT 1', [migrationName]);
const migrationInMeta = (metaRows.length && metaRows.length > 0) ? true : false;
const [tableRows] = await conn.query('SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = ? AND table_name = ?', [schema, 'wms_order_wave_strategy_match']);
const tableExists = (tableRows.length && tableRows.length > 0) ? true : false;
const [columnsRows] = await conn.query('SELECT COLUMN_NAME FROM information_schema.columns WHERE table_schema = ? AND table_name = ? AND COLUMN_NAME IN (?,?,?,?,?)', [schema, 'wms_order_wave_strategy_match', 'id','warehouse_id','order_id','strategy_id','create_time']);
const columns = (columnsRows || []).map(r => r.COLUMN_NAME);
const [idxRows] = await conn.query('SELECT DISTINCT INDEX_NAME FROM information_schema.statistics WHERE table_schema = ? AND table_name = ? AND INDEX_NAME IN (?,?)', [schema, 'wms_order_wave_strategy_match', 'idx_warehouse_order', 'idx_warehouse_strategy']);
const indices = (idxRows || []).map(r => r.INDEX_NAME);
console.log(JSON.stringify({ migrationInMeta, tableExists, columns, indices }, null, 2));
await conn.end();
process.exit(0);
} catch (err) {
console.error('ERROR:', err && err.message ? err.message : err);
process.exit(2);
}
})();