WMS_MAIN/database/migrations/20261124150000-add-pdf-base64-to-wms-order-express.js
liufumingren e9d081ed4e feat: support Shopify PDF waybill printing
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-25 00:19:34 +08:00

48 lines
1.6 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';
/**
* 为运单表新增 PDF 面单 base64 字段。
*
* - `pdf_base64`:部分 PDF 面单渠道取号返回的面单 PDF base64,直接落库。
*/
module.exports = {
/**
* 执行迁移:新增 pdf_base64(幂等)。
*
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {import('sequelize')} Sequelize Sequelize 实例。
* @return {Promise<void>} 无返回值。
*/
async up(queryInterface, Sequelize) {
const tableName = 'wms_order_express';
const columns = await queryInterface.describeTable(tableName);
if (columns.pdf_base64) {
return;
}
// 拿不到元数据锁时快速失败:MDL 排队会把后续所有读写一起堵住,
// 30 秒内拿不到锁就报错退出(可安全重试),避免拖垮生产可用性
await queryInterface.sequelize.query('SET SESSION lock_wait_timeout = 30');
await queryInterface.sequelize.query(
`ALTER TABLE \`${tableName}\` ADD COLUMN \`pdf_base64\` ${Sequelize.TEXT('long')} NULL DEFAULT NULL COMMENT 'PDF面单 base64(部分PDF面单渠道取号返回,直接存储)' AFTER \`cai_niao_auth_info_id\``
);
},
/**
* 回滚迁移:删除新增字段(幂等)。
*
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<void>} 无返回值。
*/
async down(queryInterface) {
const tableName = 'wms_order_express';
const columns = await queryInterface.describeTable(tableName);
if (columns.pdf_base64) {
await queryInterface.removeColumn(tableName, 'pdf_base64');
}
},
};