diff --git a/patches/patch20220110-6.0-SNAPSHOT/patch.sql b/patches/patch20220110-6.0-SNAPSHOT/patch.sql index 555dd0395430b37ad86ea717a3d3a3e3a2dd374f..2a707e001a607cb21a1ccda28bef9513473d83c0 100644 --- a/patches/patch20220110-6.0-SNAPSHOT/patch.sql +++ b/patches/patch20220110-6.0-SNAPSHOT/patch.sql @@ -44,7 +44,8 @@ ALTER TABLE files ADD COLUMN IF NOT EXISTS ( parent_directory INT UNSIGNED DEFAULT NULL, mimetype VARBINARY(255) DEFAULT NULL, file_storage_id VARBINARY(255) NOT NULL DEFAULT "DEFAULT", - file_key VARBINARY(16000) DEFAULT NULL + file_key VARBINARY(16000) DEFAULT NULL, + link_target INT UNSIGNED DEFAULT NULL ); -- ... and to the corresponding archive_files table. @@ -54,7 +55,8 @@ ALTER TABLE archive_files ADD COLUMN IF NOT EXISTS ( parent_directory INT UNSIGNED DEFAULT NULL, mimetype VARBINARY(255) DEFAULT NULL, file_storage_id VARBINARY(255) NOT NULL DEFAULT "DEFAULT", - file_key VARBINARY(16000) DEFAULT NULL + file_key VARBINARY(16000) DEFAULT NULL, + link_target INT UNSIGNED DEFAULT NULL ); -- no two files at the same path are allowed. diff --git a/procedures/insertFSODescriptor.sql b/procedures/insertFSODescriptor.sql index 8e24a3c028cb36336fbe593f80c7d3a7f498c01f..57060bff7177a57a094b4935ceed140e192bcf58 100644 --- a/procedures/insertFSODescriptor.sql +++ b/procedures/insertFSODescriptor.sql @@ -48,9 +48,10 @@ DROP PROCEDURE IF EXISTS db_5_0.insertFSODescriptor // * The files mime type. * FileStorageId VARCHAR(255), * The id of the file storage where the blob of the file is stored. - * FileKey VARCHAR(16000)) + * FileKey VARCHAR(16000)), * The key of the file in the file storage. - * + * LinkTarget INT UNSIGNED + * The entity id of the link target. */ CREATE PROCEDURE db_5_0.insertFSODescriptor( IN EntityID INT UNSIGNED, @@ -62,7 +63,8 @@ CREATE PROCEDURE db_5_0.insertFSODescriptor( IN FileParentID INT UNSIGNED, IN FileMimeType VARCHAR(255), IN FileStorageId VARCHAR(255), - IN FileKey VARCHAR(16000)) + IN FileKey VARCHAR(16000), + IN LinkTarget INT UNSIGNED) insertFSODescriptorBody: BEGIN INSERT INTO files ( @@ -75,8 +77,9 @@ insertFSODescriptorBody: BEGIN mimetype, file_storage_id, file_key, - parent_directory - ) VALUES (EntityID, unhex(FileHash), FileHashAlgo, FileCheckedTimestamp, FileSize, FilePath, FileMimeType, FileStorageId, FileKey, FileParentID); + parent_directory, + link_target + ) VALUES (EntityID, unhex(FileHash), FileHashAlgo, FileCheckedTimestamp, FileSize, FilePath, FileMimeType, FileStorageId, FileKey, FileParentID, LinkTarget); END; // diff --git a/procedures/listFSODescriptorByParentDirectory.sql b/procedures/listFSODescriptorByParentDirectory.sql index 600fffafaecb7aa1ff09ec8bff5f1577d038d06d..c1f70e4c5b90f15295752c35028735d9b231a47d 100644 --- a/procedures/listFSODescriptorByParentDirectory.sql +++ b/procedures/listFSODescriptorByParentDirectory.sql @@ -35,7 +35,8 @@ DROP PROCEDURE IF EXISTS db_5_0.listFSODescriptorByParentDirectory // * ResultSet * --------- * Tuples of (FileHashAlgo, FileId, FilePath, FileSize, FileHash, - * FileHashChecked, FileMimeType, FileStorageID, FileKey) + * FileHashChecked, FileMimeType, FileStorageID, FileKey, + * LinkTarget) */ CREATE PROCEDURE db_5_0.listFSODescriptorByParentDirectory( IN ParentDirectory INT UNSIGNED) @@ -50,7 +51,8 @@ listFSODescriptorByParentDirectoryBody: BEGIN checked_timestamp AS FileHashChecked, mimetype AS FileMimeType, file_storage_id AS FileStorageID, - file_key AS FileKey + file_key AS FileKey, + link_target AS LinkTarget FROM files WHERE parent_directory = ParentDirectory; diff --git a/procedures/retrieveEntity.sql b/procedures/retrieveEntity.sql index f7eb1e9ce7b6a0c60e70737785d800fac9dbd554..5ae6b6623ada2765ba0d4923b6426a51adec3443 100644 --- a/procedures/retrieveEntity.sql +++ b/procedures/retrieveEntity.sql @@ -48,12 +48,13 @@ drop procedure if exists db_5_0.retrieveEntity // * Tuple of (DatatypeID, Collection, EntityID, EntityName, EntityDesc, * EntityRole, FileSize, FilePath, FileHash, FileHashAlgo, * FileHashChecked, FileMimeType, FileStorageID, FileKey, - * FileParentID, ACL, Version) + * FileParentID, LinkTarget, ACL, Version) */ create procedure db_5_0.retrieveEntity( in EntityID INT UNSIGNED, in Version VARBINARY(255)) retrieveEntityBody: BEGIN + DECLARE LinkTarget INT UNSIGNED DEFAULT NULL; DECLARE FilePath VARCHAR(15920) DEFAULT NULL; DECLARE FileParentID INT UNSIGNED DEFAULT NULL; DECLARE FileSize BIGINT UNSIGNED DEFAULT NULL; @@ -89,8 +90,8 @@ retrieveEntityBody: BEGIN LEAVE retrieveEntityBody; END IF; - SELECT path, parent_directory, size, hex(hash), hash_algorithm, checked_timestamp, mimetype, file_storage_id, file_key - INTO FilePath, FileParentID, FileSize, FileHash, FileHashAlgo, FileHashChecked, FileMimeType, FileStorageID, FileKey + SELECT path, parent_directory, size, hex(hash), hash_algorithm, checked_timestamp, mimetype, file_storage_id, file_key, link_target + INTO FilePath, FileParentID, FileSize, FileHash, FileHashAlgo, FileHashChecked, FileMimeType, FileStorageID, FileKey, LinkTarget FROM archive_files WHERE file_id = EntityID AND _iversion = IVersion @@ -153,8 +154,8 @@ retrieveEntityBody: BEGIN END IF; END IF; - SELECT path, parent_directory, size, hex(hash), hash_algorithm, checked_timestamp, mimetype, file_storage_id, file_key - INTO FilePath, FileParentID, FileSize, FileHash, FileHashAlgo, FileHashChecked, FileMimeType, FileStorageID, FileKey + SELECT path, parent_directory, size, hex(hash), hash_algorithm, checked_timestamp, mimetype, file_storage_id, file_key, link_target + INTO FilePath, FileParentID, FileSize, FileHash, FileHashAlgo, FileHashChecked, FileMimeType, FileStorageID, FileKey, LinkTarget FROM files WHERE file_id = EntityID LIMIT 1; @@ -191,10 +192,11 @@ retrieveEntityBody: BEGIN FileHash AS FileHash, FileHashAlgo AS FileHashAlgo, FileHashChecked AS FileHashChecked, - FileMimeType as FileMimeType, - FileStorageID as FileStorageID, - FileKey as FileKey, - FileParentID as FileParentID, + FileMimeType AS FileMimeType, + FileStorageID AS FileStorageID, + FileKey AS FileKey, + FileParentID AS FileParentID, + LinkTarget AS LinkTarget, (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL, Version AS Version FROM entities e WHERE id = EntityID LIMIT 1; diff --git a/procedures/retrieveFSODescriptor.sql b/procedures/retrieveFSODescriptor.sql new file mode 100644 index 0000000000000000000000000000000000000000..e87ec650e64f47899301e26c977b840291b8f0e5 --- /dev/null +++ b/procedures/retrieveFSODescriptor.sql @@ -0,0 +1,67 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2022 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2022 Timm Fitschen <t.fitschen@indiscale + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + + +DELIMITER // + +DROP PROCEDURE IF EXISTS db_5_0.retrieveFSODescriptor // + +/** + * Retrieve the FSODescriptor by fileStorageId and key. + * + * Parameters + * ---------- + * FileStorageID : VARCHAR(255), + * The file storage id. + * FileKey : VARCHAR(16000), + * The file's key in the file storage. + * + * ResultSet + * --------- + * Tuples of (FileHashAlgo, FileId, FilePath, FileSize, FileHash, + * FileHashChecked, FileMimeType, FileStorageID, FileKey, + * FileParentID, LinkTarget) + */ +CREATE PROCEDURE db_5_0.retrieveFSODescriptor( + IN FileStorageID VARCHAR(255), + IN FileKey VARCHAR(16000) +) +retrieveFSODescriptorBody: BEGIN + + SELECT hash_algorithm AS FileHashAlgo, + file_id AS FileId, + parent_directory AS FileParentID, + path AS FilePath, + size AS FileSize, + hex(hash) AS FileHash, + checked_timestamp AS FileHashChecked, + mimetype AS FileMimeType, + file_storage_id AS FileStorageID, + file_key AS FileKey, + link_target AS LinkTarget + FROM files + WHERE file_storage_id = FileStorageID + AND file_key = FileKey; + +END; +// + + +DELIMITER ; diff --git a/procedures/retrieveFSODescriptorByPath.sql b/procedures/retrieveFSODescriptorByPath.sql index 821cf9da1284d306c41d4dbda6c13fb7e24d2ede..382882b7cd6dbbcfaed870254669f8cc8b8039a7 100644 --- a/procedures/retrieveFSODescriptorByPath.sql +++ b/procedures/retrieveFSODescriptorByPath.sql @@ -41,7 +41,7 @@ DROP PROCEDURE IF EXISTS db_5_0.retrieveFSODescriptorByPath; * ResultSet * --------- * Tuples of (FileHashAlgo, FileID, FilePath, FileSize, FileHash, FileParentID, - * FileHashChecked, FileMimeType, FileStorageID, FileKey) + * FileHashChecked, FileMimeType, FileStorageID, FileKey, LinkTarget) */ CREATE PROCEDURE db_5_0.retrieveFSODescriptorByPath( IN byPath VARBINARY(16000)) @@ -57,7 +57,8 @@ retrieveFSODescriptorByPathBody: BEGIN mimetype AS FileMimeType, file_storage_id AS FileStorageID, file_key AS FileKey, - parent_directory AS FileParentID + parent_directory AS FileParentID, + link_target AS LinkTarget FROM files WHERE path LIKE byPath;