Milo Schwartz 6 месяцев назад
Родитель
Сommit
54f5d159a5
1 измененных файлов с 36 добавлено и 1 удалено
  1. 36 1
      server/setup/migrations.ts

+ 36 - 1
server/setup/migrations.ts

@@ -4,12 +4,13 @@ import path from "path";
 import semver from "semver";
 import { versionMigrations } from "@server/db/schema";
 import { desc } from "drizzle-orm";
-import { __DIRNAME } from "@server/lib/consts";
+import { __DIRNAME, APP_PATH } from "@server/lib/consts";
 import { loadAppVersion } from "@server/lib/loadAppVersion";
 import m1 from "./scripts/1.0.0-beta1";
 import m2 from "./scripts/1.0.0-beta2";
 import m3 from "./scripts/1.0.0-beta3";
 import m4 from "./scripts/1.0.0-beta5";
+import { existsSync, mkdirSync } from "fs";
 
 // THIS CANNOT IMPORT ANYTHING FROM THE SERVER
 // EXCEPT FOR THE DATABASE AND THE SCHEMA
@@ -32,6 +33,8 @@ export async function runMigrations() {
         throw new Error("APP_VERSION is not set in the environment");
     }
 
+    bootstrapVolume();
+
     if (exists) {
         await executeScripts();
     } else {
@@ -106,3 +109,35 @@ async function executeScripts() {
         throw error;
     }
 }
+
+function bootstrapVolume() {
+    const appPath = APP_PATH;
+
+    const dbDir = path.join(appPath, "db");
+    const logsDir = path.join(appPath, "logs");
+
+    // check if the db directory exists and create it if it doesn't
+    if (!existsSync(dbDir)) {
+        mkdirSync(dbDir, { recursive: true });
+    }
+
+    // check if the logs directory exists and create it if it doesn't
+    if (!existsSync(logsDir)) {
+        mkdirSync(logsDir, { recursive: true });
+    }
+
+    // THIS IS FOR TRAEFIK; NOT REALLY NEEDED, BUT JUST IN CASE
+
+    const traefikDir = path.join(appPath, "traefik");
+    const letsEncryptDir = path.join(traefikDir, "letsencrypt");
+
+    // check if the traefik directory exists and create it if it doesn't
+    if (!existsSync(traefikDir)) {
+        mkdirSync(traefikDir, { recursive: true });
+    }
+
+    // check if the letsencrypt directory exists and create it if it doesn't
+    if (!existsSync(letsEncryptDir)) {
+        mkdirSync(letsEncryptDir, { recursive: true });
+    }
+}