'use strict'; /** * 创建退回拆包明细表 wms_return_unpack_detail。 * * 字段:关联主表 unpack_id、仓库冗余 warehouse_id、扫描条码 barcode(可空,仅记录)、 * 系统商品 stock_id(可空,关联 wms_stock_warehouse.id)、识别标记 is_recognized、 * 快照 item_code/item_name/spec/product_snapshot、数量 quantity、产品状态 product_status、备注 remark。 * * 索引: * idx_unpack_id(按拆包单查明细,最高频) * idx_warehouse_barcode(仓库+条码) * idx_stock_id(按系统商品反查) * idx_barcode(按条码查询) * * 说明:同一拆包单内可能多次扫描同一条码,明细不设 barcode 唯一约束。 */ const TABLE_NAME = 'wms_return_unpack_detail'; module.exports = { // eslint-disable-next-line no-unused-vars async up(queryInterface, Sequelize) { const { BIGINT, STRING, INTEGER, DATE, TEXT, TINYINT } = Sequelize; await queryInterface.createTable(TABLE_NAME, { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键', }, unpack_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '关联拆包主表 wms_return_unpack.id', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID(冗余,隔离查询)', }, barcode: { type: STRING(100), allowNull: true, comment: '扫描条码(前端可选传入,仅作记录;后端不用于识别)', }, stock_id: { type: BIGINT(20).UNSIGNED, allowNull: true, comment: '关联 wms_stock_warehouse.id;识别到系统商品时回填,非识别为空', }, is_recognized: { type: TINYINT(1), allowNull: false, defaultValue: 0, comment: '是否识别:1=识别到系统商品,0=非识别物品', }, item_code: { type: STRING(50), allowNull: true, comment: '商品编码快照(识别时回填)', }, item_name: { type: STRING(255), allowNull: true, comment: '物品名称(识别时回填;非识别时可手工补录)', }, spec: { type: STRING(100), allowNull: true, comment: '规格快照(sku_property)', }, quantity: { type: INTEGER(11), allowNull: false, defaultValue: 1, comment: '数量', }, product_status: { type: STRING(20), allowNull: false, defaultValue: 'normal', comment: '产品状态:normal-正常,damaged-破损', }, product_snapshot: { type: TEXT, allowNull: true, comment: '商品信息快照(JSON),识别时回填,防止商品资料变更后历史丢失', }, remark: { type: STRING(500), allowNull: true, comment: '备注', }, created_at: { type: DATE, allowNull: false }, updated_at: { type: DATE, allowNull: false }, }); await queryInterface.addIndex(TABLE_NAME, [ 'unpack_id' ], { name: 'idx_unpack_id' }); await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'barcode' ], { name: 'idx_warehouse_barcode' }); await queryInterface.addIndex(TABLE_NAME, [ 'stock_id' ], { name: 'idx_stock_id' }); await queryInterface.addIndex(TABLE_NAME, [ 'barcode' ], { name: 'idx_barcode' }); }, // eslint-disable-next-line no-unused-vars async down(queryInterface, Sequelize) { await queryInterface.dropTable(TABLE_NAME); }, };