67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
'use strict';
|
||
|
||
const TABLE_NAME = 'wms_entry_order_receiving';
|
||
|
||
module.exports = {
|
||
up: async (queryInterface, Sequelize) => {
|
||
const tables = await queryInterface.showAllTables();
|
||
const exists = tables.some(t => (typeof t === 'string' ? t : t.tableName) === TABLE_NAME);
|
||
if (exists) return;
|
||
|
||
await queryInterface.createTable(TABLE_NAME, {
|
||
id: {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
allowNull: false,
|
||
comment: '主键ID',
|
||
},
|
||
entry_order_id: {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '入库单ID,关联 wms_entry_order.id',
|
||
},
|
||
receiving_id: {
|
||
type: Sequelize.BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '收货单ID,关联 wms_receiving.id',
|
||
},
|
||
created_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '创建时间',
|
||
},
|
||
updated_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||
comment: '更新时间',
|
||
},
|
||
deleted_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: true,
|
||
defaultValue: null,
|
||
comment: '软删除时间',
|
||
},
|
||
});
|
||
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'entry_order_id' ], {
|
||
name: 'idx_entry_order_id',
|
||
});
|
||
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'receiving_id' ], {
|
||
name: 'idx_receiving_id',
|
||
});
|
||
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'entry_order_id', 'receiving_id' ], {
|
||
unique: true,
|
||
name: 'uk_entry_order_receiving',
|
||
});
|
||
},
|
||
|
||
down: async queryInterface => {
|
||
await queryInterface.dropTable(TABLE_NAME);
|
||
},
|
||
};
|