'use strict'; /** * 脚本共用的数据库连接信息解析: * 环境变量 > config/config.local.js(已 gitignore)> 内置默认值 */ const fs = require('fs'); const path = require('path'); const { env } = process; module.exports = function resolveDbConfig() { const config = { host: env.MYSQL_HOST || '127.0.0.1', port: Number(env.MYSQL_PORT || 3307), user: env.MYSQL_USER || 'packservice', password: env.MYSQL_PASSWORD || '', database: env.MYSQL_DATABASE || 'packservice', multipleStatements: true, }; const localPath = path.join(__dirname, '..', 'config', 'config.local.js'); if (fs.existsSync(localPath)) { const { sequelize = {} } = require(localPath); if (sequelize.host) config.host = sequelize.host; if (sequelize.port) config.port = sequelize.port; if (sequelize.username) config.user = sequelize.username; if (sequelize.password !== undefined) config.password = sequelize.password; if (sequelize.database) config.database = sequelize.database; } return config; };