oms/backend/database/migrations/20260910000100-create-warehouses.js
liufumingren cbd16752a5 feat(backend): 商品、店铺、组合商品、仓库与库存模块
- 商品/商品图片、店铺、店铺商品、组合商品及明细
- 仓库、仓库商品(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 等表与字段
2026-09-13 02:23:39 +08:00

54 lines
2.6 KiB
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';
/**
* 新建仓库表,并把原外部接口(principal_external_apis)中的外部仓库数据迁移过来
* principal_external_apis 表随后废弃(不再被任何接口使用)
*/
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable(
'warehouses',
{
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',
},
code: { type: Sequelize.STRING(50), allowNull: false, comment: '仓库编码' },
name: { type: Sequelize.STRING(100), allowNull: false, comment: '仓库名称' },
type: { type: Sequelize.STRING(50), comment: '仓库类型:wms/erp/other' },
base_url: { type: Sequelize.STRING(255), comment: '接口基础地址' },
app_key: { type: Sequelize.STRING(100), comment: '应用Key' },
app_secret: { type: Sequelize.STRING(255), comment: '应用密钥' },
extra: { type: Sequelize.JSON, comment: '扩展配置' },
status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
remark: { type: Sequelize.STRING(255), comment: '备注' },
deleted_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('warehouses', { fields: ['principal_id'], name: 'idx_warehouses_principal' });
await queryInterface.addIndex('warehouses', {
fields: ['principal_id', 'code'],
unique: true,
name: 'uk_warehouses_principal_code',
});
// 迁移原外部接口中的仓库数据(type 取原系统标识)
await queryInterface.sequelize.query(`
INSERT INTO warehouses (principal_id, code, name, type, base_url, app_key, app_secret, extra, status, remark, created_at, updated_at)
SELECT principal_id, code, name, code, base_url, app_key, app_secret, extra, status, '由外部接口迁移', NOW(), NOW()
FROM principal_external_apis
`);
},
async down(queryInterface) {
await queryInterface.dropTable('warehouses');
},
};