fosrl.pangolin/server/setup/scriptsPg/1.8.0.ts
Adrian Astles ec8d3569d3 fix: resolve build errors and improve database migration system
- Remove unused SQLite migration script 1.8.1.ts that was causing
  TypeScript compilation errors during PostgreSQL builds
- Fix verifyTotp.ts type error by adding proper null check for password
  parameter before passing to verifyPassword function
- Fix SQLite migration script 1.7.0.ts syntax errors in transaction
  structure and error handling
**- Update SQLite migration system to not drop tables by default, as this was used during testing and should not be in production.**

Fixes build failures for both "make build" (SQLite) and "make build-pg"
(PostgreSQL) Docker image builds.
2025-07-15 06:40:31 +08:00

31 lines
No EOL
984 B
TypeScript

import { db } from "@server/db/pg";
export default async function migrate() {
try {
console.log("Starting webauthnChallenge table creation...");
// Create the table (PostgreSQL already has the correct table name)
await db.execute(`
CREATE TABLE IF NOT EXISTS webauthnChallenge (
sessionId TEXT PRIMARY KEY,
challenge TEXT NOT NULL,
securityKeyName TEXT,
userId TEXT,
expiresAt INTEGER NOT NULL,
FOREIGN KEY (userId) REFERENCES user(id) ON DELETE CASCADE
);
`);
// Create the index
await db.execute(`
CREATE INDEX IF NOT EXISTS idx_webauthnChallenge_expiresAt ON webauthnChallenge(expiresAt);
`);
console.log("Successfully created webauthnChallenge table and index");
return true;
} catch (error: any) {
console.error("Unable to create webauthnChallenge table:", error);
console.error("Error details:", error.message);
return false;
}
}