From 437a4cdfac5fd7d10d0a7e41b4a942f534240acc Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Sun, 18 Feb 2024 22:36:48 +0100
Subject: [PATCH] BUG: fix merge errors

---
 patches/patch20240127-8.0-SNAPSHOT/patch.sql      |  7 ++-----
 procedures/getDependentEntities.sql               |  2 +-
 procedures/insertEntity.sql                       |  2 +-
 procedures/insertFSODescriptor.sql                |  2 +-
 procedures/listFSODescriptorByParentDirectory.sql | 11 +++++++----
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/patches/patch20240127-8.0-SNAPSHOT/patch.sql b/patches/patch20240127-8.0-SNAPSHOT/patch.sql
index 02faf66..90669e5 100644
--- a/patches/patch20240127-8.0-SNAPSHOT/patch.sql
+++ b/patches/patch20240127-8.0-SNAPSHOT/patch.sql
@@ -1,10 +1,5 @@
 -- USE _caosdb_schema_unit_tests;
 
-
--- REMOVE SQLITE datatype (obsolete)
-DELETE FROM name_data WHERE entity_id = 50;
-DELETE FROM entities WHERE id = 50;
-
 /*
 -- Create file_hashes table.
 -- This table is necessary because not all FSO objects have hashes (e.g.
@@ -69,6 +64,7 @@ ALTER TABLE entities MODIFY COLUMN `role` enum('RECORDTYPE','RECORD','FILE','_RE
 -- Add a new special role "DIRECTORY"
 INSERT IGNORE INTO entities (id, description, role, acl) VALUES (9, "The directory role.", "ROLE", 0);
 INSERT IGNORE INTO name_data (domain_id, entity_id, property_id, value, status, pidx) VALUES (0, 9, 20, "DIRECTORY", "FIX", 0);
+INSERT IGNORE INTO entity_ids (id, internal_id) VALUES (9,9);
 
 -- In the default file storage back-end the key is just the path.
 UPDATE files SET file_key=path;
@@ -91,6 +87,7 @@ ALTER TABLE archive_files MODIFY COLUMN path VARCHAR(16000) NOT NULL;
 -- Add a special nameless directory which is used as the root directory of the
 -- internal file system.
 INSERT IGNORE INTO entities (id, description, role, acl) VALUES (51, "The root directory of the internal files system", "DIRECTORY", 0);
+INSERT IGNORE INTO entity_ids (id, internal_id) VALUES (51,51);
 INSERT IGNORE INTO files
     (file_id, path, checked_timestamp, mimetype, file_storage_id,
         file_key, parent_directory)
diff --git a/procedures/getDependentEntities.sql b/procedures/getDependentEntities.sql
index 8472c5e..908095e 100644
--- a/procedures/getDependentEntities.sql
+++ b/procedures/getDependentEntities.sql
@@ -78,7 +78,7 @@ BEGIN
     INSERT IGNORE INTO referring (id) SELECT entity_id FROM date_data WHERE property_id=InternalEntityID AND domain_id=0 AND entity_id!=InternalEntityID;
     INSERT IGNORE INTO referring (id) SELECT domain_id FROM date_data WHERE property_id=InternalEntityID AND domain_id!=InternalEntityID AND entity_id!=InternalEntityID AND domain_id!=0;
 
-    INSERT IGNORE INTO refering (id) SELECT file_id FROM files WHERE parent_directory=InternalEntityID;
+    INSERT IGNORE INTO referring (id) SELECT file_id FROM files WHERE parent_directory=InternalEntityID;
 
     INSERT IGNORE INTO referring (id) SELECT entity_id FROM null_data WHERE property_id=InternalEntityID AND domain_id=0 AND entity_id!=InternalEntityID;
     INSERT IGNORE INTO referring (id) SELECT domain_id FROM null_data WHERE property_id=InternalEntityID AND domain_id!=InternalEntityID AND entity_id!=InternalEntityID AND domain_id!=0;
diff --git a/procedures/insertEntity.sql b/procedures/insertEntity.sql
index 00de4f7..ab0723a 100644
--- a/procedures/insertEntity.sql
+++ b/procedures/insertEntity.sql
@@ -87,7 +87,7 @@ BEGIN
             VALUES (0, InternalEntityID, 20, EntityName, "FIX", 0);
     END IF;
 
-    SELECT Version as Version;
+    SELECT Version as Version, InternalEntityID as InternalEntityID;
 
 END;
 //
diff --git a/procedures/insertFSODescriptor.sql b/procedures/insertFSODescriptor.sql
index 09c916f..597ebaf 100644
--- a/procedures/insertFSODescriptor.sql
+++ b/procedures/insertFSODescriptor.sql
@@ -80,7 +80,7 @@ insertFSODescriptorBody: BEGIN
             file_storage_id,
             file_key,
             parent_directory
-        ) VALUES (InternalEntityID, unhex(FileHash), FileHashAlgo, FileCheckedTimestamp, FileSize, FilePath, FileMimeType, FileStorageId, FileKey, FileParentID);
+        ) VALUES (InternalEntityID, unhex(FileHash), FileHashAlgo, FileCheckedTimestamp, FileSize, FilePath, FileMimeType, FileStorageId, FileKey, InternalParentID);
 
 END;
 //
diff --git a/procedures/listFSODescriptorByParentDirectory.sql b/procedures/listFSODescriptorByParentDirectory.sql
index 600fffa..430d886 100644
--- a/procedures/listFSODescriptorByParentDirectory.sql
+++ b/procedures/listFSODescriptorByParentDirectory.sql
@@ -38,12 +38,15 @@ DROP PROCEDURE IF EXISTS db_5_0.listFSODescriptorByParentDirectory //
  *            FileHashChecked, FileMimeType, FileStorageID, FileKey)
  */
 CREATE PROCEDURE db_5_0.listFSODescriptorByParentDirectory(
-    IN ParentDirectory INT UNSIGNED)
+    IN ParentDirectory VARCHAR(255))
 listFSODescriptorByParentDirectoryBody: BEGIN
+    DECLARE InternalParentID INT UNSIGNED DEFAULT NULL;
+
+    SELECT internal_id INTO InternalParentID from entity_ids WHERE id = ParentDirectory;
 
     SELECT hash_algorithm AS FileHashAlgo,
-            file_id AS FileId,
-            parent_directory AS FileParentID,
+            (SELECT id FROM entity_ids WHERE internal_id = file_id) AS FileId,
+            ParentDirectory AS FileParentID,
             path AS FilePath,
             size AS FileSize,
             hex(hash) AS FileHash,
@@ -52,7 +55,7 @@ listFSODescriptorByParentDirectoryBody: BEGIN
             file_storage_id AS FileStorageID,
             file_key AS FileKey
         FROM files
-        WHERE parent_directory = ParentDirectory;
+        WHERE parent_directory = InternalParentID;
 
 END;
 //
-- 
GitLab