mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-26 20:25:42 +02:00
- 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.
54 lines
No EOL
1.9 KiB
TypeScript
54 lines
No EOL
1.9 KiB
TypeScript
import { APP_PATH } from "@server/lib/consts";
|
|
import Database from "better-sqlite3";
|
|
import path from "path";
|
|
|
|
const version = "1.7.0";
|
|
|
|
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);
|
|
|
|
try {
|
|
db.pragma("foreign_keys = OFF");
|
|
db.transaction(() => {
|
|
// Add passwordResetTokenExpiryHours column to orgs table with default value of 1
|
|
db.exec(`
|
|
ALTER TABLE orgs ADD COLUMN passwordResetTokenExpiryHours INTEGER NOT NULL DEFAULT 1;
|
|
`);
|
|
})(); // executes the transaction immediately
|
|
db.pragma("foreign_keys = ON");
|
|
console.log(`Added passwordResetTokenExpiryHours column to orgs table`);
|
|
} catch (e) {
|
|
console.log("Error adding passwordResetTokenExpiryHours column to orgs table:");
|
|
console.log(e);
|
|
}
|
|
|
|
try {
|
|
db.pragma("foreign_keys = OFF");
|
|
db.transaction(() => {
|
|
db.exec(`
|
|
CREATE TABLE IF NOT EXISTS securityKey (
|
|
credentialId TEXT PRIMARY KEY,
|
|
userId TEXT NOT NULL,
|
|
publicKey TEXT NOT NULL,
|
|
signCount INTEGER NOT NULL,
|
|
transports TEXT,
|
|
name TEXT,
|
|
lastUsed TEXT NOT NULL,
|
|
dateCreated TEXT NOT NULL,
|
|
FOREIGN KEY (userId) REFERENCES user(id) ON DELETE CASCADE
|
|
);
|
|
`);
|
|
})(); // executes the transaction immediately
|
|
db.pragma("foreign_keys = ON");
|
|
console.log(`Created securityKey table`);
|
|
} catch (e) {
|
|
console.error("Unable to create securityKey table");
|
|
console.error(e);
|
|
throw e;
|
|
}
|
|
|
|
console.log(`${version} migration complete`);
|
|
}
|