Skip to content

Commit a9dbab2

Browse files
authored
Merge pull request #1819 from Genez-io/release_v3_2_9
Release v3.2.9
2 parents ad42e3c + 184e8b7 commit a9dbab2

File tree

11 files changed

+526
-153
lines changed

11 files changed

+526
-153
lines changed

.github/dependabot.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ updates:
1919
- dependency-name: "esbuild"
2020
versions: [">= 0.18.0"]
2121
- dependency-name: "tree-sitter"
22+
- dependency-name: "express"
2223
- package-ecosystem: "gitsubmodule"
2324
target-branch: "main"
2425
directory: "/"

package-lock.json

Lines changed: 313 additions & 135 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "genezio",
3-
"version": "3.2.8",
3+
"version": "3.2.9",
44
"description": "Command line utility to interact with Genezio infrastructure.",
55
"exports": "./index.js",
66
"type": "module",
@@ -78,7 +78,7 @@
7878
"esbuild": "^0.18.20",
7979
"esbuild-node-externals": "^1.18.0",
8080
"execa": "^9.4.0",
81-
"express": "^5.1.0",
81+
"express": "^4.19.2",
8282
"fs-extra": "^11.3.0",
8383
"glob": "^8.0.3",
8484
"hash-it": "^6.0.0",

src/commands/database.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { UserError } from "../errors.js";
2+
import { GenezioDatabaseOptions } from "../models/commandOptions.js";
3+
import { log } from "../utils/logging.js";
4+
import { createDatabase, getConnectionUrl, listDatabases } from "../requests/database.js";
5+
import { YamlConfigurationIOController } from "../projectConfiguration/yaml/v2.js";
6+
import { CreateDatabaseRequest } from "../models/requests.js";
7+
import { DatabaseType } from "../projectConfiguration/yaml/models.js";
8+
9+
export async function listDatabasesCmd(_: GenezioDatabaseOptions) {
10+
const response = await listDatabases();
11+
if (!response) {
12+
throw new UserError(`Failed to retrieve databases`);
13+
}
14+
log.info(JSON.stringify(response, null, 2));
15+
return;
16+
}
17+
18+
export async function getDatabaseConnectionCmd(options: GenezioDatabaseOptions) {
19+
if (!options.id) {
20+
throw new UserError(`Database ID is required`);
21+
}
22+
const response = await getConnectionUrl(options.id);
23+
if (!response) {
24+
throw new UserError(`Failed to retrieve databases`);
25+
}
26+
log.info(JSON.stringify(response, null, 2));
27+
return;
28+
}
29+
30+
export async function createDatabaseCmd(options: GenezioDatabaseOptions) {
31+
if (!options.name) {
32+
throw new UserError(`Database name is required`);
33+
}
34+
const configIOController = new YamlConfigurationIOController(options.config);
35+
const config = await configIOController.read();
36+
37+
const database = config.services?.databases?.find((db) => db.name === options.name);
38+
if (!database) {
39+
throw new UserError(`Database ${options.name} not found in configuration.`);
40+
}
41+
42+
let createdDatabaseRequest: CreateDatabaseRequest = {
43+
name: database.name,
44+
region: database.region || config.region,
45+
type: database.type,
46+
};
47+
if (database.type === DatabaseType.mongo) {
48+
createdDatabaseRequest = {
49+
...createdDatabaseRequest,
50+
clusterType: database.clusterType,
51+
clusterName: database.clusterName,
52+
clusterTier: database.clusterTier,
53+
};
54+
}
55+
56+
const response = await createDatabase(createdDatabaseRequest, undefined, undefined, false);
57+
if (!response) {
58+
throw new UserError(`Failed to create database ${options.name}`);
59+
}
60+
log.info(`Request to create database ${response.databaseId} was successfully sent.`);
61+
62+
return;
63+
}

