Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions apps/desktop/src/store/tinybase/persister/local/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ type MigratedHint = {
value: string;
};

const SESSION_TABLES = [
"sessions",
"mapping_session_participant",
"tags",
"mapping_tag_session",
"transcripts",
"enhanced_notes",
] as const;

function deleteSessionsFromSqlite(store: Store): boolean {
const sessionIds = store.getRowIds("sessions");
if (sessionIds.length === 0) {
return false;
}

store.transaction(() => {
for (const table of SESSION_TABLES) {
for (const rowId of store.getRowIds(table)) {
store.delRow(table, rowId);
}
}
});

return true;
}

function migrateWordsAndHintsToTranscripts(store: Store): boolean {
const wordIds = store.getRowIds("words");
if (wordIds.length === 0) {
Expand Down Expand Up @@ -127,8 +153,17 @@ export function useLocalPersister(store: Store) {
await persister.load();

if (getCurrentWebviewWindowLabel() === "main") {
const migrated = migrateWordsAndHintsToTranscripts(store as Store);
if (migrated) {
let needsSave = false;

if (migrateWordsAndHintsToTranscripts(store as Store)) {
needsSave = true;
}

if (deleteSessionsFromSqlite(store as Store)) {
needsSave = true;
}

if (needsSave) {
await persister.save();
}
}
Expand Down
Loading