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