mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-29 22:19:31 +02:00
migrations
This commit is contained in:
parent
4bcb4a1590
commit
49f84bccad
2 changed files with 20 additions and 15 deletions
|
@ -3,8 +3,6 @@ import { sql } from "drizzle-orm";
|
|||
|
||||
const version = "1.9.0";
|
||||
|
||||
await migration();
|
||||
|
||||
export default async function migration() {
|
||||
console.log(`Running setup script ${version}...`);
|
||||
|
||||
|
|
|
@ -11,8 +11,15 @@ export default async function migration() {
|
|||
const db = new Database(location);
|
||||
|
||||
const resourceSiteMap = new Map<number, number>();
|
||||
let firstSiteId: number = 1;
|
||||
|
||||
try {
|
||||
// Get the first siteId to use as default
|
||||
const firstSite = db.prepare("SELECT siteId FROM sites LIMIT 1").get() as { siteId: number } | undefined;
|
||||
if (firstSite) {
|
||||
firstSiteId = firstSite.siteId;
|
||||
}
|
||||
|
||||
const resources = db
|
||||
.prepare(
|
||||
"SELECT resourceId, siteId FROM resources WHERE siteId IS NOT NULL"
|
||||
|
@ -109,7 +116,7 @@ ALTER TABLE 'exitNodes' ADD 'lastPing' integer;--> statement-breakpoint
|
|||
ALTER TABLE 'exitNodes' ADD 'type' text DEFAULT 'gerbil';--> statement-breakpoint
|
||||
ALTER TABLE 'olms' ADD 'version' text;--> statement-breakpoint
|
||||
ALTER TABLE 'orgs' ADD 'createdAt' text;--> statement-breakpoint
|
||||
ALTER TABLE 'targets' ADD 'siteId' integer NOT NULL DEFAULT 1 REFERENCES sites(siteId);`);
|
||||
ALTER TABLE 'targets' ADD 'siteId' integer NOT NULL DEFAULT ${firstSiteId || 1} REFERENCES sites(siteId);`);
|
||||
|
||||
// for each resource, get all of its targets, and update the siteId to be the previously stored siteId
|
||||
for (const [resourceId, siteId] of resourceSiteMap) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue