diff --git a/server/setup/migrationsSqlite.ts b/server/setup/migrationsSqlite.ts index 8ff66c49..640836e0 100644 --- a/server/setup/migrationsSqlite.ts +++ b/server/setup/migrationsSqlite.ts @@ -33,6 +33,7 @@ import m28 from "./scriptsSqlite/1.11.0"; import m29 from "./scriptsSqlite/1.11.1"; import m30 from "./scriptsSqlite/1.12.0"; import m31 from "./scriptsSqlite/1.13.0"; +import m32 from "./scriptsSqlite/1.14.0"; // THIS CANNOT IMPORT ANYTHING FROM THE SERVER // EXCEPT FOR THE DATABASE AND THE SCHEMA @@ -64,7 +65,8 @@ const migrations = [ { version: "1.11.0", run: m28 }, { version: "1.11.1", run: m29 }, { version: "1.12.0", run: m30 }, - { version: "1.13.0", run: m31 } + { version: "1.13.0", run: m31 }, + { version: "1.14.0", run: m32 } // Add new migrations here as they are created ] as const; diff --git a/server/setup/scriptsSqlite/1.14.0.ts b/server/setup/scriptsSqlite/1.14.0.ts new file mode 100644 index 00000000..ce7e0ae5 --- /dev/null +++ b/server/setup/scriptsSqlite/1.14.0.ts @@ -0,0 +1,99 @@ +import { __DIRNAME, APP_PATH } from "@server/lib/consts"; +import Database from "better-sqlite3"; +import path from "path"; + +const version = "1.14.0"; + +await migration(); + +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( + ` + CREATE TABLE 'loginPageBranding' ( + 'loginPageBrandingId' integer PRIMARY KEY AUTOINCREMENT NOT NULL, + 'logoUrl' text NOT NULL, + 'logoWidth' integer NOT NULL, + 'logoHeight' integer NOT NULL, + 'primaryColor' text, + 'resourceTitle' text NOT NULL, + 'resourceSubtitle' text, + 'orgTitle' text, + 'orgSubtitle' text + ); + ` + ).run(); + + db.prepare( + ` + CREATE TABLE 'loginPageBrandingOrg' ( + 'loginPageBrandingId' integer NOT NULL, + 'orgId' text NOT NULL, + FOREIGN KEY ('loginPageBrandingId') REFERENCES 'loginPageBranding'('loginPageBrandingId') ON UPDATE no action ON DELETE cascade, + FOREIGN KEY ('orgId') REFERENCES 'orgs'('orgId') ON UPDATE no action ON DELETE cascade + ); + ` + ).run(); + + db.prepare( + ` + CREATE TABLE 'resourceHeaderAuthExtendedCompatibility' ( + 'headerAuthExtendedCompatibilityId' integer PRIMARY KEY AUTOINCREMENT NOT NULL, + 'resourceId' integer NOT NULL, + 'extendedCompatibilityIsActivated' integer NOT NULL, + FOREIGN KEY ('resourceId') REFERENCES 'resources'('resourceId') ON UPDATE no action ON DELETE cascade + ); + ` + ).run(); + + db.prepare( + `ALTER TABLE 'resources' ADD 'maintenanceModeEnabled' integer DEFAULT false NOT NULL;` + ).run(); + + db.prepare( + `ALTER TABLE 'resources' ADD 'maintenanceModeType' text DEFAULT 'forced';` + ).run(); + + db.prepare( + `ALTER TABLE 'resources' ADD 'maintenanceTitle' text;` + ).run(); + + db.prepare( + `ALTER TABLE 'resources' ADD 'maintenanceMessage' text;` + ).run(); + + db.prepare( + `ALTER TABLE 'resources' ADD 'maintenanceEstimatedTime' text;` + ).run(); + + db.prepare( + `ALTER TABLE 'siteResources' ADD 'tcpPortRangeString' text;` + ).run(); + + db.prepare( + `ALTER TABLE 'siteResources' ADD 'udpPortRangeString' text;` + ).run(); + + db.prepare( + `ALTER TABLE 'siteResources' ADD 'disableIcmp' 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`); +}