Update migrations

This commit is contained in:
Owen
2025-09-11 21:28:15 -07:00
parent 3b726dfb1e
commit 3eaca924da
2 changed files with 37 additions and 14 deletions

View File

@@ -16,13 +16,31 @@ export default async function migration() {
await db.execute(sql`BEGIN`);
await db.execute(sql`ALTER TABLE "exitNodes" ADD COLUMN "region" text;`);
await db.execute(sql`ALTER TABLE "idpOidcConfig" ADD COLUMN "variant" text DEFAULT 'oidc' NOT NULL;`);
await db.execute(sql`ALTER TABLE "resources" ADD COLUMN "niceId" text DEFAULT '' NOT NULL;`);
await db.execute(sql`ALTER TABLE "userOrgs" ADD COLUMN "autoProvisioned" boolean DEFAULT false;`);
await db.execute(
sql`ALTER TABLE "exitNodes" ADD COLUMN "region" text;`
);
await db.execute(
sql`ALTER TABLE "idpOidcConfig" ADD COLUMN "variant" text DEFAULT 'oidc' NOT NULL;`
);
await db.execute(
sql`ALTER TABLE "resources" ADD COLUMN "niceId" text DEFAULT '' NOT NULL;`
);
await db.execute(
sql`ALTER TABLE "userOrgs" ADD COLUMN "autoProvisioned" boolean DEFAULT false;`
);
await db.execute(
sql`ALTER TABLE "targets" ADD COLUMN "pathMatchType" text;`
);
await db.execute(sql`ALTER TABLE "targets" ADD COLUMN "path" text;`);
await db.execute(
sql`ALTER TABLE "resources" ADD COLUMN "headers" text;`
);
const usedNiceIds: string[] = [];

View File

@@ -12,14 +12,14 @@ export default async function migration() {
const db = new Database(location);
const resourceSiteMap = new Map<number, number>();
const firstSiteId: number = 1;
const firstSiteId: number = 1;
try {
const resources = db
.prepare(
"SELECT resourceId FROM resources WHERE siteId IS NOT NULL"
)
.all() as Array<{ resourceId: number; }>;
const resources = db
.prepare(
"SELECT resourceId FROM resources WHERE siteId IS NOT NULL"
)
.all() as Array<{ resourceId: number }>;
db.transaction(() => {
db.exec(`
@@ -27,6 +27,9 @@ export default async function migration() {
ALTER TABLE 'idpOidcConfig' ADD 'variant' text DEFAULT 'oidc' NOT NULL;
ALTER TABLE 'resources' ADD 'niceId' text DEFAULT '' NOT NULL;
ALTER TABLE 'userOrgs' ADD 'autoProvisioned' integer DEFAULT false;
ALTER TABLE 'targets' ADD 'pathMatchType' text;
ALTER TABLE 'targets' ADD 'path' text;
ALTER TABLE 'resources' ADD 'headers' text;
`); // this diverges from the schema a bit because the schema does not have a default on niceId but was required for the migration and I dont think it will effect much down the line...
const usedNiceIds: string[] = [];
@@ -47,7 +50,9 @@ export default async function migration() {
}
loops++;
}
db.prepare(`UPDATE resources SET niceId = ? WHERE resourceId = ?`).run(niceId, resourceId.resourceId);
db.prepare(
`UPDATE resources SET niceId = ? WHERE resourceId = ?`
).run(niceId, resourceId.resourceId);
}
})();