Skip to content

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

Add indexes in node_paths and users tables

Hakan Shehubab5df2000b6
diff --git a/apps/server/src/data/migrations/00015-create-node-paths-indexes.ts b/apps/server/src/data/migrations/00015-create-node-paths-indexes.ts
new file mode 100644
index 00000000..29578124
--- /dev/null
+++ b/apps/server/src/data/migrations/00015-create-node-paths-indexes.ts
@@ -0,0 +1,21 @@
+import { Migration } from 'kysely';
+
+export const createNodePathsIndexes: Migration = {
+ up: async (db) => {
+ await db.schema
+ .createIndex('node_paths_ancestor_id_idx')
+ .on('node_paths')
+ .column('ancestor_id')
+ .execute();
+
+ await db.schema
+ .createIndex('node_paths_descendant_id_idx')
+ .on('node_paths')
+ .column('descendant_id')
+ .execute();
+ },
+ down: async (db) => {
+ await db.schema.dropIndex('node_paths_ancestor_id_idx').execute();
+ await db.schema.dropIndex('node_paths_descendant_id_idx').execute();
+ },
+};
diff --git a/apps/server/src/data/migrations/00016-create-user-account-id-index.ts b/apps/server/src/data/migrations/00016-create-user-account-id-index.ts
new file mode 100644
index 00000000..a986d637
--- /dev/null
+++ b/apps/server/src/data/migrations/00016-create-user-account-id-index.ts
@@ -0,0 +1,14 @@
+import { Migration } from 'kysely';
+
+export const createUserAccountIdIndex: Migration = {
+ up: async (db) => {
+ await db.schema
+ .createIndex('users_account_id_idx')
+ .on('users')
+ .columns(['account_id'])
+ .execute();
+ },
+ down: async (db) => {
+ await db.schema.dropIndex('users_account_id_idx').execute();
+ },
+};
diff --git a/apps/server/src/data/migrations/index.ts b/apps/server/src/data/migrations/index.ts
index 46f2281d..72364052 100644
--- a/apps/server/src/data/migrations/index.ts
+++ b/apps/server/src/data/migrations/index.ts
@@ -14,6 +14,8 @@ import { createCollaborationsTable } from './00011-create-collaborations-table';
import { createDocumentsTable } from './00012-create-documents-table';
import { createDocumentUpdatesTable } from './00013-create-document-updates-table';
import { createUploadsTable } from './00014-create-uploads-table';
+import { createNodePathsIndexes } from './00015-create-node-paths-indexes';
+import { createUserAccountIdIndex } from './00016-create-user-account-id-index';
export const databaseMigrations: Record<string, Migration> = {
'00001_create_accounts_table': createAccountsTable,
@@ -30,4 +32,6 @@ export const databaseMigrations: Record<string, Migration> = {
'00012_create_documents_table': createDocumentsTable,
'00013_create_document_updates_table': createDocumentUpdatesTable,
'00014_create_uploads_table': createUploadsTable,
+ '00015_create_node_paths_indexes': createNodePathsIndexes,
+ '00016_create_user_account_id_index': createUserAccountIdIndex,
};