Skip to content

Commit

Permalink
Fix "delete and restart" after database error
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal committed Jul 10, 2021
1 parent 9c48a95 commit 455820a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ app.on('ready', async () => {
`Database startup error:\n\n${redactAll(sqlError.stack)}`
);
} else {
await sql.sqlCall('removeDB', []);
await sql.removeDB();
removeUserConfig();
app.relaunch();
}
Expand Down
7 changes: 7 additions & 0 deletions ts/sql/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export type WorkerRequest =
| {
readonly type: 'close';
}
| {
readonly type: 'removeDB';
}
| {
readonly type: 'sqlCall';
readonly method: string;
Expand Down Expand Up @@ -117,6 +120,10 @@ export class MainSQL {
await this.onExit;
}

public async removeDB(): Promise<void> {
await this.send({ type: 'removeDB' });
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public async sqlCall(method: string, args: ReadonlyArray<any>): Promise<any> {
if (this.onReady) {
Expand Down
7 changes: 7 additions & 0 deletions ts/sql/mainWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ port.on('message', async ({ seq, request }: WrappedWorkerRequest) => {
return;
}

if (request.type === 'removeDB') {
await db.removeDB();

respond(seq, undefined, undefined);
return;
}

if (request.type === 'sqlCall') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const method = (db as any)[request.method];
Expand Down

0 comments on commit 455820a

Please sign in to comment.