This commit is contained in:
Alex Holliday committed 2026-03-26 09:47:10 -07:00
1 parent e87879970a
commit be29cce788
5 files changed
+14 -13

No files matched your search

+4 -10
View File
@@ -126,6 +126,7 @@ import {
} from "@/repositories/index.js"; } from "@/repositories/index.js";
import { ILogger } from "@/utils/logger.js"; import { ILogger } from "@/utils/logger.js";
import TimescaleDB from "@/db/TimescaleDB.js"; import TimescaleDB from "@/db/TimescaleDB.js";
import { AppError } from "@/utils/AppError.js";
export type InitializedServices = { export type InitializedServices = {
settingsService: ISettingsService; settingsService: ISettingsService;
@@ -175,25 +176,18 @@ export const initializeServices = async ({
}): Promise<InitializedServices> => { }): Promise<InitializedServices> => {
// Create DB // Create DB
let dbType = "mongodb"; const dbType = envSettings.dbType;
const connectionString = envSettings.dbConnectionString;
if (connectionString.startsWith("mongodb")) {
dbType = "mongodb";
} else if (connectionString.startsWith("postgresql")) {
dbType = "postgresql";
}
let db: IDb | null = null; let db: IDb | null = null;
if (dbType === "mongodb") { if (dbType === "mongodb") {
db = new MongoDB(logger, envSettings); db = new MongoDB(logger, envSettings);
} else if (dbType === "postgresql") { } else if (dbType === "timescaledb") {
db = new TimescaleDB(logger, envSettings); db = new TimescaleDB(logger, envSettings);
} }
if (!db) { if (!db) {
throw new Error("Unsupported database type"); throw new AppError({ message: "Unsupported database type", status: 500 });
} }
await db.connect(); await db.connect();
+2 -2
View File
@@ -1,8 +1,8 @@
import { initializeServices } from "./config/services.js"; import { initializeServices } from "./config/services.js";
import { initializeControllers } from "./config/controllers.js"; import { initializeControllers } from "./config/controllers.js";
import { createApp } from "./app.js"; import { createApp } from "./app.js";
import { initShutdownListener } from "./shutdown.js"; import { initShutdownListener } from "@/shutdown.js";
import { validateEnv } from "./validation/envValidation.js"; import { validateEnv } from "@/validation/envValidation.js";
import { fileURLToPath } from "url"; import { fileURLToPath } from "url";
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
+3 -1
View File
@@ -1,5 +1,5 @@
import { ISettingsRepository } from "@/repositories/index.js"; import { ISettingsRepository } from "@/repositories/index.js";
import { Settings, SettingsUpdate } from "@/types/index.js"; import { type DbType, Settings, SettingsUpdate } from "@/types/index.js";
import { AppError } from "@/utils/AppError.js"; import { AppError } from "@/utils/AppError.js";
import { ValidatedEnv } from "@/validation/envValidation.js"; import { ValidatedEnv } from "@/validation/envValidation.js";
import type { StringValue } from "ms"; import type { StringValue } from "ms";
@@ -12,6 +12,7 @@ export type EnvConfig = {
logLevel: string; logLevel: string;
clientHost: string; clientHost: string;
dbConnectionString: string; dbConnectionString: string;
dbType: DbType;
}; };
export interface ISettingsService { export interface ISettingsService {
@@ -35,6 +36,7 @@ export class SettingsService implements ISettingsService {
logLevel: env.LOG_LEVEL, logLevel: env.LOG_LEVEL,
clientHost: env.CLIENT_HOST, clientHost: env.CLIENT_HOST,
dbConnectionString: env.DB_CONNECTION_STRING, dbConnectionString: env.DB_CONNECTION_STRING,
dbType: env.DB_TYPE,
}; };
} }
+3
View File
@@ -1,3 +1,6 @@
export const DbTypes = ["timescaledb", "mongodb"] as const;
export type DbType = (typeof DbTypes)[number];
export interface SettingsThresholds { export interface SettingsThresholds {
cpu?: number; cpu?: number;
memory?: number; memory?: number;
+2
View File
@@ -1,4 +1,5 @@
import { z } from "zod"; import { z } from "zod";
import { DbTypes } from "@/types/settings.js";
const envSchema = z.object({ const envSchema = z.object({
// Server Configuration // Server Configuration
@@ -8,6 +9,7 @@ const envSchema = z.object({
// Database // Database
DB_CONNECTION_STRING: z.string().min(1, "Database connection string is required"), DB_CONNECTION_STRING: z.string().min(1, "Database connection string is required"),
DB_TYPE: z.enum(DbTypes).default("mongodb"),
// JWT Authentication // JWT Authentication
JWT_SECRET: z.string().min(1, "JWT_SECRET is required"), JWT_SECRET: z.string().min(1, "JWT_SECRET is required"),