From 4d79badc2dc69586991eec15d6c3a9c65bf2d453 Mon Sep 17 00:00:00 2001
From: eikek <eike.kettner@posteo.de>
Date: Sat, 11 Jun 2022 12:40:16 +0200
Subject: [PATCH 1/3] Fix logging warn->debug

---
 .../scala/docspell/backend/auth/AuthTokenTest.scala | 13 +++++++++++++
 .../docspell/restserver/routes/ItemSearchPart.scala |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/modules/backend/src/test/scala/docspell/backend/auth/AuthTokenTest.scala b/modules/backend/src/test/scala/docspell/backend/auth/AuthTokenTest.scala
index 97cc7b78..10aa99f1 100644
--- a/modules/backend/src/test/scala/docspell/backend/auth/AuthTokenTest.scala
+++ b/modules/backend/src/test/scala/docspell/backend/auth/AuthTokenTest.scala
@@ -34,4 +34,17 @@ class AuthTokenTest extends CatsEffectSuite {
       !token2.copy(valid = Duration.minutes(10).some).validate(secret, Duration.millis(0))
     )
   }
+
+  test("signature") {
+    val token1 = AuthToken.user[IO](user, false, secret, None).unsafeRunSync()
+    val token2 =
+      AuthToken.user[IO](user, false, secret, Duration.seconds(10).some).unsafeRunSync()
+
+    assert(token1.sigValid(secret))
+    assert(token1.sigInvalid(otherSecret))
+    assert(token1.copy(valid = Duration.seconds(100).some).sigInvalid(secret))
+
+    assert(token2.sigValid(secret))
+    assert(token2.sigInvalid(otherSecret))
+  }
 }
diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/ItemSearchPart.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/ItemSearchPart.scala
index 00775d94..12aec359 100644
--- a/modules/restserver/src/main/scala/docspell/restserver/routes/ItemSearchPart.scala
+++ b/modules/restserver/src/main/scala/docspell/restserver/routes/ItemSearchPart.scala
@@ -108,7 +108,7 @@ final class ItemSearchPart[F[_]: Async](
         identity,
         res =>
           for {
-            _ <- logger.warn(s"Searching with query: $res")
+            _ <- logger.debug(s"Searching with query: $res")
             items <- searchOps
               .searchSelect(details, cfg.maxNoteLength, today.some, batch)(
                 res.q,

From 1611df81edaf83144b95fc61bf0ca3963a5cc09b Mon Sep 17 00:00:00 2001
From: eikek <eike.kettner@posteo.de>
Date: Sat, 11 Jun 2022 12:40:31 +0200
Subject: [PATCH 2/3] Add more indexes

---
 .../db/migration/h2/V1.38.0__more_indexes.sql | 79 +++++++++++++++++++
 .../mariadb/V1.38.0__more_indexes.sql         | 79 +++++++++++++++++++
 .../postgresql/V1.38.0__more_indexes.sql      | 79 +++++++++++++++++++
 3 files changed, 237 insertions(+)
 create mode 100644 modules/store/src/main/resources/db/migration/h2/V1.38.0__more_indexes.sql
 create mode 100644 modules/store/src/main/resources/db/migration/mariadb/V1.38.0__more_indexes.sql
 create mode 100644 modules/store/src/main/resources/db/migration/postgresql/V1.38.0__more_indexes.sql

diff --git a/modules/store/src/main/resources/db/migration/h2/V1.38.0__more_indexes.sql b/modules/store/src/main/resources/db/migration/h2/V1.38.0__more_indexes.sql
new file mode 100644
index 00000000..39032bad
--- /dev/null
+++ b/modules/store/src/main/resources/db/migration/h2/V1.38.0__more_indexes.sql
@@ -0,0 +1,79 @@
+create index if not exists addon_archive_cid_idx on addon_archive(cid);
+create index if not exists addon_archive_file_id_idx on addon_archive(file_id);
+create index if not exists addon_run_config_cid_idx on addon_run_config(cid);
+create index if not exists addon_run_config_user_id_idx on addon_run_config(user_id);
+create index if not exists addon_run_config_addon_addon_id_idx on addon_run_config_addon(addon_id);
+create index if not exists addon_run_config_addon_addon_run_config_id_idx on addon_run_config_addon(addon_run_config_id);
+create index if not exists addon_run_config_trigger_addon_run_config_id_idx on addon_run_config_trigger(addon_run_config_id);
+create index if not exists attachment_filemetaid_idx on attachment(filemetaid);
+create index if not exists attachment_itemid_idx on attachment(itemid);
+create index if not exists attachment_archive_id_idx on attachment_archive(id);
+create index if not exists attachment_archive_file_id_idx on attachment_archive(file_id);
+create index if not exists attachment_preview_id_idx on attachment_preview(id);
+create index if not exists attachment_preview_file_id_idx on attachment_preview(file_id);
+create index if not exists attachment_source_id_idx on attachment_source(id);
+create index if not exists attachment_source_file_id_idx on attachment_source(file_id);
+create index if not exists attachmentmeta_attachid_idx on attachmentmeta(attachid);
+create index if not exists classifier_model_cid_idx on classifier_model(cid);
+create index if not exists classifier_model_file_id_idx on classifier_model(file_id);
+create index if not exists classifier_setting_cid_idx on classifier_setting(cid);
+create index if not exists client_settings_collective_cid_idx on client_settings_collective(cid);
+create index if not exists client_settings_user_id_idx on client_settings_user(user_id);
+create index if not exists collective_password_cid_idx on collective_password(cid);
+create index if not exists contact_oid_idx on contact(oid);
+create index if not exists contact_pid_idx on contact(pid);
+create index if not exists custom_field_cid_idx on custom_field(cid);
+create index if not exists custom_field_value_field_idx on custom_field_value(field);
+create index if not exists custom_field_value_item_id_idx on custom_field_value(item_id);
+create index if not exists download_query_cid_idx on download_query(cid);
+create index if not exists download_query_file_id_idx on download_query(file_id);
+create index if not exists empty_trash_setting_cid_idx on empty_trash_setting(cid);
+create index if not exists equipment_cid_idx on equipment(cid);
+create index if not exists folder_cid_idx on folder(cid);
+create index if not exists folder_owner_idx on folder(owner);
+create index if not exists folder_member_folder_id_idx on folder_member(folder_id);
+create index if not exists folder_member_user_id_idx on folder_member(user_id);
+create index if not exists item_cid_idx on item(cid);
+create index if not exists item_concequipment_idx on item(concequipment);
+create index if not exists item_folder_id_idx on item(folder_id);
+create index if not exists item_corrorg_idx on item(corrorg);
+create index if not exists item_concperson_idx on item(concperson);
+create index if not exists item_corrperson_idx on item(corrperson);
+create index if not exists item_link_cid_idx on item_link(cid);
+create index if not exists item_link_item1_idx on item_link(item1);
+create index if not exists item_link_item2_idx on item_link(item2);
+create index if not exists item_proposal_itemid_idx on item_proposal(itemid);
+create index if not exists item_share_user_id_idx on item_share(user_id);
+create index if not exists joblog_jid_idx on joblog(jid);
+create index if not exists notification_channel_gotify_uid_idx on notification_channel_gotify(uid);
+create index if not exists notification_channel_http_uid_idx on notification_channel_http(uid);
+create index if not exists notification_channel_mail_uid_idx on notification_channel_mail(uid);
+create index if not exists notification_channel_mail_conn_id_idx on notification_channel_mail(conn_id);
+create index if not exists notification_channel_matrix_uid_idx on notification_channel_matrix(uid);
+create index if not exists notification_hook_uid_idx on notification_hook(uid);
+create index if not exists notification_hook_channel_channel_gotify_idx on notification_hook_channel(channel_gotify);
+create index if not exists notification_hook_channel_channel_http_idx on notification_hook_channel(channel_http);
+create index if not exists notification_hook_channel_channel_mail_idx on notification_hook_channel(channel_mail);
+create index if not exists notification_hook_channel_channel_matrix_idx on notification_hook_channel(channel_matrix);
+create index if not exists notification_hook_channel_hook_id_idx on notification_hook_channel(hook_id);
+create index if not exists notification_hook_event_hook_id_idx on notification_hook_event(hook_id);
+create index if not exists organization_cid_idx on organization(cid);
+create index if not exists person_cid_idx on person(cid);
+create index if not exists fk_person_organization on person(oid);
+create index if not exists query_bookmark_cid_idx on query_bookmark(cid);
+create index if not exists query_bookmark_user_id_idx on query_bookmark(user_id);
+create index if not exists rememberme_cid_login_idx on rememberme(cid, login);
+create index if not exists sentmail_uid_idx on sentmail(uid);
+create index if not exists sentmailitem_item_id_idx on sentmailitem(item_id);
+create index if not exists sentmailitem_sentmail_id_idx on sentmailitem(sentmail_id);
+create index if not exists source_cid_idx on source(cid);
+create index if not exists source_folder_id_idx on source(folder_id);
+create index if not exists tag_cid_idx on tag(cid);
+create index if not exists tagitem_itemid_idx on tagitem(itemid);
+create index if not exists tagitem_tid_idx on tagitem(tid);
+create index if not exists tagsource_source_id_idx on tagsource(source_id);
+create index if not exists tagsource_tag_id_idx on tagsource(tag_id);
+create index if not exists totp_user_id_idx on totp(user_id);
+create index if not exists user__cid_idx on user_(cid);
+create index if not exists useremail_uid_idx on useremail(uid);
+create index if not exists userimap_uid_idx on userimap(uid);
diff --git a/modules/store/src/main/resources/db/migration/mariadb/V1.38.0__more_indexes.sql b/modules/store/src/main/resources/db/migration/mariadb/V1.38.0__more_indexes.sql
new file mode 100644
index 00000000..39032bad
--- /dev/null
+++ b/modules/store/src/main/resources/db/migration/mariadb/V1.38.0__more_indexes.sql
@@ -0,0 +1,79 @@
+create index if not exists addon_archive_cid_idx on addon_archive(cid);
+create index if not exists addon_archive_file_id_idx on addon_archive(file_id);
+create index if not exists addon_run_config_cid_idx on addon_run_config(cid);
+create index if not exists addon_run_config_user_id_idx on addon_run_config(user_id);
+create index if not exists addon_run_config_addon_addon_id_idx on addon_run_config_addon(addon_id);
+create index if not exists addon_run_config_addon_addon_run_config_id_idx on addon_run_config_addon(addon_run_config_id);
+create index if not exists addon_run_config_trigger_addon_run_config_id_idx on addon_run_config_trigger(addon_run_config_id);
+create index if not exists attachment_filemetaid_idx on attachment(filemetaid);
+create index if not exists attachment_itemid_idx on attachment(itemid);
+create index if not exists attachment_archive_id_idx on attachment_archive(id);
+create index if not exists attachment_archive_file_id_idx on attachment_archive(file_id);
+create index if not exists attachment_preview_id_idx on attachment_preview(id);
+create index if not exists attachment_preview_file_id_idx on attachment_preview(file_id);
+create index if not exists attachment_source_id_idx on attachment_source(id);
+create index if not exists attachment_source_file_id_idx on attachment_source(file_id);
+create index if not exists attachmentmeta_attachid_idx on attachmentmeta(attachid);
+create index if not exists classifier_model_cid_idx on classifier_model(cid);
+create index if not exists classifier_model_file_id_idx on classifier_model(file_id);
+create index if not exists classifier_setting_cid_idx on classifier_setting(cid);
+create index if not exists client_settings_collective_cid_idx on client_settings_collective(cid);
+create index if not exists client_settings_user_id_idx on client_settings_user(user_id);
+create index if not exists collective_password_cid_idx on collective_password(cid);
+create index if not exists contact_oid_idx on contact(oid);
+create index if not exists contact_pid_idx on contact(pid);
+create index if not exists custom_field_cid_idx on custom_field(cid);
+create index if not exists custom_field_value_field_idx on custom_field_value(field);
+create index if not exists custom_field_value_item_id_idx on custom_field_value(item_id);
+create index if not exists download_query_cid_idx on download_query(cid);
+create index if not exists download_query_file_id_idx on download_query(file_id);
+create index if not exists empty_trash_setting_cid_idx on empty_trash_setting(cid);
+create index if not exists equipment_cid_idx on equipment(cid);
+create index if not exists folder_cid_idx on folder(cid);
+create index if not exists folder_owner_idx on folder(owner);
+create index if not exists folder_member_folder_id_idx on folder_member(folder_id);
+create index if not exists folder_member_user_id_idx on folder_member(user_id);
+create index if not exists item_cid_idx on item(cid);
+create index if not exists item_concequipment_idx on item(concequipment);
+create index if not exists item_folder_id_idx on item(folder_id);
+create index if not exists item_corrorg_idx on item(corrorg);
+create index if not exists item_concperson_idx on item(concperson);
+create index if not exists item_corrperson_idx on item(corrperson);
+create index if not exists item_link_cid_idx on item_link(cid);
+create index if not exists item_link_item1_idx on item_link(item1);
+create index if not exists item_link_item2_idx on item_link(item2);
+create index if not exists item_proposal_itemid_idx on item_proposal(itemid);
+create index if not exists item_share_user_id_idx on item_share(user_id);
+create index if not exists joblog_jid_idx on joblog(jid);
+create index if not exists notification_channel_gotify_uid_idx on notification_channel_gotify(uid);
+create index if not exists notification_channel_http_uid_idx on notification_channel_http(uid);
+create index if not exists notification_channel_mail_uid_idx on notification_channel_mail(uid);
+create index if not exists notification_channel_mail_conn_id_idx on notification_channel_mail(conn_id);
+create index if not exists notification_channel_matrix_uid_idx on notification_channel_matrix(uid);
+create index if not exists notification_hook_uid_idx on notification_hook(uid);
+create index if not exists notification_hook_channel_channel_gotify_idx on notification_hook_channel(channel_gotify);
+create index if not exists notification_hook_channel_channel_http_idx on notification_hook_channel(channel_http);
+create index if not exists notification_hook_channel_channel_mail_idx on notification_hook_channel(channel_mail);
+create index if not exists notification_hook_channel_channel_matrix_idx on notification_hook_channel(channel_matrix);
+create index if not exists notification_hook_channel_hook_id_idx on notification_hook_channel(hook_id);
+create index if not exists notification_hook_event_hook_id_idx on notification_hook_event(hook_id);
+create index if not exists organization_cid_idx on organization(cid);
+create index if not exists person_cid_idx on person(cid);
+create index if not exists fk_person_organization on person(oid);
+create index if not exists query_bookmark_cid_idx on query_bookmark(cid);
+create index if not exists query_bookmark_user_id_idx on query_bookmark(user_id);
+create index if not exists rememberme_cid_login_idx on rememberme(cid, login);
+create index if not exists sentmail_uid_idx on sentmail(uid);
+create index if not exists sentmailitem_item_id_idx on sentmailitem(item_id);
+create index if not exists sentmailitem_sentmail_id_idx on sentmailitem(sentmail_id);
+create index if not exists source_cid_idx on source(cid);
+create index if not exists source_folder_id_idx on source(folder_id);
+create index if not exists tag_cid_idx on tag(cid);
+create index if not exists tagitem_itemid_idx on tagitem(itemid);
+create index if not exists tagitem_tid_idx on tagitem(tid);
+create index if not exists tagsource_source_id_idx on tagsource(source_id);
+create index if not exists tagsource_tag_id_idx on tagsource(tag_id);
+create index if not exists totp_user_id_idx on totp(user_id);
+create index if not exists user__cid_idx on user_(cid);
+create index if not exists useremail_uid_idx on useremail(uid);
+create index if not exists userimap_uid_idx on userimap(uid);
diff --git a/modules/store/src/main/resources/db/migration/postgresql/V1.38.0__more_indexes.sql b/modules/store/src/main/resources/db/migration/postgresql/V1.38.0__more_indexes.sql
new file mode 100644
index 00000000..39032bad
--- /dev/null
+++ b/modules/store/src/main/resources/db/migration/postgresql/V1.38.0__more_indexes.sql
@@ -0,0 +1,79 @@
+create index if not exists addon_archive_cid_idx on addon_archive(cid);
+create index if not exists addon_archive_file_id_idx on addon_archive(file_id);
+create index if not exists addon_run_config_cid_idx on addon_run_config(cid);
+create index if not exists addon_run_config_user_id_idx on addon_run_config(user_id);
+create index if not exists addon_run_config_addon_addon_id_idx on addon_run_config_addon(addon_id);
+create index if not exists addon_run_config_addon_addon_run_config_id_idx on addon_run_config_addon(addon_run_config_id);
+create index if not exists addon_run_config_trigger_addon_run_config_id_idx on addon_run_config_trigger(addon_run_config_id);
+create index if not exists attachment_filemetaid_idx on attachment(filemetaid);
+create index if not exists attachment_itemid_idx on attachment(itemid);
+create index if not exists attachment_archive_id_idx on attachment_archive(id);
+create index if not exists attachment_archive_file_id_idx on attachment_archive(file_id);
+create index if not exists attachment_preview_id_idx on attachment_preview(id);
+create index if not exists attachment_preview_file_id_idx on attachment_preview(file_id);
+create index if not exists attachment_source_id_idx on attachment_source(id);
+create index if not exists attachment_source_file_id_idx on attachment_source(file_id);
+create index if not exists attachmentmeta_attachid_idx on attachmentmeta(attachid);
+create index if not exists classifier_model_cid_idx on classifier_model(cid);
+create index if not exists classifier_model_file_id_idx on classifier_model(file_id);
+create index if not exists classifier_setting_cid_idx on classifier_setting(cid);
+create index if not exists client_settings_collective_cid_idx on client_settings_collective(cid);
+create index if not exists client_settings_user_id_idx on client_settings_user(user_id);
+create index if not exists collective_password_cid_idx on collective_password(cid);
+create index if not exists contact_oid_idx on contact(oid);
+create index if not exists contact_pid_idx on contact(pid);
+create index if not exists custom_field_cid_idx on custom_field(cid);
+create index if not exists custom_field_value_field_idx on custom_field_value(field);
+create index if not exists custom_field_value_item_id_idx on custom_field_value(item_id);
+create index if not exists download_query_cid_idx on download_query(cid);
+create index if not exists download_query_file_id_idx on download_query(file_id);
+create index if not exists empty_trash_setting_cid_idx on empty_trash_setting(cid);
+create index if not exists equipment_cid_idx on equipment(cid);
+create index if not exists folder_cid_idx on folder(cid);
+create index if not exists folder_owner_idx on folder(owner);
+create index if not exists folder_member_folder_id_idx on folder_member(folder_id);
+create index if not exists folder_member_user_id_idx on folder_member(user_id);
+create index if not exists item_cid_idx on item(cid);
+create index if not exists item_concequipment_idx on item(concequipment);
+create index if not exists item_folder_id_idx on item(folder_id);
+create index if not exists item_corrorg_idx on item(corrorg);
+create index if not exists item_concperson_idx on item(concperson);
+create index if not exists item_corrperson_idx on item(corrperson);
+create index if not exists item_link_cid_idx on item_link(cid);
+create index if not exists item_link_item1_idx on item_link(item1);
+create index if not exists item_link_item2_idx on item_link(item2);
+create index if not exists item_proposal_itemid_idx on item_proposal(itemid);
+create index if not exists item_share_user_id_idx on item_share(user_id);
+create index if not exists joblog_jid_idx on joblog(jid);
+create index if not exists notification_channel_gotify_uid_idx on notification_channel_gotify(uid);
+create index if not exists notification_channel_http_uid_idx on notification_channel_http(uid);
+create index if not exists notification_channel_mail_uid_idx on notification_channel_mail(uid);
+create index if not exists notification_channel_mail_conn_id_idx on notification_channel_mail(conn_id);
+create index if not exists notification_channel_matrix_uid_idx on notification_channel_matrix(uid);
+create index if not exists notification_hook_uid_idx on notification_hook(uid);
+create index if not exists notification_hook_channel_channel_gotify_idx on notification_hook_channel(channel_gotify);
+create index if not exists notification_hook_channel_channel_http_idx on notification_hook_channel(channel_http);
+create index if not exists notification_hook_channel_channel_mail_idx on notification_hook_channel(channel_mail);
+create index if not exists notification_hook_channel_channel_matrix_idx on notification_hook_channel(channel_matrix);
+create index if not exists notification_hook_channel_hook_id_idx on notification_hook_channel(hook_id);
+create index if not exists notification_hook_event_hook_id_idx on notification_hook_event(hook_id);
+create index if not exists organization_cid_idx on organization(cid);
+create index if not exists person_cid_idx on person(cid);
+create index if not exists fk_person_organization on person(oid);
+create index if not exists query_bookmark_cid_idx on query_bookmark(cid);
+create index if not exists query_bookmark_user_id_idx on query_bookmark(user_id);
+create index if not exists rememberme_cid_login_idx on rememberme(cid, login);
+create index if not exists sentmail_uid_idx on sentmail(uid);
+create index if not exists sentmailitem_item_id_idx on sentmailitem(item_id);
+create index if not exists sentmailitem_sentmail_id_idx on sentmailitem(sentmail_id);
+create index if not exists source_cid_idx on source(cid);
+create index if not exists source_folder_id_idx on source(folder_id);
+create index if not exists tag_cid_idx on tag(cid);
+create index if not exists tagitem_itemid_idx on tagitem(itemid);
+create index if not exists tagitem_tid_idx on tagitem(tid);
+create index if not exists tagsource_source_id_idx on tagsource(source_id);
+create index if not exists tagsource_tag_id_idx on tagsource(tag_id);
+create index if not exists totp_user_id_idx on totp(user_id);
+create index if not exists user__cid_idx on user_(cid);
+create index if not exists useremail_uid_idx on useremail(uid);
+create index if not exists userimap_uid_idx on userimap(uid);

From aeeb54fcc32fdc6fe40428a21c4ea17d951c9b74 Mon Sep 17 00:00:00 2001
From: eikek <eike.kettner@posteo.de>
Date: Sat, 11 Jun 2022 13:03:14 +0200
Subject: [PATCH 3/3] Remove unused column in item

---
 modules/restapi/src/main/resources/docspell-openapi.yml    | 2 --
 .../main/scala/docspell/restserver/conv/Conversions.scala  | 1 -
 .../db/migration/h2/V1.38.1__remove_unused_column.sql      | 1 +
 .../db/migration/mariadb/V1.38.1__remove_unused_column.sql | 2 ++
 .../migration/postgresql/V1.38.1__remove_unused_column.sql | 1 +
 .../src/main/scala/docspell/store/queries/ItemData.scala   | 1 -
 .../src/main/scala/docspell/store/queries/QItem.scala      | 7 +------
 .../src/main/scala/docspell/store/records/RItem.scala      | 7 +------
 .../src/test/scala/docspell/store/fts/TempFtsOpsTest.scala | 1 -
 9 files changed, 6 insertions(+), 17 deletions(-)
 create mode 100644 modules/store/src/main/resources/db/migration/h2/V1.38.1__remove_unused_column.sql
 create mode 100644 modules/store/src/main/resources/db/migration/mariadb/V1.38.1__remove_unused_column.sql
 create mode 100644 modules/store/src/main/resources/db/migration/postgresql/V1.38.1__remove_unused_column.sql

diff --git a/modules/restapi/src/main/resources/docspell-openapi.yml b/modules/restapi/src/main/resources/docspell-openapi.yml
index 7c03aa4f..2b999c6e 100644
--- a/modules/restapi/src/main/resources/docspell-openapi.yml
+++ b/modules/restapi/src/main/resources/docspell-openapi.yml
@@ -7841,8 +7841,6 @@ components:
           $ref: "#/components/schemas/IdName"
         concEquipment:
           $ref: "#/components/schemas/IdName"
-        inReplyTo:
-          $ref: "#/components/schemas/IdName"
         folder:
           $ref: "#/components/schemas/IdName"
         dueDate:
diff --git a/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala b/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala
index 38bd05da..806b69c8 100644
--- a/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala
+++ b/modules/restserver/src/main/scala/docspell/restserver/conv/Conversions.scala
@@ -136,7 +136,6 @@ trait Conversions {
       data.corrPerson.map(p => IdName(p.pid, p.name)),
       data.concPerson.map(p => IdName(p.pid, p.name)),
       data.concEquip.map(e => IdName(e.eid, e.name)),
-      data.inReplyTo.map(mkIdName),
       data.folder.map(mkIdName),
       data.item.dueDate,
       data.item.notes,
diff --git a/modules/store/src/main/resources/db/migration/h2/V1.38.1__remove_unused_column.sql b/modules/store/src/main/resources/db/migration/h2/V1.38.1__remove_unused_column.sql
new file mode 100644
index 00000000..06c45311
--- /dev/null
+++ b/modules/store/src/main/resources/db/migration/h2/V1.38.1__remove_unused_column.sql
@@ -0,0 +1 @@
+alter table "item" drop column "inreplyto";
diff --git a/modules/store/src/main/resources/db/migration/mariadb/V1.38.1__remove_unused_column.sql b/modules/store/src/main/resources/db/migration/mariadb/V1.38.1__remove_unused_column.sql
new file mode 100644
index 00000000..045a97d0
--- /dev/null
+++ b/modules/store/src/main/resources/db/migration/mariadb/V1.38.1__remove_unused_column.sql
@@ -0,0 +1,2 @@
+alter table `item` drop foreign key item_ibfk_1;
+alter table `item` drop column `inreplyto` cascade;
diff --git a/modules/store/src/main/resources/db/migration/postgresql/V1.38.1__remove_unused_column.sql b/modules/store/src/main/resources/db/migration/postgresql/V1.38.1__remove_unused_column.sql
new file mode 100644
index 00000000..06c45311
--- /dev/null
+++ b/modules/store/src/main/resources/db/migration/postgresql/V1.38.1__remove_unused_column.sql
@@ -0,0 +1 @@
+alter table "item" drop column "inreplyto";
diff --git a/modules/store/src/main/scala/docspell/store/queries/ItemData.scala b/modules/store/src/main/scala/docspell/store/queries/ItemData.scala
index 3ee7c535..ad5028da 100644
--- a/modules/store/src/main/scala/docspell/store/queries/ItemData.scala
+++ b/modules/store/src/main/scala/docspell/store/queries/ItemData.scala
@@ -15,7 +15,6 @@ case class ItemData(
     corrPerson: Option[RPerson],
     concPerson: Option[RPerson],
     concEquip: Option[REquipment],
-    inReplyTo: Option[IdRef],
     folder: Option[IdRef],
     tags: Vector[RTag],
     attachments: Vector[(RAttachment, RFileMeta)],
diff --git a/modules/store/src/main/scala/docspell/store/queries/QItem.scala b/modules/store/src/main/scala/docspell/store/queries/QItem.scala
index 44054354..172d38a9 100644
--- a/modules/store/src/main/scala/docspell/store/queries/QItem.scala
+++ b/modules/store/src/main/scala/docspell/store/queries/QItem.scala
@@ -74,12 +74,9 @@ object QItem extends FtsSupport {
   }
 
   def findItem(id: Ident, collective: Ident): ConnectionIO[Option[ItemData]] = {
-    val ref = RItem.as("ref")
     val cq =
       Select(
         select(i.all, org.all, pers0.all, pers1.all, equip.all)
-          .append(ref.id.s)
-          .append(ref.name.s)
           .append(f.id.s)
           .append(f.name.s),
         from(i)
@@ -87,7 +84,6 @@ object QItem extends FtsSupport {
           .leftJoin(pers0, pers0.pid === i.corrPerson)
           .leftJoin(pers1, pers1.pid === i.concPerson)
           .leftJoin(equip, equip.eid === i.concEquipment)
-          .leftJoin(ref, ref.id === i.inReplyTo)
           .leftJoin(f, f.id === i.folder),
         i.id === id
       ).build
@@ -100,7 +96,6 @@ object QItem extends FtsSupport {
             Option[RPerson],
             Option[RPerson],
             Option[REquipment],
-            Option[IdRef],
             Option[IdRef]
         )
       ]
@@ -122,7 +117,7 @@ object QItem extends FtsSupport {
       cfs <- customfields
       rel <- related
     } yield data.map(d =>
-      ItemData(d._1, d._2, d._3, d._4, d._5, d._6, d._7, ts, att, srcs, arch, cfs, rel)
+      ItemData(d._1, d._2, d._3, d._4, d._5, d._6, ts, att, srcs, arch, cfs, rel)
     )
   }
 
diff --git a/modules/store/src/main/scala/docspell/store/records/RItem.scala b/modules/store/src/main/scala/docspell/store/records/RItem.scala
index 2ac753ca..36eadefe 100644
--- a/modules/store/src/main/scala/docspell/store/records/RItem.scala
+++ b/modules/store/src/main/scala/docspell/store/records/RItem.scala
@@ -30,7 +30,6 @@ case class RItem(
     corrPerson: Option[Ident],
     concPerson: Option[Ident],
     concEquipment: Option[Ident],
-    inReplyTo: Option[Ident],
     dueDate: Option[Timestamp],
     created: Timestamp,
     updated: Timestamp,
@@ -63,7 +62,6 @@ object RItem {
       None,
       None,
       None,
-      None,
       now,
       now,
       None,
@@ -85,7 +83,6 @@ object RItem {
     val corrPerson = Column[Ident]("corrperson", this)
     val concPerson = Column[Ident]("concperson", this)
     val concEquipment = Column[Ident]("concequipment", this)
-    val inReplyTo = Column[Ident]("inreplyto", this)
     val dueDate = Column[Timestamp]("duedate", this)
     val created = Column[Timestamp]("created", this)
     val updated = Column[Timestamp]("updated", this)
@@ -103,7 +100,6 @@ object RItem {
       corrPerson,
       concPerson,
       concEquipment,
-      inReplyTo,
       dueDate,
       created,
       updated,
@@ -123,7 +119,7 @@ object RItem {
       T,
       T.all,
       fr"${v.id},${v.cid},${v.name},${v.itemDate},${v.source},${v.direction},${v.state}," ++
-        fr"${v.corrOrg},${v.corrPerson},${v.concPerson},${v.concEquipment},${v.inReplyTo},${v.dueDate}," ++
+        fr"${v.corrOrg},${v.corrPerson},${v.concPerson},${v.concEquipment},${v.dueDate}," ++
         fr"${v.created},${v.updated},${v.notes},${v.folderId}"
     )
 
@@ -145,7 +141,6 @@ object RItem {
           T.corrPerson.setTo(item.corrPerson),
           T.concPerson.setTo(item.concPerson),
           T.concEquipment.setTo(item.concEquipment),
-          T.inReplyTo.setTo(item.inReplyTo),
           T.dueDate.setTo(item.dueDate),
           T.notes.setTo(item.notes),
           T.folder.setTo(item.folderId),
diff --git a/modules/store/src/test/scala/docspell/store/fts/TempFtsOpsTest.scala b/modules/store/src/test/scala/docspell/store/fts/TempFtsOpsTest.scala
index 4946f39f..0b3c9aa5 100644
--- a/modules/store/src/test/scala/docspell/store/fts/TempFtsOpsTest.scala
+++ b/modules/store/src/test/scala/docspell/store/fts/TempFtsOpsTest.scala
@@ -187,7 +187,6 @@ class TempFtsOpsTest extends DatabaseTest {
       None,
       None,
       None,
-      None,
       ts,
       ts,
       None,