Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(core): find lost data (#4035)

Alex Yang02bd9fc2d1b2
diff --git a/apps/electron/src/helper/db/base-db-adapter.ts b/apps/electron/src/helper/db/base-db-adapter.ts
index 7d90c8a0bb..44f5669b88 100644
--- a/apps/electron/src/helper/db/base-db-adapter.ts
+++ b/apps/electron/src/helper/db/base-db-adapter.ts
@@ -1,5 +1,10 @@
-import { type InsertRow, SqliteConnection } from '@affine/native';
+import {
+ type InsertRow,
+ SqliteConnection,
+ ValidationResult,
+} from '@affine/native';
+import { migrateToLatestDatabase } from '../db/migration';
import { logger } from '../logger';
/**
@@ -13,6 +18,10 @@ export abstract class BaseSQLiteAdapter {
async connectIfNeeded() {
if (!this.db) {
+ const validation = await SqliteConnection.validate(this.path);
+ if (validation === ValidationResult.MissingVersionColumn) {
+ await migrateToLatestDatabase(this.path);
+ }
this.db = new SqliteConnection(this.path);
await this.db.connect();
logger.info(`[SQLiteAdapter:${this.role}]`, 'connected:', this.path);
diff --git a/packages/workspace/src/local/crud.ts b/packages/workspace/src/local/crud.ts
index 498a0837f8..9594eaa30c 100644
--- a/packages/workspace/src/local/crud.ts
+++ b/packages/workspace/src/local/crud.ts
@@ -98,10 +98,17 @@ export const CRUD: WorkspaceCRUD<WorkspaceFlavour.LOCAL> = {
list: async () => {
logger.debug('list');
const storage = getStorage();
- const allWorkspaceIDs: string[] = storage.getItem(kStoreKey, []) as z.infer<
+ let allWorkspaceIDs: string[] = storage.getItem(kStoreKey, []) as z.infer<
typeof schema
>;
+ // fixme: remove this once desktop data migration is done
+ if (window.apis && environment.isDesktop) {
+ const desktopIds = (await window.apis.workspace.list()).map(v => v[0]);
+ allWorkspaceIDs = [...new Set([...allWorkspaceIDs, ...desktopIds])];
+ storage.setItem(kStoreKey, allWorkspaceIDs);
+ }
+
const workspaces = (
await Promise.all(allWorkspaceIDs.map(id => CRUD.get(id)))
).filter(item => item !== null) as LocalWorkspace[];