forked from jsnbuchanan/crowd-funder-for-time-pwa
fix linting
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { QueryExecResult } from '../interfaces/database';
|
||||
import { QueryExecResult } from "../interfaces/database";
|
||||
|
||||
interface Migration {
|
||||
name: string;
|
||||
@@ -23,7 +23,7 @@ export class MigrationService {
|
||||
}
|
||||
|
||||
async runMigrations(
|
||||
sqlExec: (sql: string, params?: any[]) => Promise<Array<QueryExecResult>>
|
||||
sqlExec: (sql: string, params?: any[]) => Promise<Array<QueryExecResult>>,
|
||||
): Promise<void> {
|
||||
// Create migrations table if it doesn't exist
|
||||
await sqlExec(`
|
||||
@@ -35,12 +35,16 @@ export class MigrationService {
|
||||
`);
|
||||
|
||||
// Get list of executed migrations
|
||||
const result: QueryExecResult[] = await sqlExec('SELECT name FROM migrations;');
|
||||
const result: QueryExecResult[] = await sqlExec(
|
||||
"SELECT name FROM migrations;",
|
||||
);
|
||||
let executedMigrations: Set<string> = new Set();
|
||||
// Even with that query, the QueryExecResult may be [] (which doesn't make sense to me).
|
||||
if (result.length > 0) {
|
||||
const singleResult = result[0];
|
||||
executedMigrations = new Set(singleResult.values.map((row: any[]) => row[0]));
|
||||
executedMigrations = new Set(
|
||||
singleResult.values.map((row: any[]) => row[0]),
|
||||
);
|
||||
}
|
||||
|
||||
// Run pending migrations in order
|
||||
@@ -48,7 +52,9 @@ export class MigrationService {
|
||||
if (!executedMigrations.has(migration.name)) {
|
||||
try {
|
||||
await sqlExec(migration.sql);
|
||||
await sqlExec('INSERT INTO migrations (name) VALUES (?)', [migration.name]);
|
||||
await sqlExec("INSERT INTO migrations (name) VALUES (?)", [
|
||||
migration.name,
|
||||
]);
|
||||
console.log(`Migration ${migration.name} executed successfully`);
|
||||
} catch (error) {
|
||||
console.error(`Error executing migration ${migration.name}:`, error);
|
||||
@@ -59,4 +65,4 @@ export class MigrationService {
|
||||
}
|
||||
}
|
||||
|
||||
export default MigrationService.getInstance();
|
||||
export default MigrationService.getInstance();
|
||||
|
||||
Reference in New Issue
Block a user