fix problem with initialization & refactor types
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
type SqlValue = string | number | null | Uint8Array;
|
||||
|
||||
export interface QueryExecResult {
|
||||
columns: Array<string>;
|
||||
values: Array<Array<SqlValue>>;
|
||||
}
|
||||
import { QueryExecResult } from '../interfaces/database';
|
||||
|
||||
interface Migration {
|
||||
name: string;
|
||||
@@ -36,13 +31,17 @@ export class MigrationService {
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
);
|
||||
`);
|
||||
|
||||
// Get list of executed migrations
|
||||
const result = await sqlExec('SELECT name FROM migrations');
|
||||
const singleResult = result[0];
|
||||
const executedMigrations = new Set(singleResult.values.map(row => row[0]));
|
||||
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]));
|
||||
}
|
||||
|
||||
// Run pending migrations in order
|
||||
for (const migration of this.migrations) {
|
||||
|
||||
Reference in New Issue
Block a user