mirror of
https://github.com/fosrl/pangolin.git
synced 2025-12-15 20:46:27 +00:00
Update migrations
This commit is contained in:
@@ -11,7 +11,11 @@ export default async function migration() {
|
||||
|
||||
try {
|
||||
const resources = await db.execute(sql`
|
||||
SELECT "resourceId" FROM "resources" WHERE "siteId" IS NOT NULL
|
||||
SELECT "resourceId" FROM "resources"
|
||||
`);
|
||||
|
||||
const siteResources = await db.execute(sql`
|
||||
SELECT "siteResourceId" FROM "siteResources"
|
||||
`);
|
||||
|
||||
await db.execute(sql`BEGIN`);
|
||||
@@ -28,6 +32,10 @@ export default async function migration() {
|
||||
sql`ALTER TABLE "resources" ADD COLUMN "niceId" text DEFAULT '' NOT NULL;`
|
||||
);
|
||||
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "siteResources" ADD COLUMN "niceId" text DEFAULT '' NOT NULL;`
|
||||
);
|
||||
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "userOrgs" ADD COLUMN "autoProvisioned" boolean DEFAULT false;`
|
||||
);
|
||||
@@ -65,6 +73,27 @@ export default async function migration() {
|
||||
`);
|
||||
}
|
||||
|
||||
for (const resource of siteResources.rows) {
|
||||
// Generate a unique name and ensure it's unique
|
||||
let niceId = "";
|
||||
let loops = 0;
|
||||
while (true) {
|
||||
if (loops > 100) {
|
||||
throw new Error("Could not generate a unique name");
|
||||
}
|
||||
|
||||
niceId = generateName();
|
||||
if (!usedNiceIds.includes(niceId)) {
|
||||
usedNiceIds.push(niceId);
|
||||
break;
|
||||
}
|
||||
loops++;
|
||||
}
|
||||
await db.execute(sql`
|
||||
UPDATE "siteResources" SET "niceId" = ${niceId} WHERE "siteResourceId" = ${resource.siteResourceId}
|
||||
`);
|
||||
}
|
||||
|
||||
await db.execute(sql`COMMIT`);
|
||||
console.log(`Migrated database`);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user