oms/backend/database/migrations/20260909001903-add-shop-id-on-orders.js
liufumingren 8ef79914f9 feat(backend): 订单明细模块(order_items)与订单店铺字段
- 订单明细控制器与模型(controller/model/orderItem.js)
- 迁移:创建 order_items 表、orders 增加 shop_id
- 说明:旧 orders/order_items 模块保留启用,发货单已改用 order_deliveries
2026-09-13 02:24:01 +08:00

24 lines
913 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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');
},
};