- 订单明细控制器与模型(controller/model/orderItem.js) - 迁移:创建 order_items 表、orders 增加 shop_id - 说明:旧 orders/order_items 模块保留启用,发货单已改用 order_deliveries
24 lines
913 B
JavaScript
24 lines
913 B
JavaScript
'use strict';
|
||
|
||
/** 12. 订单表增加店铺ID:订单归属到具体店铺(可为空,兼容历史订单) */
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
await queryInterface.addColumn('orders', 'shop_id', {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: true,
|
||
comment: '所属店铺ID,为空表示未关联店铺',
|
||
references: { model: 'shops', key: 'id' },
|
||
onDelete: 'SET NULL',
|
||
});
|
||
|
||
await queryInterface.addIndex('orders', { fields: [ 'shop_id' ], name: 'idx_orders_shop' });
|
||
await queryInterface.addIndex('orders', { fields: [ 'principal_id', 'shop_id' ], name: 'idx_orders_principal_shop' });
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.removeIndex('orders', 'idx_orders_principal_shop');
|
||
await queryInterface.removeIndex('orders', 'idx_orders_shop');
|
||
await queryInterface.removeColumn('orders', 'shop_id');
|
||
},
|
||
};
|