|
1 | 1 | import { schema, setClient } from '@tloncorp/shared/db';
|
2 | 2 | import { handleChange } from '@tloncorp/shared/db';
|
| 3 | +import * as kv from '@tloncorp/shared/db'; |
3 | 4 | import { migrations } from '@tloncorp/shared/db/migrations';
|
4 | 5 | import { drizzle } from 'drizzle-orm/sqlite-proxy';
|
5 | 6 |
|
@@ -128,6 +129,9 @@ export class ElectronDb extends BaseDb {
|
128 | 129 | await window.sqliteBridge.purgeDb();
|
129 | 130 | this.client = null;
|
130 | 131 |
|
| 132 | + // reset values related to tracking db sync state |
| 133 | + await kv.headsSyncedAt.resetValue(); |
| 134 | + |
131 | 135 | logger.log('Purged Electron SQLite database, reconnecting');
|
132 | 136 | await this.setupDb();
|
133 | 137 | }
|
@@ -170,18 +174,22 @@ export class ElectronDb extends BaseDb {
|
170 | 174 | } catch (e) {
|
171 | 175 | // Check if this is a "table already exists" error, which isn't fatal
|
172 | 176 | if (e.message && e.message.includes('already exists')) {
|
173 |
| - logger.log('Migration contains tables that already exist, continuing', e); |
| 177 | + logger.log( |
| 178 | + 'Migration contains tables that already exist, continuing', |
| 179 | + e |
| 180 | + ); |
174 | 181 | return;
|
175 |
| - } |
176 |
| - |
| 182 | + } |
| 183 | + |
177 | 184 | // For other errors, log but don't purge database
|
178 | 185 | logger.error('Migration failed:', e);
|
179 |
| - |
| 186 | + |
180 | 187 | // Only purge the database for critical errors that prevent app from working
|
181 |
| - if (e.message && ( |
182 |
| - e.message.includes('database is corrupted') || |
183 |
| - e.message.includes('database disk image is malformed') |
184 |
| - )) { |
| 188 | + if ( |
| 189 | + e.message && |
| 190 | + (e.message.includes('database is corrupted') || |
| 191 | + e.message.includes('database disk image is malformed')) |
| 192 | + ) { |
185 | 193 | logger.error('Database appears corrupted, purging and retrying');
|
186 | 194 | await this.purgeDb();
|
187 | 195 | await window.sqliteBridge.runMigrations(formattedMigrations);
|
|
0 commit comments