diff --git a/src/models/requests.ts b/src/models/requests.ts index 6df6e195f..b003307ce 100644 --- a/src/models/requests.ts +++ b/src/models/requests.ts @@ -1,13 +1,14 @@ import { AuthenticationDatabaseType, AuthenticationEmailTemplateType, + DatabaseType, } from "../projectConfiguration/yaml/models.js"; import { ProjectDetailsEnvElement } from "../requests/models.js"; export interface CreateDatabaseRequest { name: string; region: string; - type?: string; + type: DatabaseType; } export interface CreateDatabaseResponse { diff --git a/src/projectConfiguration/yaml/models.ts b/src/projectConfiguration/yaml/models.ts index 49cdefe65..aa5661893 100644 --- a/src/projectConfiguration/yaml/models.ts +++ b/src/projectConfiguration/yaml/models.ts @@ -15,6 +15,7 @@ export enum AuthenticationDatabaseType { export enum DatabaseType { neon = "postgres-neon", + mongo = "mongo-atlas", } export enum TriggerType { diff --git a/src/projectConfiguration/yaml/v2.ts b/src/projectConfiguration/yaml/v2.ts index f8214115c..470b7956f 100644 --- a/src/projectConfiguration/yaml/v2.ts +++ b/src/projectConfiguration/yaml/v2.ts @@ -2,7 +2,7 @@ import { YAMLContext, parse as parseYaml, stringify as stringifyYaml } from "yam import zod from "zod"; import nativeFs from "fs"; import { IFs } from "memfs"; -import { databaseRegions, legacyRegions } from "../../utils/configs.js"; +import { neonDatabaseRegions, legacyRegions, mongoDatabaseRegions } from "../../utils/configs.js"; import { GENEZIO_CONFIGURATION_FILE_NOT_FOUND, UserError, zodFormatError } from "../../errors.js"; import { AuthenticationDatabaseType, DatabaseType, FunctionType, Language } from "./models.js"; import { @@ -28,6 +28,9 @@ type YamlScripts = NonNullable | NonNullable; +export type YamlDatabase = NonNullable< + NonNullable["databases"] +>[number]; function parseGenezioConfig(config: unknown) { const languageSchema = zod.object({ @@ -99,11 +102,23 @@ function parseGenezioConfig(config: unknown) { type: zod.nativeEnum(FunctionType).default(FunctionType.aws), }); - const databaseSchema = zod.object({ - name: zod.string(), - type: zod.nativeEnum(DatabaseType).optional().default(DatabaseType.neon), - region: zod.enum(databaseRegions.map((r) => r.value) as [string, ...string[]]).optional(), - }); + const databaseSchema = zod + .object({ + name: zod.string(), + type: zod.literal(DatabaseType.neon), + region: zod + .enum(neonDatabaseRegions.map((r) => r.value) as [string, ...string[]]) + .optional(), + }) + .or( + zod.object({ + name: zod.string(), + type: zod.literal(DatabaseType.mongo), + region: zod + .enum(mongoDatabaseRegions.map((r) => r.value) as [string, ...string[]]) + .optional(), + }), + ); const redirectUrlSchema = zod.string(); diff --git a/src/requests/database.ts b/src/requests/database.ts index fdb81c37c..97a72eb4d 100644 --- a/src/requests/database.ts +++ b/src/requests/database.ts @@ -14,11 +14,16 @@ export async function createDatabase( envId?: string, linkToStage: boolean = false, ): Promise { - const { name, region, type = "postgres-neon" } = request; + const { name, type } = request; + let { region } = request; + + if (type === "postgres-neon") { + region = `aws-${region}`; + } const data: string = JSON.stringify({ name: name, - region: "aws-" + region, + region: region, type: type, }); diff --git a/src/utils/configs.ts b/src/utils/configs.ts index 3302449be..841aac4ab 100644 --- a/src/utils/configs.ts +++ b/src/utils/configs.ts @@ -42,7 +42,7 @@ export const regions = [ { name: "Europe (Frankfurt)", value: "eu-central-1" }, ]; -export const databaseRegions = [ +export const neonDatabaseRegions = [ { name: "US East (N. Virginia)", value: "us-east-1" }, { name: "US East (Ohio)", value: "us-east-2" }, { name: "US West (Oregon)", value: "us-west-2" }, @@ -50,3 +50,8 @@ export const databaseRegions = [ { name: "Asia Pacific (Sydney)", value: "ap-southeast-2" }, { name: "Europe (Frankfurt)", value: "eu-central-1" }, ]; + +export const mongoDatabaseRegions = [ + { name: "US East (N. Virginia)", value: "us-east-1" }, + { name: "Europe (Frankfurt)", value: "eu-central-1" }, +];