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:
@@ -1,10 +1,10 @@
|
||||
import fastify, { type FastifyRequest } from 'fastify';
|
||||
import cors from '@fastify/cors';
|
||||
import { fastifyTRPCPlugin } from '@trpc/server/adapters/fastify';
|
||||
import type { PrismaClient } from '@prisma/client';
|
||||
import {
|
||||
createPostgresConnector,
|
||||
createGatewayPostgresConnector,
|
||||
createRedisConnector,
|
||||
type GatewayPrismaClient,
|
||||
resolvePostgresConfigFromEnv,
|
||||
resolveRedisConfigFromEnv,
|
||||
} from '@sammo-ts/infra';
|
||||
@@ -22,13 +22,15 @@ import { RepositoryProfileStatusService } from './lobby/profileStatusService.js'
|
||||
|
||||
export const createGatewayApiServer = async () => {
|
||||
const config = resolveGatewayApiConfigFromEnv();
|
||||
const postgres = createPostgresConnector(resolvePostgresConfigFromEnv());
|
||||
const postgres = createGatewayPostgresConnector(
|
||||
resolvePostgresConfigFromEnv({ schema: config.dbSchema })
|
||||
);
|
||||
const redis = createRedisConnector(resolveRedisConfigFromEnv());
|
||||
await postgres.connect();
|
||||
await redis.connect();
|
||||
|
||||
const users = createPostgresUserRepository(
|
||||
postgres.prisma as PrismaClient
|
||||
postgres.prisma as GatewayPrismaClient
|
||||
);
|
||||
const sessions = new RedisGatewaySessionService(redis.client, {
|
||||
keyPrefix: config.redisKeyPrefix,
|
||||
@@ -48,7 +50,7 @@ export const createGatewayApiServer = async () => {
|
||||
);
|
||||
|
||||
const { orchestrator, profiles } = createGatewayOrchestrator(
|
||||
postgres.prisma as PrismaClient,
|
||||
postgres.prisma as GatewayPrismaClient,
|
||||
config,
|
||||
process.env
|
||||
);
|
||||
@@ -82,7 +84,7 @@ export const createGatewayApiServer = async () => {
|
||||
profileStatus,
|
||||
adminToken: config.adminToken,
|
||||
requestHeaders: req.headers,
|
||||
prisma: postgres.prisma as PrismaClient,
|
||||
prisma: postgres.prisma as GatewayPrismaClient,
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user