src/commands/deploy/utils.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,22 @@ export async function prepareServicesPreBackendDeployment(
117117
if (!database.region) {
118118
database.region = configuration.region;
119119
}
120+
let createdDatabaseRequest: CreateDatabaseRequest = {
121+
name: database.name,
122+
region: database.region,
123+
type: database.type,
124+
};
125+
if (database.type === DatabaseType.mongo) {
126+
createdDatabaseRequest = {
127+
...createdDatabaseRequest,
128+
clusterType: database.clusterType,
129+
clusterName: database.clusterName,
130+
clusterTier: database.clusterTier,
131+
};
132+
}
133+
120134
await getOrCreateDatabase(
121-
{
122-
name: database.name,
123-
region: database.region,
124-
type: database.type,
125-
},
135+
createdDatabaseRequest,
126136
environment || "prod",
127137
projectDetails.projectId,
128138
projectDetails.projectEnvId,
@@ -701,12 +711,23 @@ export async function enableAuthentication(
701711
if (!configDatabase.region) {
702712
configDatabase.region = configuration.region;
703713
}
714+
715+
let createdDatabaseRequest: CreateDatabaseRequest = {
716+
name: configDatabase.name,
717+
region: configDatabase.region,
718+
type: configDatabase.type,
719+
};
720+
if (configDatabase.type === DatabaseType.mongo) {
721+
createdDatabaseRequest = {
722+
...createdDatabaseRequest,
723+
clusterType: configDatabase.clusterType,
724+
clusterName: configDatabase.clusterName,
725+
clusterTier: configDatabase.clusterTier,
726+
};
727+
}
728+
704729
const database: GetDatabaseResponse | undefined = await getOrCreateDatabase(
705-
{
706-
name: configDatabase.name,
707-
region: configDatabase.region,
708-
type: configDatabase.type,
709-
},
730+
createdDatabaseRequest,
710731
stage,
711732
projectId,
712733
projectEnvId,

src/commands/local.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { DartBundler } from "../bundlers/dart/localDartBundler.js";
4242
import axios, { AxiosError, AxiosResponse } from "axios";
4343
import { findAvailablePort } from "../utils/findAvailablePort.js";
4444
import {
45+
DatabaseType,
4546
entryFileFunctionMap,
4647
FunctionType,
4748
Language,
@@ -103,6 +104,7 @@ import { getFunctionEntryFilename } from "../utils/getFunctionEntryFilename.js";
103104
import { SSRFrameworkComponent } from "./deploy/command.js";
104105
import fs from "fs";
105106
import { detectPythonCommand } from "../utils/detectPythonCommand.js";
107+
import { CreateDatabaseRequest } from "../models/requests.js";
106108

107109
type UnitProcess = {
108110
process: ChildProcess;
@@ -168,12 +170,22 @@ export async function prepareLocalBackendEnvironment(
168170
if (!database.region) {
169171
database.region = region;
170172
}
173+
let createdDatabaseRequest: CreateDatabaseRequest = {
174+
name: database.name,
175+
region: database.region,
176+
type: database.type,
177+
};
178+
if (database.type === DatabaseType.mongo) {
179+
createdDatabaseRequest = {
180+
...createdDatabaseRequest,
181+
clusterType: database.clusterType,
182+
clusterName: database.clusterName,
183+
clusterTier: database.clusterTier,
184+
};
185+
}
186+
171187
const remoteDatabase = await getOrCreateDatabase(
172-
{
173-
name: database.name,
174-
region: database.region,
175-
type: database.type,
176-
},
188+
createdDatabaseRequest,
177189
options.stage || "prod",
178190
projectDetails.projectId,
179191
projectDetails.projectEnvId,

src/genezio.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
GenezioBundleFunctionOptions,
3737
GenezioAnalyzeOptions,
3838
GenezioEnvOptions,
39+
GenezioDatabaseOptions,
3940
} from "./models/commandOptions.js";
4041
import currentGenezioVersion, {
4142
checkNodeMinimumVersion,
@@ -57,6 +58,11 @@ import { CloudProviderIdentifier } from "./models/cloudProviderIdentifier.js";
5758
import { isCI } from "./utils/process.js";
5859
import { analyzeCommand, DEFAULT_FORMAT } from "./commands/analyze/command.js";
5960
import { revealEnvironmentVariables } from "./commands/env.js";
61+
import {
62+
createDatabaseCmd,
63+
getDatabaseConnectionCmd,
64+
listDatabasesCmd,
65+
} from "./commands/database.js";
6066

6167
const program = new Command();
6268

@@ -110,7 +116,8 @@ program.hook("preAction", async (thisCommand) => {
110116
if (
111117
thisCommand.args[0] === "analyze" ||
112118
thisCommand.args[0] === "getenv" ||
113-
thisCommand.args[0] === "list"
119+
thisCommand.args[0] === "list" ||
120+
thisCommand.args[0] === "database"
114121
) {
115122
return;
116123
}
@@ -823,4 +830,44 @@ program
823830
exit(0);
824831
});
825832

833+
program
834+
.command("database")
835+
.option(
836+
"--action <action>",
837+
"The action to perform on the database service - list, create, delete.",
838+
"list",
839+
)
840+
.option("--name <name>", "The name of the database service.")
841+
.option("--id <id>", "The name of the database service.")
842+
.option("--config <config>", "The project name to pull from.", "./genezio.yaml")
843+
.option("--stage <stage>", "The stage of the project to pull from.", "prod")
844+
.summary("Manage the database service.")
845+
.action(async (options: GenezioDatabaseOptions) => {
846+
switch (options.action) {
847+
case "list":
848+
await listDatabasesCmd(options).catch((error) => {
849+
logError(error);
850+
exit(1);
851+
});
852+
break;
853+
854+
case "create":
855+
await createDatabaseCmd(options).catch((error) => {
856+
logError(error);
857+
exit(1);
858+
});
859+
break;
860+
case "get-connection":
861+
await getDatabaseConnectionCmd(options).catch((error) => {
862+
logError(error);
863+
exit(1);
864+
});
865+
break;
866+
default:
867+
log.error(`Unknown action: ${options.action}`);
868+
exit(1);
869+
}
870+
exit(0);
871+
});
872+
826873
export default program;

src/models/commandOptions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ export interface GenezioEnvOptions extends BaseOptions {
9999
format?: string;
100100
}
101101

102+
export interface GenezioDatabaseOptions extends BaseOptions {
103+
id?: string;
104+
name?: string;
105+
config?: string;
106+
action?: string;
107+
}
108+
102109
export interface GenezioCreateInteractiveOptions extends BaseOptions {
103110
path?: string;
104111
}

src/models/requests.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@ import {
55
} from "../projectConfiguration/yaml/models.js";
66
import { ProjectDetailsEnvElement } from "../requests/models.js";
77

8+
export enum MongoClusterType {
9+
SHARED = "sharedCluster",
10+
DEDICATED = "dedicatedCluster",
11+
}
12+
13+
export enum MongoClusterTier {
14+
M10 = "M10",
15+
M20 = "M20",
16+
M30 = "M30",
17+
M40 = "M40",
18+
M50 = "M50",
19+
}
20+
821
export interface CreateDatabaseRequest {
922
name: string;
1023
region: string;
1124
type: DatabaseType;
25+
clusterType?: MongoClusterType;
26+
clusterName?: string;
27+
clusterTier?: MongoClusterTier;
1228
}
1329

1430
export interface CreateDatabaseResponse {
@@ -39,6 +55,10 @@ export interface GetDatabasesResponse {
3955
type: string;
4056
}[];
4157
}
58+
export interface GetConnectionUrlResponse {
59+
status: string;
60+
connectionUrl: string;
61+
}
4262

4363
export interface LinkedDatabaseResponse {
4464
status: string;

src/projectConfiguration/yaml/v2.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import yaml, { YAMLParseError } from "yaml";
2525
import { DeepRequired } from "../../utils/types.js";
2626
import { isUnique } from "../../utils/yaml.js";
2727
import path from "path";
28+
import { MongoClusterTier, MongoClusterType } from "../../models/requests.js";
2829

2930
export type RawYamlProjectConfiguration = ReturnType<typeof parseGenezioConfig>;
3031
export type YAMLBackend = NonNullable<YamlProjectConfiguration["backend"]>;
@@ -188,6 +189,9 @@ function parseGenezioConfig(config: unknown) {
188189
region: zod
189190
.enum(mongoDatabaseRegions.map((r) => r.value) as [string, ...string[]])
190191
.optional(),
192+
clusterType: zod.nativeEnum(MongoClusterType).optional(),
193+
clusterName: zod.string().optional(),
194+
clusterTier: zod.nativeEnum(MongoClusterTier).optional(),
191195
}),
192196
);
193197

0 commit comments

Comments
 (0)