diff --git a/server/setup/migrations.ts b/server/setup/migrations.ts index 5581fc24..52a82ad4 100644 --- a/server/setup/migrations.ts +++ b/server/setup/migrations.ts @@ -14,6 +14,7 @@ import m5 from "./scripts/1.0.0-beta6"; import m6 from "./scripts/1.0.0-beta9"; import m7 from "./scripts/1.0.0-beta10"; import m8 from "./scripts/1.0.0-beta12"; +import m13 from "./scripts/1.0.0-beta13"; // THIS CANNOT IMPORT ANYTHING FROM THE SERVER // EXCEPT FOR THE DATABASE AND THE SCHEMA @@ -27,7 +28,8 @@ const migrations = [ { version: "1.0.0-beta.6", run: m5 }, { version: "1.0.0-beta.9", run: m6 }, { version: "1.0.0-beta.10", run: m7 }, - { version: "1.0.0-beta.12", run: m8 } + { version: "1.0.0-beta.12", run: m8 }, + { version: "1.0.0-beta.13", run: m13 } // Add new migrations here as they are created ] as const; diff --git a/server/setup/scripts/1.0.0-beta13.ts b/server/setup/scripts/1.0.0-beta13.ts new file mode 100644 index 00000000..26dac8f9 --- /dev/null +++ b/server/setup/scripts/1.0.0-beta13.ts @@ -0,0 +1,29 @@ +import db from "@server/db"; +import { sql } from "drizzle-orm"; + +export default async function migration() { + console.log("Running setup script 1.0.0-beta.13..."); + + try { + db.transaction((trx) => { + trx.run(sql`CREATE TABLE resourceRules ( + ruleId integer PRIMARY KEY AUTOINCREMENT NOT NULL, + resourceId integer NOT NULL, + action text NOT NULL, + match text NOT NULL, + value text NOT NULL, + FOREIGN KEY (resourceId) REFERENCES resources(resourceId) ON UPDATE no action ON DELETE cascade + );`); + trx.run( + sql`ALTER TABLE resources ADD applyRules integer DEFAULT false NOT NULL;` + ); + }); + + console.log(`Added new table and column: resourceRules, applyRules`); + } catch (e) { + console.log("Unable to add new table and column: resourceRules, applyRules"); + throw e; + } + + console.log("Done."); +}