Files
steel_prices_service/scripts/migrate-add-source-fields.js
2026-01-06 18:00:43 +08:00

36 lines
1.2 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.

require('dotenv').config();
const Price = require('../src/models/Price');
/**
* 数据库迁移脚本:添加数据源标识字段
* 为现有 prices 表添加数据源区分字段
*/
async function migrate() {
console.log('🔄 开始数据库迁移:添加数据源标识字段\n');
try {
await Price.migrateAddSourceFields();
console.log('\n' + '='.repeat(60));
console.log('✅ 数据库迁移完成!');
console.log('='.repeat(60));
console.log('\n📊 新增字段说明:');
console.log(' - price_source_code: 数据源代码YUNNAN_STEEL_ASSOC / MY_STEEL / DE_STEEL_FACTORY');
console.log(' - price_source_desc: 数据源描述');
console.log(' - data_origin: 数据来源标识LOCAL_FILE 或 API:ENDPOINT');
console.log('\n🎨 数据源标识:');
console.log(' 🔴 YUNNAN_STEEL_ASSOC - 云南钢协指导价DEFAULT 接口)');
console.log(' 🔵 MY_STEEL - 我的钢铁网价格BACKUP 接口)');
console.log(' 🟢 DE_STEEL_FACTORY - 德钢钢厂指导价EXTENDED 接口)');
process.exit(0);
} catch (error) {
console.error('\n❌ 迁移失败:', error);
process.exit(1);
}
}
// 运行迁移
migrate();