const args = require('args'); const path = require('path'); const moment = require('moment'); const dev = process.env.NODE_ENV == 'development'; // 启动参数 args.option(['g', 'postgresUrl'], 'PostgreSQL服务器URL'); // clickHouse args.option('clickhouseUrl', 'ClickHouse URL'); args.option('clickhousePort', 'ClickHouse Port'); args.option('clickhouseDbPepcaM', 'ClickHouse pepca 数据库名称'); const flags = args.parse(process.argv); const POSTGRES_URL = process.env.POSTGRES_URL || flags.postgresUrl; const CLICKHOUST_URL = process.env.CLICKHOUST_URL || flags.clickhouseUrl; const CLICKHOUST_PORT = process.env.CLICKHOUST_PORT || flags.clickhousePort; const CLICKHOUST_USERNAME = process.env.CLICKHOUST_USERNAME || flags.clickhouseUsername; const CLICKHOUST_PASSWORD = process.env.CLICKHOUST_PASSWORD || flags.clickhousePassword; const CLICKHOUST_DB_PEP_CA_M = process.env.CLICKHOUST_DB_PEP_CA_M || flags.clickhouseDbPepcaM; if (!POSTGRES_URL || !CLICKHOUST_URL || !CLICKHOUST_PORT || !CLICKHOUST_DB_PEP_CA_M) { console.log('缺少启动参数,异常退出'); args.showHelp(); process.exit(1); } const product = { postgres: { url: POSTGRES_URL, opts: { pool: { max: 20, min: 10, idle: 10000 }, define: { freezeTableName: true, // 固定表名 timestamps: false // 不含列 "createAt"/"updateAt"/"DeleteAt" }, timezone: '+08:00', logging: false }, models: [ require('./lib/models') ] }, clickhouse: { url: CLICKHOUST_URL, port: CLICKHOUST_PORT, username: CLICKHOUST_USERNAME, password: CLICKHOUST_PASSWORD, databases: [{ key: 'pg_pepca_m', name: CLICKHOUST_DB_PEP_CA_M }] }, logger: { level: 'info', json: false, filename: path.join(__dirname, 'log', 'runtime.txt'), colorize: false, maxsize: 1024 * 1024 * 5, zippedArchive: true, maxFiles: 10, prettyPrint: true, label: '', timestamp: () => moment().format('YYYY-MM-DD HH:mm:ss.SSS'), tailable: true, depth: null, showLevel: true, maxRetries: 1 } }; const development = { postgres: product.postgres, clickhouse: product.clickhouse, logger: product.logger }; if (dev) { development.logger.filename = path.join(__dirname, 'log', 'development.log'); development.logger.level = 'debug'; development.postgres.opts.logging = console.log; } module.exports = dev ? development : product;