- 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.
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
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';
|
|
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: schemaPath,
|
|
datasource: {
|
|
url: databaseUrl,
|
|
},
|
|
});
|