- 商品/商品图片、店铺、店铺商品、组合商品及明细 - 仓库、仓库商品(WMS itemId 映射)、仓库接口配置与字段定义(warehouseApi/warehouseApiField) - 库存:stock_items、product_stocks(ZC/CC 双维度)与库存重算工具(utils/recalcStock.js) - 库存单据与对接日志:stock orders、api_outbound_logs - 相关迁移:shops/shop_products/stock_orders/warehouses/warehouse_apis/warehouse_products/product_stocks/files-images 等表与字段
64 lines
2.4 KiB
JavaScript
64 lines
2.4 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 仓库-商品关联表:只做极简关联,记录某个商品是否已推送到某个仓库
|
||
* - pushed:是否已推送(1是 0否)
|
||
* - pushed_at:最近一次推送时间
|
||
* 删除仓库或删除仓库接口配置时,都会清空该仓库下的关联数据
|
||
*/
|
||
module.exports = {
|
||
async up(queryInterface, Sequelize) {
|
||
await queryInterface.createTable(
|
||
'warehouse_products',
|
||
{
|
||
id: { type: Sequelize.BIGINT.UNSIGNED, autoIncrement: true, primaryKey: true },
|
||
principal_id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: false,
|
||
comment: '所属主体ID',
|
||
references: { model: 'principals', key: 'id' },
|
||
onDelete: 'CASCADE',
|
||
},
|
||
warehouse_id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: false,
|
||
comment: '仓库ID',
|
||
references: { model: 'warehouses', key: 'id' },
|
||
onDelete: 'CASCADE',
|
||
},
|
||
product_id: {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: false,
|
||
comment: '商品ID',
|
||
references: { model: 'products', key: 'id' },
|
||
onDelete: 'CASCADE',
|
||
},
|
||
pushed: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 0, comment: '是否已推送到仓库:1是 0否' },
|
||
pushed_at: { type: Sequelize.DATE, comment: '最近一次推送时间' },
|
||
created_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
},
|
||
updated_at: {
|
||
type: Sequelize.DATE,
|
||
allowNull: false,
|
||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
|
||
},
|
||
},
|
||
{ charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '仓库-商品关联表(是否推送到仓库)' }
|
||
);
|
||
await queryInterface.addIndex('warehouse_products', {
|
||
fields: [ 'warehouse_id', 'product_id' ],
|
||
unique: true,
|
||
name: 'uk_warehouse_products_warehouse_product',
|
||
});
|
||
await queryInterface.addIndex('warehouse_products', { fields: [ 'principal_id' ], name: 'idx_warehouse_products_principal' });
|
||
await queryInterface.addIndex('warehouse_products', { fields: [ 'product_id' ], name: 'idx_warehouse_products_product' });
|
||
},
|
||
|
||
async down(queryInterface) {
|
||
await queryInterface.dropTable('warehouse_products');
|
||
},
|
||
};
|