From 74fd0219f5d69b424e0ccc10d03dba896e87603d Mon Sep 17 00:00:00 2001
From: Sonia Zorba <sonia.zorba@inaf.it>
Date: Tue, 25 May 2021 16:06:49 +0200
Subject: [PATCH] Added unique path constraint

---
 01-paths-indexes.sql | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/01-paths-indexes.sql b/01-paths-indexes.sql
index 38e587e..ad2bfde 100644
--- a/01-paths-indexes.sql
+++ b/01-paths-indexes.sql
@@ -36,5 +36,7 @@ CREATE UNIQUE INDEX file_path_idx ON node USING btree(path);
 ALTER TABLE node ADD COLUMN relative_path ltree GENERATED ALWAYS AS (path(parent_relative_path, node_id)) STORED;
 CREATE INDEX file_rel_path_gist_idx ON node USING GIST(relative_path);
 
+ALTER TABLE node ADD CONSTRAINT unique_path UNIQUE (parent_path, name);
+
 -- Create root node
 INSERT INTO node (parent_path, parent_relative_path, name, type, creator_id, is_public) VALUES (NULL, NULL, '', 'container', '0', true);
-- 
GitLab