fosrl.pangolin/server/setup/scripts/1.0.0-beta13.ts

34 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-02-09 11:10:19 -05:00
import db from "@server/db";
import { sql } from "drizzle-orm";
2025-02-12 22:29:42 -05:00
const version = "1.0.0-beta.13";
2025-02-09 11:10:19 -05:00
export default async function migration() {
2025-02-12 22:29:42 -05:00
console.log(`Running setup script ${version}...`);
2025-02-09 11:10:19 -05:00
try {
db.transaction((trx) => {
trx.run(sql`CREATE TABLE resourceRules (
ruleId integer PRIMARY KEY AUTOINCREMENT NOT NULL,
resourceId integer NOT NULL,
priority integer NOT NULL,
enabled integer DEFAULT true NOT NULL,
2025-02-09 11:10:19 -05:00
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;
}
2025-02-12 22:29:42 -05:00
console.log(`${version} migration complete`);
2025-02-09 11:10:19 -05:00
}