Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Init workspace database create on workspace create event

Hakan Shehu2d693d06c6b9
diff --git a/apps/desktop/src/main/data/database-service.ts b/apps/desktop/src/main/data/database-service.ts
index 6fbc6b48..828982c3 100644
--- a/apps/desktop/src/main/data/database-service.ts
+++ b/apps/desktop/src/main/data/database-service.ts
@@ -6,6 +6,7 @@ import { appDatabaseMigrations } from '@/main/data/app/migrations';
import { workspaceDatabaseMigrations } from '@/main/data/workspace/migrations';
import { appDatabasePath, getWorkspaceDirectoryPath } from '@/main/utils';
import SQLite from 'better-sqlite3';
+import { eventBus } from '@/shared/lib/event-bus';
class DatabaseService {
private initPromise: Promise<void> | null = null;
@@ -22,6 +23,12 @@ class DatabaseService {
});
this.appDatabase = new Kysely<AppDatabaseSchema>({ dialect });
+
+ eventBus.subscribe((event) => {
+ if (event.type === 'workspace_created') {
+ this.initWorkspaceDatabase(event.workspace.userId);
+ }
+ });
}
public async init(): Promise<void> {
diff --git a/apps/desktop/src/main/queries/workspace-get.ts b/apps/desktop/src/main/queries/workspace-get.ts
index e697ee71..7a145239 100644
--- a/apps/desktop/src/main/queries/workspace-get.ts
+++ b/apps/desktop/src/main/queries/workspace-get.ts
@@ -23,7 +23,7 @@ export class WorkspaceGetQueryHandler
public async checkForChanges(
event: Event,
input: WorkspaceGetQueryInput,
- output: Workspace | null
+ _: Workspace | null
): Promise<ChangeCheckResult<WorkspaceGetQueryInput>> {
if (
event.type === 'workspace_created' &&