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