mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +00:00
Fix migration
This commit is contained in:
@@ -13,21 +13,31 @@ export default async function migration() {
|
||||
|
||||
db.transaction(() => {
|
||||
|
||||
const webauthnCredentials = db.prepare(`SELECT credentialId, publicKey FROM 'webauthnCredentials'`).all() as {
|
||||
credentialId: string; publicKey: string
|
||||
const webauthnCredentials = db.prepare(`SELECT credentialId, publicKey, userId, signCount, transports, name, lastUsed, dateCreated FROM 'webauthnCredentials'`).all() as {
|
||||
credentialId: string; publicKey: string; userId: string; signCount: number; transports: string | null; name: string | null; lastUsed: string; dateCreated: string;
|
||||
}[];
|
||||
|
||||
for (const webauthnCredential of webauthnCredentials) {
|
||||
const credentialId = isoBase64URL.fromBuffer(new Uint8Array(Buffer.from(webauthnCredential.credentialId, 'base64')));
|
||||
db.prepare(
|
||||
`UPDATE 'webauthnCredentials' SET 'credentialId' = ? WHERE 'credentialId' = ?`
|
||||
).run(credentialId, webauthnCredential.credentialId);
|
||||
|
||||
const publicKey = isoBase64URL.fromBuffer(new Uint8Array(Buffer.from(webauthnCredential.publicKey, 'base64')));
|
||||
db.prepare(
|
||||
`UPDATE 'webauthnCredentials' SET 'publicKey' = ? WHERE 'credentialId' = ?`
|
||||
).run(publicKey, webauthnCredential.credentialId);
|
||||
}
|
||||
const newCredentialId = isoBase64URL.fromBuffer(new Uint8Array(Buffer.from(webauthnCredential.credentialId, 'base64')));
|
||||
const newPublicKey = isoBase64URL.fromBuffer(new Uint8Array(Buffer.from(webauthnCredential.publicKey, 'base64')));
|
||||
|
||||
// Delete the old record
|
||||
db.prepare(`DELETE FROM 'webauthnCredentials' WHERE 'credentialId' = ?`).run(webauthnCredential.credentialId);
|
||||
|
||||
// Insert the updated record with converted values
|
||||
db.prepare(
|
||||
`INSERT INTO 'webauthnCredentials' (credentialId, publicKey, userId, signCount, transports, name, lastUsed, dateCreated) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
).run(
|
||||
newCredentialId,
|
||||
newPublicKey,
|
||||
webauthnCredential.userId,
|
||||
webauthnCredential.signCount,
|
||||
webauthnCredential.transports,
|
||||
webauthnCredential.name,
|
||||
webauthnCredential.lastUsed,
|
||||
webauthnCredential.dateCreated
|
||||
);
|
||||
}
|
||||
})();
|
||||
|
||||
console.log(`${version} migration complete`);
|
||||
|
||||
Reference in New Issue
Block a user