mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-22 11:01:54 +03:00
uberf-8511: configurable account db ns (#6978)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
e9098372af
commit
bad07b90fc
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
@ -95,6 +95,7 @@
|
||||
"ACCOUNT_PORT": "3000",
|
||||
"FRONT_URL": "http://localhost:8080",
|
||||
"SES_URL": "",
|
||||
// "DB_NS": "account-2",
|
||||
// "WS_LIVENESS_DAYS": "1",
|
||||
"MINIO_ACCESS_KEY": "minioadmin",
|
||||
"MINIO_SECRET_KEY": "minioadmin",
|
||||
|
@ -75,6 +75,7 @@ services:
|
||||
- SERVER_SECRET=secret
|
||||
# - DB_URL=postgresql://postgres:example@postgres:5432
|
||||
- DB_URL=${MONGO_URL}
|
||||
# - DB_NS=account-2
|
||||
- REGION_INFO=|Mongo;pg|Postgres
|
||||
- TRANSACTOR_URL=ws://host.docker.internal:3333,ws://host.docker.internal:3331;;pg
|
||||
- SES_URL=
|
||||
|
@ -95,7 +95,8 @@ export function serveAccount (measureCtx: MeasureContext, brandings: BrandingMap
|
||||
const hasSignUp = process.env.DISABLE_SIGNUP !== 'true'
|
||||
const methods = getMethods(hasSignUp)
|
||||
|
||||
const accountsDb = getAccountDB(dbUrl)
|
||||
const dbNs = process.env.DB_NS
|
||||
const accountsDb = getAccountDB(dbUrl, dbNs)
|
||||
|
||||
const app = new Koa()
|
||||
const router = new Router()
|
||||
|
@ -24,17 +24,12 @@ import { PostgresAccountDB } from './collections/postgres'
|
||||
import { accountPlugin } from './plugin'
|
||||
import type { Account, AccountDB, AccountInfo, RegionInfo, WorkspaceInfo } from './types'
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const ACCOUNT_DB = 'account'
|
||||
|
||||
export async function getAccountDB (uri: string, db: string = ACCOUNT_DB): Promise<[AccountDB, () => void]> {
|
||||
export async function getAccountDB (uri: string, dbNs?: string): Promise<[AccountDB, () => void]> {
|
||||
const isMongo = uri.startsWith('mongodb://')
|
||||
|
||||
if (isMongo) {
|
||||
const client = getMongoClient(uri)
|
||||
const db = (await client.getClient()).db(ACCOUNT_DB)
|
||||
const db = (await client.getClient()).db(dbNs ?? 'account')
|
||||
const mongoAccount = new MongoAccountDB(db)
|
||||
|
||||
await mongoAccount.init()
|
||||
@ -48,6 +43,7 @@ export async function getAccountDB (uri: string, db: string = ACCOUNT_DB): Promi
|
||||
} else {
|
||||
const client = getDBClient(uri)
|
||||
const pgClient = await client.getClient()
|
||||
// TODO: if dbNs is provided put tables in that schema
|
||||
const pgAccount = new PostgresAccountDB(pgClient)
|
||||
|
||||
let error = false
|
||||
|
Loading…
Reference in New Issue
Block a user