新增一批一次性排查脚本(script/tmp-*.cjs),与仓库既有 script/tmp- 约定保持一致, 覆盖波次池边界与优先级核对、库位/出库报表核对、订单状态与更新范围核验等场景
64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 临时校验:video_record_request 模型定义与 wms_video_record_request 表结构是否一致。
|
||
* 仅只读(describeTable + findAll limit 1),默认连本地开发库:
|
||
* Remove-Item Env:\NODE_ENV; $env:WMS_DB_TARGET='local'; node script/tmp-check-video-record-request.cjs
|
||
*/
|
||
|
||
const SequelizeLib = require('sequelize');
|
||
const dbConfig = require('../database/config');
|
||
|
||
/**
|
||
* 主流程:加载模型定义并与实际表结构比对。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
async function main() {
|
||
const config = dbConfig.production;
|
||
console.log(`[check] target=${config.host}:${config.port}/${config.database} (${(dbConfig.dbTarget || {}).source})`);
|
||
|
||
const sequelize = new SequelizeLib(config.database, config.username, config.password, {
|
||
host: config.host,
|
||
port: config.port,
|
||
dialect: config.dialect || 'mysql',
|
||
logging: false,
|
||
});
|
||
|
||
const app = {
|
||
Sequelize: SequelizeLib,
|
||
model: { define: (name, attrs, opts) => sequelize.define(name, attrs, opts) },
|
||
};
|
||
|
||
try {
|
||
const model = require('../app/model/video_record_request')(app);
|
||
const tableInfo = await sequelize.getQueryInterface().describeTable('wms_video_record_request');
|
||
const tableCols = Object.keys(tableInfo);
|
||
const modelCols = Object.keys(model.rawAttributes);
|
||
|
||
const missingInModel = tableCols.filter(col => !modelCols.includes(col));
|
||
const missingInTable = modelCols.filter(col => !tableCols.includes(col));
|
||
|
||
console.log('[check] modelCols =', modelCols.join(','));
|
||
console.log('[check] missingInModel =', JSON.stringify(missingInModel));
|
||
console.log('[check] missingInTable =', JSON.stringify(missingInTable));
|
||
|
||
const rows = await model.findAll({ limit: 1, raw: true });
|
||
console.log('[check] findAll ok, rows =', rows.length);
|
||
|
||
// 状态机枚举可达性(只读:构造 where 不执行写入)
|
||
const counting = await model.count({ where: { status: 'pending' } });
|
||
console.log('[check] count(status=pending) =', counting);
|
||
|
||
console.log(missingInModel.length === 0 && missingInTable.length === 0
|
||
? '[check] OK: 模型与表结构一致'
|
||
: '[check] MISMATCH: 存在差异');
|
||
} finally {
|
||
await sequelize.close();
|
||
}
|
||
}
|
||
|
||
main().catch(err => {
|
||
console.error('[check] FAILED:', err.message);
|
||
process.exitCode = 1;
|
||
});
|