Open-source and local-first Slack and Notion alternative that puts you in control of your data
TypeScript chatchat-applicationcrdteditorelectronknowledge-baselocal-firstnotionnotion-alternativerealtime-collaborationself-hostedslacksqliteteam-collaborationwikiyjs
Add some extra columns in desktop tables
Hakan Shehu89c3969b72a1
diff --git a/apps/desktop/src/main/databases/account/migrations/00001-create-workspaces-table.ts b/apps/desktop/src/main/databases/account/migrations/00001-create-workspaces-table.tsindex 3dbe7f37..aaa2f525 100644--- a/apps/desktop/src/main/databases/account/migrations/00001-create-workspaces-table.ts+++ b/apps/desktop/src/main/databases/account/migrations/00001-create-workspaces-table.ts@@ -11,6 +11,9 @@ export const createWorkspacesTable: Migration = {.addColumn('description', 'text').addColumn('avatar', 'text').addColumn('role', 'text', (col) => col.notNull())+ .addColumn('storage_limit', 'integer', (col) => col.notNull())+ .addColumn('max_file_size', 'integer', (col) => col.notNull())+ .addColumn('created_at', 'text', (col) => col.notNull()).execute();},down: async (db) => {diff --git a/apps/desktop/src/main/databases/account/schema.ts b/apps/desktop/src/main/databases/account/schema.tsindex 804250f4..1349e71c 100644--- a/apps/desktop/src/main/databases/account/schema.ts+++ b/apps/desktop/src/main/databases/account/schema.ts@@ -9,6 +9,9 @@ interface WorkspaceTable {description: ColumnType<string | null, string | null, string | null>;avatar: ColumnType<string | null, string | null, string | null>;role: ColumnType<WorkspaceRole, WorkspaceRole, WorkspaceRole>;+ storage_limit: ColumnType<bigint, bigint, bigint>;+ max_file_size: ColumnType<bigint, bigint, bigint>;+ created_at: ColumnType<string, string, never>;}export type SelectWorkspace = Selectable<WorkspaceTable>;diff --git a/apps/desktop/src/main/databases/app/migrations/00001-create-servers-table.ts b/apps/desktop/src/main/databases/app/migrations/00001-create-servers-table.tsindex 765254aa..fd739802 100644--- a/apps/desktop/src/main/databases/app/migrations/00001-create-servers-table.ts+++ b/apps/desktop/src/main/databases/app/migrations/00001-create-servers-table.ts@@ -10,7 +10,7 @@ export const createServersTable: Migration = {.addColumn('attributes', 'text', (col) => col.notNull()).addColumn('version', 'text', (col) => col.notNull()).addColumn('created_at', 'text', (col) => col.notNull())- .addColumn('last_synced_at', 'text')+ .addColumn('synced_at', 'text').execute();await dbdiff --git a/apps/desktop/src/main/databases/app/migrations/00002-create-accounts-table.ts b/apps/desktop/src/main/databases/app/migrations/00002-create-accounts-table.tsindex 34d78c72..97e2c6e0 100644--- a/apps/desktop/src/main/databases/app/migrations/00002-create-accounts-table.ts+++ b/apps/desktop/src/main/databases/app/migrations/00002-create-accounts-table.ts@@ -11,6 +11,9 @@ export const createAccountsTable: Migration = {.addColumn('email', 'text', (col) => col.notNull()).addColumn('avatar', 'text').addColumn('token', 'text', (col) => col.notNull())+ .addColumn('created_at', 'text', (col) => col.notNull())+ .addColumn('updated_at', 'text')+ .addColumn('synced_at', 'text').execute();},down: async (db) => {diff --git a/apps/desktop/src/main/databases/app/schema.ts b/apps/desktop/src/main/databases/app/schema.tsindex c4bd73d4..e9401059 100644--- a/apps/desktop/src/main/databases/app/schema.ts+++ b/apps/desktop/src/main/databases/app/schema.ts@@ -7,7 +7,7 @@ interface ServerTable {attributes: ColumnType<string, string, string>;version: ColumnType<string, string, string>;created_at: ColumnType<string, string, string>;- last_synced_at: ColumnType<string | null, string | null, string>;+ synced_at: ColumnType<string | null, string | null, string>;}export type SelectServer = Selectable<ServerTable>;@@ -22,6 +22,9 @@ interface AccountTable {avatar: ColumnType<string | null, string | null, string | null>;token: ColumnType<string, string, string>;device_id: ColumnType<string, string, never>;+ created_at: ColumnType<string, string, string>;+ updated_at: ColumnType<string | null, string | null, string | null>;+ synced_at: ColumnType<string | null, string | null, string | null>;}export type SelectAccount = Selectable<AccountTable>;diff --git a/apps/desktop/src/main/mutations/accounts/account-update.ts b/apps/desktop/src/main/mutations/accounts/account-update.tsindex a077fc3f..e81986ad 100644--- a/apps/desktop/src/main/mutations/accounts/account-update.ts+++ b/apps/desktop/src/main/mutations/accounts/account-update.ts@@ -40,6 +40,7 @@ export class AccountUpdateMutationHandler.set({name: data.name,avatar: data.avatar,+ updated_at: new Date().toISOString(),}).where('id', '=', input.id).returningAll()diff --git a/apps/desktop/src/main/mutations/accounts/base.ts b/apps/desktop/src/main/mutations/accounts/base.tsindex e73e561f..734e6f91 100644--- a/apps/desktop/src/main/mutations/accounts/base.ts+++ b/apps/desktop/src/main/mutations/accounts/base.ts@@ -22,6 +22,7 @@ export abstract class AccountMutationHandlerBase {token: login.token,device_id: login.deviceId,avatar: login.account.avatar,+ created_at: new Date().toISOString(),}).executeTakeFirst();@@ -54,8 +55,11 @@ export abstract class AccountMutationHandlerBase {user_id: workspace.user.id,account_id: account.id,role: workspace.user.role,+ storage_limit: workspace.user.storageLimit,+ max_file_size: workspace.user.maxFileSize,avatar: workspace.avatar,description: workspace.description,+ created_at: new Date().toISOString(),}).executeTakeFirst();diff --git a/apps/desktop/src/main/mutations/workspaces/workspace-create.ts b/apps/desktop/src/main/mutations/workspaces/workspace-create.tsindex 8632ea0e..c56f46fe 100644--- a/apps/desktop/src/main/mutations/workspaces/workspace-create.ts+++ b/apps/desktop/src/main/mutations/workspaces/workspace-create.ts@@ -46,7 +46,10 @@ export class WorkspaceCreateMutationHandlerdescription: data.description,avatar: data.avatar,role: data.user.role,+ storage_limit: data.user.storageLimit,+ max_file_size: data.user.maxFileSize,user_id: data.user.id,+ created_at: new Date().toISOString(),}).onConflict((cb) => cb.doNothing()).executeTakeFirst();diff --git a/apps/desktop/src/main/queries/servers/server-list.ts b/apps/desktop/src/main/queries/servers/server-list.tsindex 8b1231a3..827bbf8e 100644--- a/apps/desktop/src/main/queries/servers/server-list.ts+++ b/apps/desktop/src/main/queries/servers/server-list.ts@@ -52,7 +52,7 @@ export class ServerListQueryHandlerattributes: JSON.parse(row.attributes),version: row.version,createdAt: new Date(row.created_at),- lastSyncedAt: row.last_synced_at ? new Date(row.last_synced_at) : null,+ syncedAt: row.synced_at ? new Date(row.synced_at) : null,};});};diff --git a/apps/desktop/src/main/services/accounts/account-service.ts b/apps/desktop/src/main/services/accounts/account-service.tsindex 6b5f6eef..6ed3dbf7 100644--- a/apps/desktop/src/main/services/accounts/account-service.ts+++ b/apps/desktop/src/main/services/accounts/account-service.ts@@ -250,12 +250,20 @@ export class AccountService {});+ const hasChanges =+ data.account.name !== this.account.name ||+ data.account.avatar !== this.account.avatar;+const updatedAccount = await this.app.database.updateTable('accounts').returningAll().set({name: data.account.name,avatar: data.account.avatar,+ updated_at: hasChanges+ ? new Date().toISOString()+ : this.account.updatedAt,+ synced_at: new Date().toISOString(),}).where('id', '=', this.account.id).executeTakeFirst();@@ -289,6 +297,9 @@ export class AccountService {description: workspace.description,avatar: workspace.avatar,role: workspace.user.role,+ storage_limit: workspace.user.storageLimit,+ max_file_size: workspace.user.maxFileSize,+ created_at: new Date().toISOString(),}).executeTakeFirst();@@ -313,6 +324,8 @@ export class AccountService {description: workspace.description,avatar: workspace.avatar,role: workspace.user.role,+ storage_limit: workspace.user.storageLimit,+ max_file_size: workspace.user.maxFileSize,}).where('id', '=', workspace.id).executeTakeFirst();diff --git a/apps/desktop/src/main/services/server-service.ts b/apps/desktop/src/main/services/server-service.tsindex 2c000480..fa66a60f 100644--- a/apps/desktop/src/main/services/server-service.ts+++ b/apps/desktop/src/main/services/server-service.ts@@ -78,7 +78,7 @@ export class ServerService {.updateTable('servers').returningAll().set({- last_synced_at: new Date().toISOString(),+ synced_at: new Date().toISOString(),attributes: JSON.stringify(config.attributes),avatar: config.avatar,name: config.name,diff --git a/apps/desktop/src/main/utils.ts b/apps/desktop/src/main/utils.tsindex 04c67a9e..004acf64 100644--- a/apps/desktop/src/main/utils.ts+++ b/apps/desktop/src/main/utils.ts@@ -245,6 +245,9 @@ export const mapAccount = (row: SelectAccount): Account => {deviceId: row.device_id,email: row.email,token: row.token,+ createdAt: row.created_at,+ updatedAt: row.updated_at,+ syncedAt: row.synced_at,};};@@ -318,7 +321,7 @@ export const mapServer = (row: SelectServer): Server => {attributes: JSON.parse(row.attributes),version: row.version,createdAt: new Date(row.created_at),- lastSyncedAt: row.last_synced_at ? new Date(row.last_synced_at) : null,+ syncedAt: row.synced_at ? new Date(row.synced_at) : null,};};diff --git a/apps/desktop/src/shared/types/accounts.ts b/apps/desktop/src/shared/types/accounts.tsindex 1b913a1c..575ea4b1 100644--- a/apps/desktop/src/shared/types/accounts.ts+++ b/apps/desktop/src/shared/types/accounts.ts@@ -6,4 +6,7 @@ export type Account = {token: string;deviceId: string;server: string;+ createdAt: string;+ updatedAt: string | null;+ syncedAt: string | null;};diff --git a/apps/desktop/src/shared/types/servers.ts b/apps/desktop/src/shared/types/servers.tsindex 9d036b76..90b27fc2 100644--- a/apps/desktop/src/shared/types/servers.ts+++ b/apps/desktop/src/shared/types/servers.ts@@ -7,5 +7,5 @@ export type Server = {attributes: ServerAttributes;version: string;createdAt: Date;- lastSyncedAt: Date | null;+ syncedAt: Date | null;};diff --git a/apps/server/src/controllers/client/accounts/account-sync.ts b/apps/server/src/controllers/client/accounts/account-sync.tsindex 4211d0b0..4fc66f1f 100644--- a/apps/server/src/controllers/client/accounts/account-sync.ts+++ b/apps/server/src/controllers/client/accounts/account-sync.ts@@ -84,6 +84,8 @@ export const accountSyncHandler = async (id: user.id,accountId: user.account_id,role: user.role as WorkspaceRole,+ storageLimit: user.storage_limit,+ maxFileSize: user.max_file_size,},});}diff --git a/apps/server/src/controllers/client/workspaces/workspace-get.ts b/apps/server/src/controllers/client/workspaces/workspace-get.tsindex e871988b..b1140415 100644--- a/apps/server/src/controllers/client/workspaces/workspace-get.ts+++ b/apps/server/src/controllers/client/workspaces/workspace-get.ts@@ -46,6 +46,8 @@ export const workspaceGetHandler = async (id: user.id,accountId: user.account_id,role: user.role as WorkspaceRole,+ storageLimit: user.storage_limit,+ maxFileSize: user.max_file_size,},};diff --git a/apps/server/src/controllers/client/workspaces/workspace-update.ts b/apps/server/src/controllers/client/workspaces/workspace-update.tsindex 3b67cf38..459718dd 100644--- a/apps/server/src/controllers/client/workspaces/workspace-update.ts+++ b/apps/server/src/controllers/client/workspaces/workspace-update.ts@@ -58,6 +58,8 @@ export const workspaceUpdateHandler = async (id: res.locals.user.id,accountId: res.locals.user.account_id,role: res.locals.user.role,+ storageLimit: res.locals.user.storage_limit,+ maxFileSize: res.locals.user.max_file_size,},};diff --git a/apps/server/src/services/account-service.ts b/apps/server/src/services/account-service.tsindex 01766a71..1ce3dfc1 100644--- a/apps/server/src/services/account-service.ts+++ b/apps/server/src/services/account-service.ts@@ -65,6 +65,8 @@ class AccountService {id: user.id,accountId: user.account_id,role: user.role as WorkspaceRole,+ storageLimit: user.storage_limit,+ maxFileSize: user.max_file_size,},});}diff --git a/apps/server/src/services/workspace-service.ts b/apps/server/src/services/workspace-service.tsindex 5bcf7aed..1c2a58db 100644--- a/apps/server/src/services/workspace-service.ts+++ b/apps/server/src/services/workspace-service.ts@@ -132,6 +132,8 @@ class WorkspaceService {id: user.id,accountId: user.account_id,role: user.role,+ storageLimit: user.storage_limit,+ maxFileSize: user.max_file_size,},};}diff --git a/packages/core/src/types/workspaces.ts b/packages/core/src/types/workspaces.tsindex c70d8195..7c6ff9cb 100644--- a/packages/core/src/types/workspaces.ts+++ b/packages/core/src/types/workspaces.ts@@ -35,6 +35,8 @@ export type WorkspaceUserOutput = {id: string;accountId: string;role: WorkspaceRole;+ storageLimit: bigint;+ maxFileSize: bigint;};export type WorkspaceUpdateInput = {