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,4 +1,4 @@
|
||||
import type { PrismaClient } from '@prisma/client';
|
||||
import type { GatewayPrismaClient } from '@sammo-ts/infra';
|
||||
|
||||
import type { GatewayOrchestratorConfig } from '../config.js';
|
||||
import { createGatewayProfileRepository } from './profileRepository.js';
|
||||
@@ -16,7 +16,7 @@ export const buildEnvMap = (env: NodeJS.ProcessEnv): Record<string, string> => {
|
||||
};
|
||||
|
||||
export const createGatewayOrchestrator = (
|
||||
prisma: PrismaClient,
|
||||
prisma: GatewayPrismaClient,
|
||||
config: GatewayOrchestratorConfig,
|
||||
env: NodeJS.ProcessEnv = process.env
|
||||
): {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { PrismaClient } from '@prisma/client';
|
||||
import {
|
||||
createPostgresConnector,
|
||||
createGatewayPostgresConnector,
|
||||
type GatewayPrismaClient,
|
||||
resolvePostgresConfigFromEnv,
|
||||
} from '@sammo-ts/infra';
|
||||
|
||||
@@ -9,11 +9,13 @@ import { createGatewayOrchestrator } from './orchestratorFactory.js';
|
||||
|
||||
export const runGatewayOrchestrator = async (): Promise<void> => {
|
||||
const config = resolveGatewayOrchestratorConfigFromEnv();
|
||||
const postgres = createPostgresConnector(resolvePostgresConfigFromEnv());
|
||||
const postgres = createGatewayPostgresConnector(
|
||||
resolvePostgresConfigFromEnv({ schema: config.dbSchema })
|
||||
);
|
||||
await postgres.connect();
|
||||
|
||||
const { orchestrator } = createGatewayOrchestrator(
|
||||
postgres.prisma as PrismaClient,
|
||||
postgres.prisma as GatewayPrismaClient,
|
||||
config,
|
||||
process.env
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Prisma, type PrismaClient } from '@prisma/client';
|
||||
import { GatewayPrisma, type GatewayPrismaClient } from '@sammo-ts/infra';
|
||||
|
||||
export const GATEWAY_PROFILE_STATUSES = [
|
||||
'RESERVED',
|
||||
@@ -38,7 +38,7 @@ export interface GatewayProfileRecord {
|
||||
buildCompletedAt?: string;
|
||||
buildError?: string;
|
||||
lastError?: string;
|
||||
meta: Prisma.JsonObject;
|
||||
meta: GatewayPrisma.JsonObject;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export interface GatewayProfileUpsertInput {
|
||||
openAt?: string;
|
||||
scheduledStartAt?: string;
|
||||
buildCommitSha?: string;
|
||||
meta?: Prisma.JsonObject;
|
||||
meta?: GatewayPrisma.JsonObject;
|
||||
}
|
||||
|
||||
export interface GatewayProfileRepository {
|
||||
@@ -113,7 +113,7 @@ type GatewayProfileRow = {
|
||||
buildCompletedAt: Date | null;
|
||||
buildError: string | null;
|
||||
lastError: string | null;
|
||||
meta: Prisma.JsonValue;
|
||||
meta: GatewayPrisma.JsonValue;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
@@ -145,7 +145,7 @@ const mapProfile = (row: GatewayProfileRow): GatewayProfileRecord => ({
|
||||
buildCompletedAt: toIso(row.buildCompletedAt),
|
||||
buildError: row.buildError ?? undefined,
|
||||
lastError: row.lastError ?? undefined,
|
||||
meta: (row.meta ?? {}) as Prisma.JsonObject,
|
||||
meta: (row.meta ?? {}) as GatewayPrisma.JsonObject,
|
||||
createdAt: row.createdAt.toISOString(),
|
||||
updatedAt: row.updatedAt.toISOString(),
|
||||
});
|
||||
@@ -154,7 +154,7 @@ const buildProfileName = (profile: string, scenario: string): string =>
|
||||
`${profile}:${scenario}`;
|
||||
|
||||
export const createGatewayProfileRepository = (
|
||||
prisma: PrismaClient
|
||||
prisma: GatewayPrismaClient
|
||||
): GatewayProfileRepository => ({
|
||||
async listProfiles(): Promise<GatewayProfileRecord[]> {
|
||||
const gatewayProfile = prisma.gatewayProfile as unknown as GatewayProfileClient;
|
||||
@@ -187,7 +187,7 @@ export const createGatewayProfileRepository = (
|
||||
? new Date(input.scheduledStartAt)
|
||||
: null,
|
||||
buildCommitSha: input.buildCommitSha ?? null,
|
||||
meta: (input.meta ?? {}) as Prisma.JsonObject,
|
||||
meta: (input.meta ?? {}) as GatewayPrisma.JsonObject,
|
||||
},
|
||||
update: {
|
||||
apiPort: input.apiPort,
|
||||
@@ -211,7 +211,7 @@ export const createGatewayProfileRepository = (
|
||||
input.buildCommitSha === undefined
|
||||
? undefined
|
||||
: input.buildCommitSha,
|
||||
meta: input.meta ? (input.meta as Prisma.JsonObject) : undefined,
|
||||
meta: input.meta ? (input.meta as GatewayPrisma.JsonObject) : undefined,
|
||||
},
|
||||
});
|
||||
return mapProfile(row);
|
||||
|
||||
Reference in New Issue
Block a user