diff --git a/server/setup/migrationsPg.ts b/server/setup/migrationsPg.ts index a3dc6499..1f88baa8 100644 --- a/server/setup/migrationsPg.ts +++ b/server/setup/migrationsPg.ts @@ -2,14 +2,16 @@ import { migrate } from "drizzle-orm/node-postgres/migrator"; import { db } from "../db/pg"; import semver from "semver"; import { versionMigrations } from "../db/pg"; -import { __DIRNAME, APP_PATH, APP_VERSION } from "@server/lib/consts"; +import { __DIRNAME, APP_VERSION } from "@server/lib/consts"; import path from "path"; +import m1 from "./scriptsSqlite/1.6.0"; // THIS CANNOT IMPORT ANYTHING FROM THE SERVER // EXCEPT FOR THE DATABASE AND THE SCHEMA // Define the migration list with versions and their corresponding functions const migrations = [ + { version: "1.6.0", run: m1 } // Add new migrations here as they are created ] as { version: string; diff --git a/server/setup/migrationsSqlite.ts b/server/setup/migrationsSqlite.ts index 36b87de2..1e279bae 100644 --- a/server/setup/migrationsSqlite.ts +++ b/server/setup/migrationsSqlite.ts @@ -21,6 +21,7 @@ import m17 from "./scriptsSqlite/1.1.0"; import m18 from "./scriptsSqlite/1.2.0"; import m19 from "./scriptsSqlite/1.3.0"; import m20 from "./scriptsSqlite/1.5.0"; +import m21 from "./scriptsSqlite/1.6.0"; // THIS CANNOT IMPORT ANYTHING FROM THE SERVER // EXCEPT FOR THE DATABASE AND THE SCHEMA @@ -42,6 +43,7 @@ const migrations = [ { version: "1.2.0", run: m18 }, { version: "1.3.0", run: m19 }, { version: "1.5.0", run: m20 }, + { version: "1.6.0", run: m21 } // Add new migrations here as they are created ] as const; diff --git a/server/setup/scriptsPg/1.6.0.ts b/server/setup/scriptsPg/1.6.0.ts new file mode 100644 index 00000000..375f8388 --- /dev/null +++ b/server/setup/scriptsPg/1.6.0.ts @@ -0,0 +1,46 @@ +import { configFilePath1, configFilePath2 } from "@server/lib/consts"; +import fs from "fs"; +import yaml from "js-yaml"; + +const version = "1.6.0"; + +export default async function migration() { + console.log(`Running setup script ${version}...`); + + try { + // Determine which config file exists + const filePaths = [configFilePath1, configFilePath2]; + let filePath = ""; + for (const path of filePaths) { + if (fs.existsSync(path)) { + filePath = path; + break; + } + } + + if (!filePath) { + throw new Error( + `No config file found (expected config.yml or config.yaml).` + ); + } + + // Read and parse the YAML file + let rawConfig: any; + const fileContents = fs.readFileSync(filePath, "utf8"); + rawConfig = yaml.load(fileContents); + + if (rawConfig.server?.trust_proxy) { + rawConfig.server.trust_proxy = 1; + } + + // Write the updated YAML back to the file + const updatedYaml = yaml.dump(rawConfig); + fs.writeFileSync(filePath, updatedYaml, "utf8"); + + console.log(`Set trust_proxy to 1 in config file`); + } catch (e) { + console.log(`Unable to migrate config file. Error: ${e}`); + } + + console.log(`${version} migration complete`); +} diff --git a/server/setup/scriptsSqlite/1.6.0.ts b/server/setup/scriptsSqlite/1.6.0.ts new file mode 100644 index 00000000..375f8388 --- /dev/null +++ b/server/setup/scriptsSqlite/1.6.0.ts @@ -0,0 +1,46 @@ +import { configFilePath1, configFilePath2 } from "@server/lib/consts"; +import fs from "fs"; +import yaml from "js-yaml"; + +const version = "1.6.0"; + +export default async function migration() { + console.log(`Running setup script ${version}...`); + + try { + // Determine which config file exists + const filePaths = [configFilePath1, configFilePath2]; + let filePath = ""; + for (const path of filePaths) { + if (fs.existsSync(path)) { + filePath = path; + break; + } + } + + if (!filePath) { + throw new Error( + `No config file found (expected config.yml or config.yaml).` + ); + } + + // Read and parse the YAML file + let rawConfig: any; + const fileContents = fs.readFileSync(filePath, "utf8"); + rawConfig = yaml.load(fileContents); + + if (rawConfig.server?.trust_proxy) { + rawConfig.server.trust_proxy = 1; + } + + // Write the updated YAML back to the file + const updatedYaml = yaml.dump(rawConfig); + fs.writeFileSync(filePath, updatedYaml, "utf8"); + + console.log(`Set trust_proxy to 1 in config file`); + } catch (e) { + console.log(`Unable to migrate config file. Error: ${e}`); + } + + console.log(`${version} migration complete`); +}