feat: add database schema support for gateway and game profiles
- Introduced `dbSchema` configuration option in GatewayApiConfig and GatewayOrchestratorConfig. - Implemented schema resolution logic in environment configuration functions. - Updated context and orchestrator factory to use GatewayPrismaClient instead of PrismaClient. - Refactored orchestrator server and profile repository to accommodate new database schema handling. - Created separate Prisma schemas for game and gateway in the infra package. - Enhanced Postgres connector to support schema overrides in database URLs. - Updated documentation to reflect changes in database schema handling. - Added new Prisma generation and database push scripts for game and gateway schemas.
This commit is contained in:
@@ -2,20 +2,33 @@ import 'dotenv/config';
|
||||
|
||||
import { defineConfig } from 'prisma/config';
|
||||
|
||||
const resolveSchemaName = (value: string | undefined): string => {
|
||||
if (!value) {
|
||||
return 'public';
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed ? trimmed : 'public';
|
||||
};
|
||||
|
||||
const buildDatabaseUrlFromEnv = (): string => {
|
||||
const host = process.env.POSTGRES_HOST ?? '127.0.0.1';
|
||||
const port = process.env.POSTGRES_PORT ?? '15432';
|
||||
const user = process.env.POSTGRES_USER ?? 'sammo';
|
||||
const password = process.env.POSTGRES_PASSWORD ?? '';
|
||||
const dbName = process.env.POSTGRES_DB ?? 'sammo';
|
||||
return `postgresql://${user}:${password}@${host}:${port}/${dbName}?schema=public`;
|
||||
const schema = resolveSchemaName(
|
||||
process.env.POSTGRES_SCHEMA ?? process.env.DATABASE_SCHEMA
|
||||
);
|
||||
return `postgresql://${user}:${password}@${host}:${port}/${dbName}?schema=${schema}`;
|
||||
};
|
||||
|
||||
const databaseUrl =
|
||||
process.env.DATABASE_URL ?? buildDatabaseUrlFromEnv();
|
||||
|
||||
const schemaPath = process.env.PRISMA_SCHEMA ?? 'prisma/game.prisma';
|
||||
|
||||
export default defineConfig({
|
||||
schema: 'prisma/schema.prisma',
|
||||
schema: schemaPath,
|
||||
datasource: {
|
||||
url: databaseUrl,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user