mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +00:00
added migration for simplewebauthn
This commit is contained in:
@@ -11,6 +11,7 @@ import m3 from "./scriptsPg/1.8.0";
|
||||
import m4 from "./scriptsPg/1.9.0";
|
||||
import m5 from "./scriptsPg/1.10.0";
|
||||
import m6 from "./scriptsPg/1.10.2";
|
||||
import m7 from "./scriptsPg/1.10.4";
|
||||
|
||||
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
|
||||
// EXCEPT FOR THE DATABASE AND THE SCHEMA
|
||||
@@ -23,6 +24,7 @@ const migrations = [
|
||||
{ version: "1.9.0", run: m4 },
|
||||
{ version: "1.10.0", run: m5 },
|
||||
{ version: "1.10.2", run: m6 },
|
||||
{ version: "1.10.4", run: m7 },
|
||||
// Add new migrations here as they are created
|
||||
] as {
|
||||
version: string;
|
||||
|
||||
@@ -29,6 +29,7 @@ import m24 from "./scriptsSqlite/1.9.0";
|
||||
import m25 from "./scriptsSqlite/1.10.0";
|
||||
import m26 from "./scriptsSqlite/1.10.1";
|
||||
import m27 from "./scriptsSqlite/1.10.2";
|
||||
import m28 from "./scriptsSqlite/1.10.4";
|
||||
|
||||
// THIS CANNOT IMPORT ANYTHING FROM THE SERVER
|
||||
// EXCEPT FOR THE DATABASE AND THE SCHEMA
|
||||
@@ -57,6 +58,7 @@ const migrations = [
|
||||
{ version: "1.10.0", run: m25 },
|
||||
{ version: "1.10.1", run: m26 },
|
||||
{ version: "1.10.2", run: m27 },
|
||||
{ version: "1.10.4", run: m28 },
|
||||
// Add new migrations here as they are created
|
||||
] as const;
|
||||
|
||||
|
||||
39
server/setup/scriptsPg/1.10.4.ts
Normal file
39
server/setup/scriptsPg/1.10.4.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { db } from "@server/db/pg/driver";
|
||||
import { sql } from "drizzle-orm";
|
||||
import { isoBase64URL } from "@simplewebauthn/server/helpers";
|
||||
|
||||
const version = "1.10.4";
|
||||
|
||||
export default async function migration() {
|
||||
console.log(`Running setup script ${version}...`);
|
||||
|
||||
try {
|
||||
await db.execute(sql`BEGIN`);
|
||||
|
||||
const webauthnCredentialsQuery = await db.execute(sql`SELECT credentialId, publicKey FROM 'webauthnCredentials'`);
|
||||
|
||||
const webauthnCredentials = webauthnCredentialsQuery.rows as { credentialId: string; publicKey: string }[];
|
||||
|
||||
for (const webauthnCredential of webauthnCredentials) {
|
||||
const credentialId = isoBase64URL.fromBuffer(new Uint8Array(Buffer.from(webauthnCredential.credentialId, 'base64')));
|
||||
await db.execute(sql`
|
||||
UPDATE "webauthnCredentials" SET "credentialId" = ${credentialId}
|
||||
`);
|
||||
|
||||
const publicKey = isoBase64URL.fromBuffer(new Uint8Array(Buffer.from(webauthnCredential.publicKey, 'base64')));
|
||||
await db.execute(sql`
|
||||
UPDATE "webauthnCredentials" SET "publicKey" = ${publicKey}
|
||||
`);
|
||||
}
|
||||
|
||||
await db.execute(sql`COMMIT`);
|
||||
console.log(`Updated credentialId and publicKey`);
|
||||
} catch (e) {
|
||||
await db.execute(sql`ROLLBACK`);
|
||||
console.log("Unable to update credentialId and publicKey");
|
||||
console.log(e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
console.log(`${version} migration complete`);
|
||||
}
|
||||
34
server/setup/scriptsSqlite/1.10.4.ts
Normal file
34
server/setup/scriptsSqlite/1.10.4.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { APP_PATH } from "@server/lib/consts";
|
||||
import Database from "better-sqlite3";
|
||||
import path from "path";
|
||||
import { isoBase64URL } from "@simplewebauthn/server/helpers";
|
||||
|
||||
const version = "1.10.4";
|
||||
|
||||
export default async function migration() {
|
||||
console.log(`Running setup script ${version}...`);
|
||||
|
||||
const location = path.join(APP_PATH, "db", "db.sqlite");
|
||||
const db = new Database(location);
|
||||
|
||||
db.transaction(() => {
|
||||
|
||||
const webauthnCredentials = db.prepare(`SELECT credentialId, publicKey FROM 'webauthnCredentials'`).all() as {
|
||||
credentialId: string; publicKey: string
|
||||
}[];
|
||||
|
||||
for (const webauthnCredential of webauthnCredentials) {
|
||||
const credentialId = isoBase64URL.fromBuffer(new Uint8Array(Buffer.from(webauthnCredential.credentialId, 'base64')));
|
||||
db.prepare(
|
||||
`UPDATE 'webauthnCredentials' SET 'credentialId' = ?`
|
||||
).run(credentialId);
|
||||
|
||||
const publicKey = isoBase64URL.fromBuffer(new Uint8Array(Buffer.from(webauthnCredential.publicKey, 'base64')));
|
||||
db.prepare(
|
||||
`UPDATE 'webauthnCredentials' SET 'publicKey' = ?`
|
||||
).run(publicKey);
|
||||
}
|
||||
})();
|
||||
|
||||
console.log(`${version} migration complete`);
|
||||
}
|
||||
Reference in New Issue
Block a user