diff --git a/.vscode/launch.json b/.vscode/launch.json index 9a9f0cb02d..0cb4fdfd4c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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", diff --git a/dev/docker-compose.yaml b/dev/docker-compose.yaml index 4dbab23640..c82f014d1d 100644 --- a/dev/docker-compose.yaml +++ b/dev/docker-compose.yaml @@ -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= diff --git a/server/account-service/src/index.ts b/server/account-service/src/index.ts index f3e92f4922..9e0cb5f76c 100644 --- a/server/account-service/src/index.ts +++ b/server/account-service/src/index.ts @@ -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() diff --git a/server/account/src/utils.ts b/server/account/src/utils.ts index e572034cb7..f5067b6d3f 100644 --- a/server/account/src/utils.ts +++ b/server/account/src/utils.ts @@ -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