'use strict'; /** * 创建收件任务表 wms_receiving_task。 * * 字段:批次号 batch_no、仓库ID warehouse_id(数据隔离维度)、 * 创建人 creator_id/creator_name、创建时间 created_at。 * 主键 id 自增从 10000 开始(建表后设置 AUTO_INCREMENT = 10000)。 * * 索引: * idx_warehouse_id(按仓库查询) * idx_batch_no(按批次号查询) * idx_creator_id(按创建人查询) */ const TABLE_NAME = 'wms_receiving_task'; const AUTO_INCREMENT_START = 10000; module.exports = { // eslint-disable-next-line no-unused-vars async up(queryInterface, Sequelize) { const { BIGINT, STRING, DATE } = Sequelize; await queryInterface.createTable(TABLE_NAME, { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键ID(自增从10000开始)', }, batch_no: { type: STRING(50), allowNull: false, comment: '批次号', }, warehouse_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '仓库ID(数据隔离维度)', }, creator_id: { type: BIGINT(20).UNSIGNED, allowNull: false, comment: '创建人账户ID', }, creator_name: { type: STRING(50), allowNull: true, comment: '创建人名称快照', }, created_at: { type: DATE, allowNull: false, comment: '创建时间' }, updated_at: { type: DATE, allowNull: false, comment: '更新时间' }, }); // 自增ID从 10000 开始 await queryInterface.sequelize.query( `ALTER TABLE ${TABLE_NAME} AUTO_INCREMENT = ${AUTO_INCREMENT_START}` ); await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id' ], { name: 'idx_warehouse_id' }); await queryInterface.addIndex(TABLE_NAME, [ 'batch_no' ], { name: 'idx_batch_no' }); await queryInterface.addIndex(TABLE_NAME, [ 'creator_id' ], { name: 'idx_creator_id' }); }, // eslint-disable-next-line no-unused-vars async down(queryInterface, Sequelize) { await queryInterface.dropTable(TABLE_NAME); }, };