forked from trent_larson/crowd-funder-for-time-pwa
refactor(db): improve type safety in migration system
- Replace any[] with SqlValue[] type for SQL parameters in runMigrations - Update import to use QueryExecResult from interfaces/database - Add proper typing for SQL parameter values (string | number | null | Uint8Array) This change improves type safety and helps catch potential SQL parameter type mismatches at compile time, reducing the risk of runtime errors or data corruption.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import migrationService from "../services/migrationService";
|
||||
import type { QueryExecResult } from "../services/migrationService";
|
||||
import type { QueryExecResult, SqlValue } from "../interfaces/database";
|
||||
|
||||
// Each migration can include multiple SQL statements (with semicolons)
|
||||
const MIGRATIONS = [
|
||||
@@ -96,7 +96,10 @@ export async function registerMigrations(): Promise<void> {
|
||||
}
|
||||
|
||||
export async function runMigrations(
|
||||
sqlExec: (sql: string, params?: any[]) => Promise<Array<QueryExecResult>>,
|
||||
sqlExec: (
|
||||
sql: string,
|
||||
params?: SqlValue[],
|
||||
) => Promise<Array<QueryExecResult>>,
|
||||
): Promise<void> {
|
||||
await registerMigrations();
|
||||
await migrationService.runMigrations(sqlExec);
|
||||
|
||||
Reference in New Issue
Block a user