- 商品/商品图片、店铺、店铺商品、组合商品及明细 - 仓库、仓库商品(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 等表与字段
49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* 修正 products 表列名,使其与外部商品结构及 Product 模型保持一致:
|
|
* code→item_code、name→item_name、sku_code→goods_code、type→item_type、
|
|
* category→category_name、spec→sku_property、unit→stock_unit、price→retail_price
|
|
*
|
|
* 背景:迁移 20260910000500 曾把上述列改名后又改回旧名,导致 Product 模型/控制器按
|
|
* item_code / item_name / item_type 等查询时报 "Unknown column 'item_type' in 'field list'"。
|
|
* 本迁移幂等:仅当旧列存在、新列不存在时才重命名,可重复执行。
|
|
*/
|
|
module.exports = {
|
|
async up(queryInterface) {
|
|
const cols = await queryInterface.describeTable('products');
|
|
const has = (n) => Object.prototype.hasOwnProperty.call(cols, n);
|
|
const rename = async (from, to) => {
|
|
if (has(from) && !has(to)) {
|
|
await queryInterface.renameColumn('products', from, to);
|
|
}
|
|
};
|
|
await rename('code', 'item_code');
|
|
await rename('name', 'item_name');
|
|
await rename('sku_code', 'goods_code');
|
|
await rename('type', 'item_type');
|
|
await rename('category', 'category_name');
|
|
await rename('spec', 'sku_property');
|
|
await rename('unit', 'stock_unit');
|
|
await rename('price', 'retail_price');
|
|
},
|
|
|
|
async down(queryInterface) {
|
|
const cols = await queryInterface.describeTable('products');
|
|
const has = (n) => Object.prototype.hasOwnProperty.call(cols, n);
|
|
const rename = async (from, to) => {
|
|
if (has(from) && !has(to)) {
|
|
await queryInterface.renameColumn('products', from, to);
|
|
}
|
|
};
|
|
await rename('item_code', 'code');
|
|
await rename('item_name', 'name');
|
|
await rename('goods_code', 'sku_code');
|
|
await rename('item_type', 'type');
|
|
await rename('category_name', 'category');
|
|
await rename('sku_property', 'spec');
|
|
await rename('stock_unit', 'unit');
|
|
await rename('retail_price', 'price');
|
|
},
|
|
};
|