政务数据资源中心(Government data Resource center) 03专项3期主要建设内容
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

68 lines
2.0 KiB

const Automate = require('sequelize-automate-freesun')
const moment = require('moment');
async function handleTask(app, task) {
try {
const { models } = app.fs.dc
const dataSource = await models.DataSource.findOne({
where: {
id: task.dataSourceId
}
});
if (dataSource) {
const dbOptions = createDbOptions(dataSource.config);
const automate = new Automate(dbOptions, {});
const tables = await automate.getTables()
//创建或更新库元数据
const dataToSave = {
code: dataSource.config.database,
name: dataSource.config.database,
catalog: dataSource.mountPath,
parent: null,
description: null,
type: "库",
createBy: 1,
createAt: moment(),
updateAt: null,
user: { id: 1, name: "超级管理员", username: "SuperAdmin" },
attributesParam: null
}
// const databaseRslt = await models.MetadataDatabase.create(dataToSave)
//创建或更新表元数据
//创建或更新字段&索引&外键元数据
// MetadataDatabase
// console.log(databaseRslt)
}
} catch (error) {
app.fs.logger.error(`sechedule: handleTask, error: ${error}`);
}
}
function createDbOptions(params) {
const dbOptions = {
database: params.database,
username: params.user,
password: params.password,
dialect: 'postgres',
host: params.host,
port: params.port,
define: {
underscored: false,
freezeTableName: false,
charset: 'utf8mb4',
timezone: '+00: 00',
dialectOptions: {
collate: 'utf8_general_ci',
},
timestamps: false,
},
}
return dbOptions
}
module.exports = { handleTask }