mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-06 02:36:38 +00:00
Update migration
This commit is contained in:
@@ -49,33 +49,35 @@ export default async function migration() {
|
|||||||
INSERT INTO "webauthnCredentials" ("credentialId", "publicKey", "userId", "signCount", "transports", "name", "lastUsed", "dateCreated")
|
INSERT INTO "webauthnCredentials" ("credentialId", "publicKey", "userId", "signCount", "transports", "name", "lastUsed", "dateCreated")
|
||||||
VALUES (${newCredentialId}, ${newPublicKey}, ${webauthnCredential.userId}, ${webauthnCredential.signCount}, ${webauthnCredential.transports}, ${webauthnCredential.name}, ${webauthnCredential.lastUsed}, ${webauthnCredential.dateCreated})
|
VALUES (${newCredentialId}, ${newPublicKey}, ${webauthnCredential.userId}, ${webauthnCredential.signCount}, ${webauthnCredential.transports}, ${webauthnCredential.name}, ${webauthnCredential.lastUsed}, ${webauthnCredential.dateCreated})
|
||||||
`);
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
// 1. Add the column with placeholder so NOT NULL is satisfied
|
// 1. Add the column with placeholder so NOT NULL is satisfied
|
||||||
await db.execute(sql`
|
await db.execute(sql`
|
||||||
ALTER TABLE "resources"
|
ALTER TABLE "resources"
|
||||||
ADD COLUMN IF NOT EXISTS "resourceGuid" varchar(36) NOT NULL DEFAULT 'PLACEHOLDER'
|
ADD COLUMN IF NOT EXISTS "resourceGuid" varchar(36) NOT NULL DEFAULT 'PLACEHOLDER'
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// 2. Fetch every row to backfill UUIDs
|
// 2. Fetch every row to backfill UUIDs
|
||||||
const rows = await db.execute(
|
const rows = await db.execute(
|
||||||
sql`SELECT "resourceId" FROM "resources" WHERE "resourceGuid" = 'PLACEHOLDER'`
|
sql`SELECT "resourceId" FROM "resources" WHERE "resourceGuid" = 'PLACEHOLDER'`
|
||||||
);
|
);
|
||||||
const resources = rows.rows as { resourceId: number }[];
|
const resources = rows.rows as { resourceId: number }[];
|
||||||
|
|
||||||
for (const r of resources) {
|
for (const r of resources) {
|
||||||
await db.execute(sql`
|
await db.execute(sql`
|
||||||
UPDATE "resources"
|
UPDATE "resources"
|
||||||
SET "resourceGuid" = ${randomUUID()}
|
SET "resourceGuid" = ${randomUUID()}
|
||||||
WHERE "resourceId" = ${r.resourceId}
|
WHERE "resourceId" = ${r.resourceId}
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Add UNIQUE constraint now that values are filled
|
// 3. Add UNIQUE constraint now that values are filled
|
||||||
await db.execute(sql`
|
await db.execute(sql`
|
||||||
ALTER TABLE "resources"
|
ALTER TABLE "resources"
|
||||||
ADD CONSTRAINT "resources_resourceGuid_unique" UNIQUE("resourceGuid")
|
ADD CONSTRAINT "resources_resourceGuid_unique" UNIQUE("resourceGuid")
|
||||||
`);
|
`);
|
||||||
}
|
|
||||||
|
await db.execute(sql`ALTER TABLE "orgs" ADD COLUMN IF NOT EXISTS "settings" text`);
|
||||||
|
|
||||||
await db.execute(sql`COMMIT`);
|
await db.execute(sql`COMMIT`);
|
||||||
console.log(`Updated credentialId and publicKey`);
|
console.log(`Updated credentialId and publicKey`);
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ export default async function migration() {
|
|||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
updateStmt.run(randomUUID(), row.resourceId);
|
updateStmt.run(randomUUID(), row.resourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.prepare(`ALTER TABLE "orgs" ADD COLUMN IF NOT EXISTS "settings" text`).run();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
console.log(`${version} migration complete`);
|
console.log(`${version} migration complete`);
|
||||||
|
|||||||
Reference in New Issue
Block a user