Add migrations

This commit is contained in:
Owen 2025-02-09 11:10:19 -05:00
parent 117548c9bb
commit 45dcdd8f85
2 changed files with 32 additions and 1 deletions

View file

@ -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.");
}