mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-31 15:09:39 +02:00
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.
This commit is contained in:
parent
5278c4d6f2
commit
ec8d3569d3
10 changed files with 96 additions and 114 deletions
|
@ -1,46 +1,13 @@
|
|||
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
||||
import db from "./driver";
|
||||
import path from "path";
|
||||
import { location } from "./driver";
|
||||
import Database from "better-sqlite3";
|
||||
import type { Database as BetterSqlite3Database } from "better-sqlite3";
|
||||
|
||||
const migrationsFolder = path.join("server/migrations");
|
||||
|
||||
const dropAllTables = (sqlite: BetterSqlite3Database) => {
|
||||
console.log("Dropping all existing tables...");
|
||||
|
||||
// Disable foreign key checks
|
||||
sqlite.pragma('foreign_keys = OFF');
|
||||
|
||||
// Get all tables
|
||||
const tables = sqlite.prepare(`
|
||||
SELECT name FROM sqlite_master
|
||||
WHERE type='table'
|
||||
AND name NOT LIKE 'sqlite_%'
|
||||
`).all() as { name: string }[];
|
||||
|
||||
// Drop each table
|
||||
for (const table of tables) {
|
||||
console.log(`Dropping table: ${table.name}`);
|
||||
sqlite.prepare(`DROP TABLE IF EXISTS "${table.name}"`).run();
|
||||
}
|
||||
|
||||
// Re-enable foreign key checks
|
||||
sqlite.pragma('foreign_keys = ON');
|
||||
};
|
||||
|
||||
const runMigrations = async () => {
|
||||
console.log("Running migrations...");
|
||||
try {
|
||||
// Initialize the database file with a valid SQLite header
|
||||
const sqlite = new Database(location) as BetterSqlite3Database;
|
||||
|
||||
// Drop all existing tables first
|
||||
dropAllTables(sqlite);
|
||||
|
||||
// Run the migrations
|
||||
migrate(db as any, {
|
||||
await migrate(db as any, {
|
||||
migrationsFolder: migrationsFolder,
|
||||
});
|
||||
console.log("Migrations completed successfully.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue