70 lines
2.9 KiB
JavaScript
70 lines
2.9 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 为取号增加订单级幂等键,并在取号历史中保存包裹序号与完整返回结果。
|
||
*/
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
await queryInterface.addColumn('waybill_fetch_records', 'package_index', {
|
||
type: Sequelize.INTEGER.UNSIGNED,
|
||
allowNull: true,
|
||
comment: '包裹序号(0 基);历史记录可能为空',
|
||
after: 'express_code',
|
||
});
|
||
await queryInterface.addColumn('waybill_fetch_records', 'result_data', {
|
||
type: Sequelize.TEXT('medium'),
|
||
allowNull: true,
|
||
comment: '完整的逐单返回结果(JSON)',
|
||
after: 'waybill_codes',
|
||
});
|
||
|
||
await queryInterface.createTable('waybill_fetch_idempotencies', {
|
||
id: { type: Sequelize.BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
|
||
principal_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, comment: '主体ID' },
|
||
warehouse_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, comment: '仓库ID' },
|
||
delivery_order_code: { type: Sequelize.STRING(100), allowNull: false, comment: 'OMS 发货单号' },
|
||
express_code: { type: Sequelize.STRING(50), allowNull: false, comment: 'WMS 传入的快递编码' },
|
||
package_index: { type: Sequelize.INTEGER.UNSIGNED, allowNull: false, comment: '包裹序号(0 基)' },
|
||
request_id: { type: Sequelize.STRING(100), allowNull: true, comment: '首次取号的 request_id' },
|
||
status: {
|
||
type: Sequelize.TINYINT,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '状态:0处理中 1成功 2结果待核实',
|
||
},
|
||
result_data: { type: Sequelize.TEXT('medium'), allowNull: true, comment: '成功时完整的逐单返回结果(JSON)' },
|
||
error_message: { type: Sequelize.TEXT, allowNull: true, comment: '结果待核实时的原因' },
|
||
created_at: { type: Sequelize.DATE, allowNull: true, comment: '创建时间' },
|
||
updated_at: { type: Sequelize.DATE, allowNull: true, comment: '更新时间' },
|
||
});
|
||
|
||
await queryInterface.addIndex('waybill_fetch_idempotencies', [
|
||
'principal_id',
|
||
'warehouse_id',
|
||
'delivery_order_code',
|
||
'express_code',
|
||
'package_index',
|
||
], {
|
||
unique: true,
|
||
name: 'uk_waybill_fetch_idempotency',
|
||
});
|
||
await queryInterface.addIndex('waybill_fetch_records', [
|
||
'principal_id',
|
||
'warehouse_id',
|
||
'delivery_order_code',
|
||
'express_code',
|
||
'package_index',
|
||
'status',
|
||
], {
|
||
name: 'idx_waybill_fetch_idempotency_lookup',
|
||
});
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.removeIndex('waybill_fetch_records', 'idx_waybill_fetch_idempotency_lookup');
|
||
await queryInterface.dropTable('waybill_fetch_idempotencies');
|
||
await queryInterface.removeColumn('waybill_fetch_records', 'result_data');
|
||
await queryInterface.removeColumn('waybill_fetch_records', 'package_index');
|
||
},
|
||
};
|