From 939f248499e16d8ea3e4904015131ebbb941f960 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Wed, 15 Oct 2025 21:56:20 +0200 Subject: [PATCH] unique (folder_id, title) for documents --- .../down.sql | 16 ++++++++++++++++ .../202503240002_unique_document_names/up.sql | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 backend/migrations/202503240002_unique_document_names/down.sql create mode 100644 backend/migrations/202503240002_unique_document_names/up.sql diff --git a/backend/migrations/202503240002_unique_document_names/down.sql b/backend/migrations/202503240002_unique_document_names/down.sql new file mode 100644 index 0000000..648a7ed --- /dev/null +++ b/backend/migrations/202503240002_unique_document_names/down.sql @@ -0,0 +1,16 @@ +DROP INDEX IF EXISTS documents_unique_folder_filename; +DROP INDEX IF EXISTS idx_documents_folder_title; + +CREATE INDEX idx_documents_folder_title + ON documents ( + COALESCE(folder_id, '00000000-0000-0000-0000-000000000000'::uuid), + title + ) + WHERE deleted_at IS NULL; + +CREATE INDEX idx_documents_folder_filename + ON documents ( + COALESCE(folder_id, '00000000-0000-0000-0000-000000000000'::uuid), + filename + ) + WHERE deleted_at IS NULL; diff --git a/backend/migrations/202503240002_unique_document_names/up.sql b/backend/migrations/202503240002_unique_document_names/up.sql new file mode 100644 index 0000000..a48b8b3 --- /dev/null +++ b/backend/migrations/202503240002_unique_document_names/up.sql @@ -0,0 +1,18 @@ +DROP INDEX IF EXISTS idx_documents_folder_title; +DROP INDEX IF EXISTS idx_documents_folder_filename; +DROP INDEX IF EXISTS documents_unique_folder_title; +DROP INDEX IF EXISTS documents_unique_folder_filename; + +CREATE INDEX idx_documents_folder_title + ON documents ( + COALESCE(folder_id, '00000000-0000-0000-0000-000000000000'::uuid), + title + ) + WHERE deleted_at IS NULL; + +CREATE UNIQUE INDEX documents_unique_folder_filename + ON documents ( + COALESCE(folder_id, '00000000-0000-0000-0000-000000000000'::uuid), + filename + ) + WHERE deleted_at IS NULL;