diff --git a/server/lib/consts.ts b/server/lib/consts.ts index b71b3299f..e33ea52b9 100644 --- a/server/lib/consts.ts +++ b/server/lib/consts.ts @@ -2,7 +2,7 @@ import path from "path"; import { fileURLToPath } from "url"; // This is a placeholder value replaced by the build process -export const APP_VERSION = "1.18.3"; +export const APP_VERSION = "1.18.4"; export const __FILENAME = fileURLToPath(import.meta.url); export const __DIRNAME = path.dirname(__FILENAME); diff --git a/server/setup/migrationsPg.ts b/server/setup/migrationsPg.ts index 7c7c67ad7..0b8af06bc 100644 --- a/server/setup/migrationsPg.ts +++ b/server/setup/migrationsPg.ts @@ -24,6 +24,7 @@ import m15 from "./scriptsPg/1.16.0"; import m16 from "./scriptsPg/1.17.0"; import m17 from "./scriptsPg/1.18.0"; import m18 from "./scriptsPg/1.18.3"; +import m19 from "./scriptsPg/1.18.4"; // THIS CANNOT IMPORT ANYTHING FROM THE SERVER // EXCEPT FOR THE DATABASE AND THE SCHEMA @@ -47,7 +48,8 @@ const migrations = [ { version: "1.16.0", run: m15 }, { version: "1.17.0", run: m16 }, { version: "1.18.0", run: m17 }, - { version: "1.18.3", run: m18 } + { version: "1.18.3", run: m18 }, + { version: "1.18.4", run: m19 } // Add new migrations here as they are created ] as { version: string; diff --git a/server/setup/migrationsSqlite.ts b/server/setup/migrationsSqlite.ts index 43ce07629..837b039f7 100644 --- a/server/setup/migrationsSqlite.ts +++ b/server/setup/migrationsSqlite.ts @@ -42,6 +42,7 @@ import m36 from "./scriptsSqlite/1.16.0"; import m37 from "./scriptsSqlite/1.17.0"; import m38 from "./scriptsSqlite/1.18.0"; import m39 from "./scriptsSqlite/1.18.3"; +import m40 from "./scriptsSqlite/1.18.4"; // THIS CANNOT IMPORT ANYTHING FROM THE SERVER // EXCEPT FOR THE DATABASE AND THE SCHEMA @@ -81,7 +82,8 @@ const migrations = [ { version: "1.16.0", run: m36 }, { version: "1.17.0", run: m37 }, { version: "1.18.0", run: m38 }, - { version: "1.18.3", run: m39 } + { version: "1.18.3", run: m39 }, + { version: "1.18.4", run: m40 } // Add new migrations here as they are created ] as const; diff --git a/server/setup/scriptsPg/1.18.4.ts b/server/setup/scriptsPg/1.18.4.ts new file mode 100644 index 000000000..904d414c0 --- /dev/null +++ b/server/setup/scriptsPg/1.18.4.ts @@ -0,0 +1,34 @@ +import { db } from "@server/db/pg/driver"; +import { sql } from "drizzle-orm"; + +const version = "1.18.4"; + +export default async function migration() { + console.log(`Running setup script ${version}...`); + + try { + await db.execute(sql`BEGIN`); + + await db.execute(sql` + ALTER TABLE "connectionAuditLog" ADD COLUMN "clientEndpoint" text; + `); + + await db.execute(sql` + ALTER TABLE "eventStreamingDestinations" ADD COLUMN "lastError" text; + `); + + await db.execute(sql` + ALTER TABLE "eventStreamingDestinations" ADD COLUMN "lastErrorAt" bigint; + `); + + await db.execute(sql`COMMIT`); + console.log("Migrated database"); + } catch (e) { + await db.execute(sql`ROLLBACK`); + console.log("Unable to migrate database"); + console.log(e); + throw e; + } + + console.log(`${version} migration complete`); +} diff --git a/server/setup/scriptsSqlite/1.18.4.ts b/server/setup/scriptsSqlite/1.18.4.ts new file mode 100644 index 000000000..73296ce02 --- /dev/null +++ b/server/setup/scriptsSqlite/1.18.4.ts @@ -0,0 +1,43 @@ +import { APP_PATH } from "@server/lib/consts"; +import Database from "better-sqlite3"; +import path from "path"; + +const version = "1.18.4"; + +export default async function migration() { + console.log(`Running setup script ${version}...`); + + const location = path.join(APP_PATH, "db", "db.sqlite"); + const db = new Database(location); + + try { + db.pragma("foreign_keys = OFF"); + + db.transaction(() => { + db.prepare( + ` + ALTER TABLE 'connectionAuditLog' ADD 'clientEndpoint' text; + ` + ).run(); + db.prepare( + ` + ALTER TABLE 'eventStreamingDestinations' ADD 'lastError' text; + ` + ).run(); + db.prepare( + ` + ALTER TABLE 'eventStreamingDestinations' ADD 'lastErrorAt' integer; + ` + ).run(); + })(); + + db.pragma("foreign_keys = ON"); + + console.log("Migrated database"); + } catch (e) { + console.log("Failed to migrate db:", e); + throw e; + } + + console.log(`${version} migration complete`); +}