WMS_MAIN/script/tmp-check-video-record-request.cjs
liufumingren c3f1c67592 chore(script): 沉淀波次池/报表/库存/订单本地排查脚本
新增一批一次性排查脚本(script/tmp-*.cjs),与仓库既有 script/tmp- 约定保持一致,
覆盖波次池边界与优先级核对、库位/出库报表核对、订单状态与更新范围核验等场景
2026-09-13 15:31:27 +08:00

64 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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;
});