🐞 fix(数据库): web和gm添加userlog副数据库
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import 'reflect-metadata'
|
import 'reflect-metadata'
|
||||||
import * as mongoose from 'mongoose';
|
import * as mongoose from 'mongoose';
|
||||||
import { Application, IBoot } from 'egg';
|
import { Application, IBoot } from 'egg';
|
||||||
import { loadGmDb } from '@db/index';
|
import { loadGmDb, loadSubDb } from '@db/index';
|
||||||
import { connectRedis } from '@pubUtils/redis';
|
import { connectRedis } from '@pubUtils/redis';
|
||||||
|
|
||||||
export default class FooBoot implements IBoot {
|
export default class FooBoot implements IBoot {
|
||||||
@@ -17,6 +17,7 @@ export default class FooBoot implements IBoot {
|
|||||||
// this is the last chance to modify the config.
|
// this is the last chance to modify the config.
|
||||||
await this.connectDB(this.app)
|
await this.connectDB(this.app)
|
||||||
await this.connectGMDB(this.app);
|
await this.connectGMDB(this.app);
|
||||||
|
await this.connectSubDB(this.app);
|
||||||
await this.connectRedis(this.app);
|
await this.connectRedis(this.app);
|
||||||
|
|
||||||
this.app.config.realEnv = this.app.config.env;
|
this.app.config.realEnv = this.app.config.env;
|
||||||
@@ -85,6 +86,20 @@ export default class FooBoot implements IBoot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async connectSubDB(app: Application) {
|
||||||
|
const { url, options } = app.config.submongoose||app.config.mongoose
|
||||||
|
try {
|
||||||
|
if (url) {
|
||||||
|
const connection = await mongoose.createConnection(url, options)
|
||||||
|
app.context.connectionGM = connection;
|
||||||
|
loadSubDb(connection);
|
||||||
|
console.log('******connectSubDB suc', url, options)
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async connectRedis(app: Application) {
|
public async connectRedis(app: Application) {
|
||||||
const { url, pw } = app.config.redis
|
const { url, pw } = app.config.redis
|
||||||
if (url) {
|
if (url) {
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ export default (appInfo: EggAppInfo) => {
|
|||||||
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
config.submongoose = {
|
||||||
|
url: 'mongodb://yjzDbOp:yjz2023ZyDB@dds-8vbc6a169e1dd6941.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6942.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6943.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6944.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-516005504', // 内网
|
||||||
|
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||||
|
};
|
||||||
|
|
||||||
config.redis = {
|
config.redis = {
|
||||||
url: 'r-8vbkqfcnivt4ja3ndj.redis.zhangbei.rds.aliyuncs.com', // 内网
|
url: 'r-8vbkqfcnivt4ja3ndj.redis.zhangbei.rds.aliyuncs.com', // 内网
|
||||||
pw: 'hWCJ$HDajm9SN&&Z'
|
pw: 'hWCJ$HDajm9SN&&Z'
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import 'reflect-metadata'
|
|||||||
import * as mongoose from 'mongoose';
|
import * as mongoose from 'mongoose';
|
||||||
import { Application, IBoot } from 'egg';
|
import { Application, IBoot } from 'egg';
|
||||||
import { connectRedis } from './app/pubUtils/redis';
|
import { connectRedis } from './app/pubUtils/redis';
|
||||||
import { loadGmDb } from '@db/index';
|
import { loadGmDb, loadSubDb } from '@db/index';
|
||||||
import { SDK_TA_CONST, THINKING_DATA_MODE, THINKING_DATA_MODE_LIST } from '@consts';
|
import { SDK_TA_CONST, THINKING_DATA_MODE, THINKING_DATA_MODE_LIST } from '@consts';
|
||||||
const ThinkingAnalytics = require("thinkingdata-node");
|
const ThinkingAnalytics = require("thinkingdata-node");
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@ export default class FooBoot implements IBoot {
|
|||||||
// this is the last chance to modify the config.
|
// this is the last chance to modify the config.
|
||||||
await this.connectDB(this.app);
|
await this.connectDB(this.app);
|
||||||
await this.connectGMDB(this.app);
|
await this.connectGMDB(this.app);
|
||||||
|
await this.connectSubDB(this.app);
|
||||||
await this.connectRedis(this.app);
|
await this.connectRedis(this.app);
|
||||||
|
|
||||||
this.app.config.realEnv = this.app.config.env;
|
this.app.config.realEnv = this.app.config.env;
|
||||||
@@ -89,6 +90,20 @@ export default class FooBoot implements IBoot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async connectSubDB(app: Application) {
|
||||||
|
const { url, options } = app.config.submongoose||app.config.mongoose
|
||||||
|
try {
|
||||||
|
if (url) {
|
||||||
|
const connection = await mongoose.createConnection(url, options)
|
||||||
|
app.context.connectionGM = connection;
|
||||||
|
loadSubDb(connection);
|
||||||
|
console.log('******connectSubDB suc', url, options)
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async connectRedis(app: Application) {
|
public async connectRedis(app: Application) {
|
||||||
const { url, pw } = app.config.redis
|
const { url, pw } = app.config.redis
|
||||||
if (url) {
|
if (url) {
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ export default (appInfo: EggAppInfo) => {
|
|||||||
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
config.submongoose = {
|
||||||
|
url: 'mongodb://yjzDbOp:yjz2023ZyDB@dds-8vbc6a169e1dd6941.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6942.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6943.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6944.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-516005504', // 内网
|
||||||
|
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||||
|
};
|
||||||
|
|
||||||
config.redis = {
|
config.redis = {
|
||||||
url: 'r-8vbkqfcnivt4ja3ndj.redis.zhangbei.rds.aliyuncs.com', // 内网
|
url: 'r-8vbkqfcnivt4ja3ndj.redis.zhangbei.rds.aliyuncs.com', // 内网
|
||||||
pw: 'hWCJ$HDajm9SN&&Z'
|
pw: 'hWCJ$HDajm9SN&&Z'
|
||||||
|
|||||||
Reference in New Issue
Block a user