uberf-8511: configurable account db ns (#6978)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2024-10-18 17:22:26 +04:00 committed by GitHub
parent e9098372af
commit bad07b90fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 7 additions and 8 deletions

1
.vscode/launch.json vendored
View File

@ -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",

View File

@ -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=

View File

@ -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()

View File

@ -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