Skip to content
Snippets Groups Projects
Verified Commit a7d23ea5 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: file storage: link

parent 98133475
Branches
Tags
1 merge request!13Draft: EHN: file system: link
Pipeline #31802 failed
...@@ -44,7 +44,8 @@ ALTER TABLE files ADD COLUMN IF NOT EXISTS ( ...@@ -44,7 +44,8 @@ ALTER TABLE files ADD COLUMN IF NOT EXISTS (
parent_directory INT UNSIGNED DEFAULT NULL, parent_directory INT UNSIGNED DEFAULT NULL,
mimetype VARBINARY(255) DEFAULT NULL, mimetype VARBINARY(255) DEFAULT NULL,
file_storage_id VARBINARY(255) NOT NULL DEFAULT "DEFAULT", 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. -- ... and to the corresponding archive_files table.
...@@ -54,7 +55,8 @@ ALTER TABLE archive_files ADD COLUMN IF NOT EXISTS ( ...@@ -54,7 +55,8 @@ ALTER TABLE archive_files ADD COLUMN IF NOT EXISTS (
parent_directory INT UNSIGNED DEFAULT NULL, parent_directory INT UNSIGNED DEFAULT NULL,
mimetype VARBINARY(255) DEFAULT NULL, mimetype VARBINARY(255) DEFAULT NULL,
file_storage_id VARBINARY(255) NOT NULL DEFAULT "DEFAULT", 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. -- no two files at the same path are allowed.
......
...@@ -48,9 +48,10 @@ DROP PROCEDURE IF EXISTS db_5_0.insertFSODescriptor // ...@@ -48,9 +48,10 @@ DROP PROCEDURE IF EXISTS db_5_0.insertFSODescriptor //
* The files mime type. * The files mime type.
* FileStorageId VARCHAR(255), * FileStorageId VARCHAR(255),
* The id of the file storage where the blob of the file is stored. * 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. * 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( CREATE PROCEDURE db_5_0.insertFSODescriptor(
IN EntityID INT UNSIGNED, IN EntityID INT UNSIGNED,
...@@ -62,7 +63,8 @@ CREATE PROCEDURE db_5_0.insertFSODescriptor( ...@@ -62,7 +63,8 @@ CREATE PROCEDURE db_5_0.insertFSODescriptor(
IN FileParentID INT UNSIGNED, IN FileParentID INT UNSIGNED,
IN FileMimeType VARCHAR(255), IN FileMimeType VARCHAR(255),
IN FileStorageId VARCHAR(255), IN FileStorageId VARCHAR(255),
IN FileKey VARCHAR(16000)) IN FileKey VARCHAR(16000),
IN LinkTarget INT UNSIGNED)
insertFSODescriptorBody: BEGIN insertFSODescriptorBody: BEGIN
INSERT INTO files ( INSERT INTO files (
...@@ -75,8 +77,9 @@ insertFSODescriptorBody: BEGIN ...@@ -75,8 +77,9 @@ insertFSODescriptorBody: BEGIN
mimetype, mimetype,
file_storage_id, file_storage_id,
file_key, file_key,
parent_directory parent_directory,
) VALUES (EntityID, unhex(FileHash), FileHashAlgo, FileCheckedTimestamp, FileSize, FilePath, FileMimeType, FileStorageId, FileKey, FileParentID); link_target
) VALUES (EntityID, unhex(FileHash), FileHashAlgo, FileCheckedTimestamp, FileSize, FilePath, FileMimeType, FileStorageId, FileKey, FileParentID, LinkTarget);
END; END;
// //
......
...@@ -35,7 +35,8 @@ DROP PROCEDURE IF EXISTS db_5_0.listFSODescriptorByParentDirectory // ...@@ -35,7 +35,8 @@ DROP PROCEDURE IF EXISTS db_5_0.listFSODescriptorByParentDirectory //
* ResultSet * ResultSet
* --------- * ---------
* Tuples of (FileHashAlgo, FileId, FilePath, FileSize, FileHash, * Tuples of (FileHashAlgo, FileId, FilePath, FileSize, FileHash,
* FileHashChecked, FileMimeType, FileStorageID, FileKey) * FileHashChecked, FileMimeType, FileStorageID, FileKey,
* LinkTarget)
*/ */
CREATE PROCEDURE db_5_0.listFSODescriptorByParentDirectory( CREATE PROCEDURE db_5_0.listFSODescriptorByParentDirectory(
IN ParentDirectory INT UNSIGNED) IN ParentDirectory INT UNSIGNED)
...@@ -50,7 +51,8 @@ listFSODescriptorByParentDirectoryBody: BEGIN ...@@ -50,7 +51,8 @@ listFSODescriptorByParentDirectoryBody: BEGIN
checked_timestamp AS FileHashChecked, checked_timestamp AS FileHashChecked,
mimetype AS FileMimeType, mimetype AS FileMimeType,
file_storage_id AS FileStorageID, file_storage_id AS FileStorageID,
file_key AS FileKey file_key AS FileKey,
link_target AS LinkTarget
FROM files FROM files
WHERE parent_directory = ParentDirectory; WHERE parent_directory = ParentDirectory;
......
...@@ -48,12 +48,13 @@ drop procedure if exists db_5_0.retrieveEntity // ...@@ -48,12 +48,13 @@ drop procedure if exists db_5_0.retrieveEntity //
* Tuple of (DatatypeID, Collection, EntityID, EntityName, EntityDesc, * Tuple of (DatatypeID, Collection, EntityID, EntityName, EntityDesc,
* EntityRole, FileSize, FilePath, FileHash, FileHashAlgo, * EntityRole, FileSize, FilePath, FileHash, FileHashAlgo,
* FileHashChecked, FileMimeType, FileStorageID, FileKey, * FileHashChecked, FileMimeType, FileStorageID, FileKey,
* FileParentID, ACL, Version) * FileParentID, LinkTarget, ACL, Version)
*/ */
create procedure db_5_0.retrieveEntity( create procedure db_5_0.retrieveEntity(
in EntityID INT UNSIGNED, in EntityID INT UNSIGNED,
in Version VARBINARY(255)) in Version VARBINARY(255))
retrieveEntityBody: BEGIN retrieveEntityBody: BEGIN
DECLARE LinkTarget INT UNSIGNED DEFAULT NULL;
DECLARE FilePath VARCHAR(15920) DEFAULT NULL; DECLARE FilePath VARCHAR(15920) DEFAULT NULL;
DECLARE FileParentID INT UNSIGNED DEFAULT NULL; DECLARE FileParentID INT UNSIGNED DEFAULT NULL;
DECLARE FileSize BIGINT UNSIGNED DEFAULT NULL; DECLARE FileSize BIGINT UNSIGNED DEFAULT NULL;
...@@ -89,8 +90,8 @@ retrieveEntityBody: BEGIN ...@@ -89,8 +90,8 @@ retrieveEntityBody: BEGIN
LEAVE retrieveEntityBody; LEAVE retrieveEntityBody;
END IF; END IF;
SELECT path, parent_directory, size, hex(hash), hash_algorithm, checked_timestamp, mimetype, file_storage_id, file_key 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 INTO FilePath, FileParentID, FileSize, FileHash, FileHashAlgo, FileHashChecked, FileMimeType, FileStorageID, FileKey, LinkTarget
FROM archive_files FROM archive_files
WHERE file_id = EntityID WHERE file_id = EntityID
AND _iversion = IVersion AND _iversion = IVersion
...@@ -153,8 +154,8 @@ retrieveEntityBody: BEGIN ...@@ -153,8 +154,8 @@ retrieveEntityBody: BEGIN
END IF; END IF;
END IF; END IF;
SELECT path, parent_directory, size, hex(hash), hash_algorithm, checked_timestamp, mimetype, file_storage_id, file_key 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 INTO FilePath, FileParentID, FileSize, FileHash, FileHashAlgo, FileHashChecked, FileMimeType, FileStorageID, FileKey, LinkTarget
FROM files FROM files
WHERE file_id = EntityID WHERE file_id = EntityID
LIMIT 1; LIMIT 1;
...@@ -191,10 +192,11 @@ retrieveEntityBody: BEGIN ...@@ -191,10 +192,11 @@ retrieveEntityBody: BEGIN
FileHash AS FileHash, FileHash AS FileHash,
FileHashAlgo AS FileHashAlgo, FileHashAlgo AS FileHashAlgo,
FileHashChecked AS FileHashChecked, FileHashChecked AS FileHashChecked,
FileMimeType as FileMimeType, FileMimeType AS FileMimeType,
FileStorageID as FileStorageID, FileStorageID AS FileStorageID,
FileKey as FileKey, FileKey AS FileKey,
FileParentID as FileParentID, FileParentID AS FileParentID,
LinkTarget AS LinkTarget,
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL, (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL,
Version AS Version Version AS Version
FROM entities e WHERE id = EntityID LIMIT 1; FROM entities e WHERE id = EntityID LIMIT 1;
......
/*
* 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 ;
...@@ -41,7 +41,7 @@ DROP PROCEDURE IF EXISTS db_5_0.retrieveFSODescriptorByPath; ...@@ -41,7 +41,7 @@ DROP PROCEDURE IF EXISTS db_5_0.retrieveFSODescriptorByPath;
* ResultSet * ResultSet
* --------- * ---------
* Tuples of (FileHashAlgo, FileID, FilePath, FileSize, FileHash, FileParentID, * Tuples of (FileHashAlgo, FileID, FilePath, FileSize, FileHash, FileParentID,
* FileHashChecked, FileMimeType, FileStorageID, FileKey) * FileHashChecked, FileMimeType, FileStorageID, FileKey, LinkTarget)
*/ */
CREATE PROCEDURE db_5_0.retrieveFSODescriptorByPath( CREATE PROCEDURE db_5_0.retrieveFSODescriptorByPath(
IN byPath VARBINARY(16000)) IN byPath VARBINARY(16000))
...@@ -57,7 +57,8 @@ retrieveFSODescriptorByPathBody: BEGIN ...@@ -57,7 +57,8 @@ retrieveFSODescriptorByPathBody: BEGIN
mimetype AS FileMimeType, mimetype AS FileMimeType,
file_storage_id AS FileStorageID, file_storage_id AS FileStorageID,
file_key AS FileKey, file_key AS FileKey,
parent_directory AS FileParentID parent_directory AS FileParentID,
link_target AS LinkTarget
FROM files FROM files
WHERE path LIKE byPath; WHERE path LIKE byPath;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment