Files
autoAiWorkSys/scripts/sync_pla_account_is_enabled.js
张成 5d7444cd65 1
2025-11-24 13:23:42 +08:00

68 lines
2.2 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const Framework = require('../framework/node-core-framework.js');
const frameworkConfig = require('../config/framework.config.js');
const Sequelize = require('sequelize');
async function syncPlaAccountIsEnabled() {
console.log('🔄 开始同步 pla_account 表 is_enabled 字段...\n');
try {
const framework = await Framework.init(frameworkConfig);
const models = Framework.getModels();
if (!models) {
throw new Error('无法获取模型列表');
}
const pla_account = models.pla_account;
if (!pla_account) {
throw new Error('无法获取 pla_account 模型');
}
console.log('正在同步表结构(使用 alter: true 模式,保留现有数据)...\n');
await pla_account.sync({ alter: true });
console.log('✅ pla_account 表同步成功!\n');
// 显示表结构
const sequelize = pla_account.sequelize;
const tableInfo = await sequelize.query(
`DESCRIBE pla_account`,
{ type: Sequelize.QueryTypes.SELECT }
);
console.table(tableInfo.map(field => ({
字段名: field.Field,
类型: field.Type,
允许空: field.Null,
默认值: field.Default,
注释: field.Comment || ''
})));
// 检查 is_enabled 字段是否存在
const isEnabledField = tableInfo.find(field => field.Field === 'is_enabled');
if (isEnabledField) {
console.log('\n✅ is_enabled 字段已存在');
console.log(` 类型: ${isEnabledField.Type}`);
console.log(` 默认值: ${isEnabledField.Default}`);
console.log(` 注释: ${isEnabledField.Comment || '无'}\n`);
} else {
console.warn('\n⚠ is_enabled 字段不存在,可能需要手动添加\n');
}
} catch (error) {
console.error('❌ 同步失败:', error.message);
console.error('\n详细错误:', error);
throw error;
}
}
syncPlaAccountIsEnabled()
.then(() => {
console.log('✅ 同步完成');
process.exit(0);
})
.catch(error => {
console.error('❌ 同步失败');
process.exit(1);
});