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

WIP: parent_directories

parent 2d455272
Branches
No related tags found
1 merge request!12DRAFT: ENH: file system: core
Pipeline #7922 failed
...@@ -20,12 +20,11 @@ ALTER TABLE archive_files ADD COLUMN IF NOT EXISTS ( ...@@ -20,12 +20,11 @@ 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(255) DEFAULT NULL, file_key VARBINARY(40000) DEFAULT NULL,
checked_timestamp BIGINT NOT NULL DEFAULT 0, checked_timestamp BIGINT NOT NULL DEFAULT 0,
hash_algorithm VARBINARY(255) DEFAULT NULL hash_algorithm VARBINARY(255) DEFAULT NULL
); );
ALTER TABLE entities MODIFY COLUMN `role` enum('RECORDTYPE','RECORD','FILE','DOMAIN','PROPERTY','DATATYPE','ROLE','QUERYTEMPLATE', 'DIRECTORY') COLLATE utf8_unicode_ci NOT NULL; ALTER TABLE entities MODIFY COLUMN `role` enum('RECORDTYPE','RECORD','FILE','DOMAIN','PROPERTY','DATATYPE','ROLE','QUERYTEMPLATE', 'DIRECTORY') COLLATE utf8_unicode_ci NOT NULL;
INSERT INTO entities (id, description, role, acl) VALUES (9, "The directory role.", "ROLE", 0); INSERT INTO entities (id, description, role, acl) VALUES (9, "The directory role.", "ROLE", 0);
...@@ -34,8 +33,11 @@ INSERT INTO name_data (domain_id, entity_id, property_id, value, status, pidx) V ...@@ -34,8 +33,11 @@ INSERT INTO name_data (domain_id, entity_id, property_id, value, status, pidx) V
UPDATE files SET file_key=path; UPDATE files SET file_key=path;
UPDATE archive_files SET file_key=path; UPDATE archive_files SET file_key=path;
ALTER TABLE files MODIFY COLUMN file_key VARBINARY(255) NOT NULL; ALTER TABLE files MODIFY COLUMN size BIGINT NULL DEFAULT NULL;
ALTER TABLE archive_files MODIFY COLUMN file_key VARBINARY(255) NOT NULL; ALTER TABLE files MODIFY COLUMN path VARCHAR(5000) NOT NULL;
ALTER TABLE archive_files MODIFY COLUMN path VARCHAR(5000) NOT NULL;
ALTER TABLE files MODIFY COLUMN file_key VARBINARY(40000) NOT NULL;
ALTER TABLE archive_files MODIFY COLUMN file_key VARBINARY(40000) NOT NULL;
DROP PROCEDURE IF EXISTS _create_dirs; DROP PROCEDURE IF EXISTS _create_dirs;
DELIMITER // DELIMITER //
......
...@@ -422,32 +422,42 @@ DROP PROCEDURE IF EXISTS setFileProperties // ...@@ -422,32 +422,42 @@ DROP PROCEDURE IF EXISTS setFileProperties //
* *
* Parameters * Parameters
* ---------- * ----------
* EntityID * FileID
* The file's id. * The entity's id.
* FilePath
* Path of the file in the internal file system. If NULL, an existing file
* entity is simply deleted.
* FileSize
* Size of the file in bytes.
* FileHash * FileHash
* A Sha512 Hash of the file. * The SHA512 Hash of the file (or NULL for directories).
* FileCheckedTimestamp
* The timestamp when the hash was last checked.
* FileSize
* The byte size (or NULL for directories).
* FilePath
* The path of the object.
* FileMimetype
* The mimetype (use "inode/directory" for directories, use NULL for unknown)
* FileStorageID
* The ID of the back-end file storage where this object is located.
* FileKey
* The file storage key of this object.
* FileParentID
* The entity id of the parent directory (or NULL).
*/ */
CREATE PROCEDURE setFileProperties ( CREATE PROCEDURE setFileProperties (
in EntityID INT UNSIGNED, in FileID INT UNSIGNED,
in FilePath TEXT, in FilePath VARCHAR(5000),
in FileSize BIGINT UNSIGNED, in FileSize BIGINT UNSIGNED,
in FileHash VARCHAR(255), in FileHash VARCHAR(255),
in FileChecked BIGINT, in FileChecked BIGINT,
in FileMimetype VARBINARY(255), in FileMimetype VARBINARY(255),
in FileStorageId VARBINARY(255), in FileStorageId VARBINARY(255),
in FileKey VARBINARY(65525) in FileKey VARBINARY(40000),
in FileParentID INT UNSIGNED
) )
BEGIN BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL; DECLARE IVersion INT UNSIGNED DEFAULT NULL;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
SELECT max(e._iversion) INTO IVersion SELECT max(e._iversion) INTO IVersion
FROM entity_version AS e FROM entity_version AS e
WHERE e.entity_id = EntityID; WHERE e.entity_id = FileID;
INSERT INTO archive_files (file_id, path, size, hash, INSERT INTO archive_files (file_id, path, size, hash,
checked_timestamp, mimetype, file_storage_id, file_key, checked_timestamp, mimetype, file_storage_id, file_key,
...@@ -455,15 +465,15 @@ BEGIN ...@@ -455,15 +465,15 @@ BEGIN
SELECT file_id, path, size, hash, checked_timestamp, mimetype, SELECT file_id, path, size, hash, checked_timestamp, mimetype,
file_storage_id, file_key, IVersion AS _iversion file_storage_id, file_key, IVersion AS _iversion
FROM files FROM files
WHERE file_id = EntityID; WHERE file_id = FileID;
END IF; END IF;
DELETE FROM files WHERE file_id = EntityID; DELETE FROM files WHERE file_id = FileID;
IF FilePath IS NOT NULL THEN IF FilePath IS NOT NULL THEN
INSERT INTO files (file_id, path, size, hash, checked_timestamp, INSERT INTO files (file_id, path, size, hash, checked_timestamp,
mimetype, file_storage_id, file_key) mimetype, file_storage_id, file_key)
VALUES (EntityID, FilePath, FileSize, unhex(FileHash), FileChecked, VALUES (FileID, FilePath, FileSize, unhex(FileHash), FileChecked,
FileMimetype, FileStorageId, FileKey); FileMimetype, FileStorageId, FileKey);
END IF; END IF;
......
/*
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2021 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/>.
*/
DROP PROCEDURE IF EXISTS db_2_0.insertFSODescriptor;
delimiter //
/**
* Insert a FSODescriptor
*
* Parameters
* ----------
* FileID
* The entity's id.
* FileHash
* The SHA512 Hash of the file (or NULL for directories).
* FileCheckedTimestamp
* The timestamp when the hash was last checked.
* FileSize
* The byte size (or NULL for directories).
* FilePath
* The path of the object.
* FileMimetype
* The mimetype (use "inode/directory" for directories, use NULL for unknown)
* FileStorageID
* The ID of the back-end file storage where this object is located.
* FileKey
* The file storage key of this object.
* FileParentID
* The entity id of the parent directory (or NULL).
*/
CREATE PROCEDURE db_2_0.insertFSODescriptor(
in FileID INT UNSIGNED,
in FileHash VARCHAR(255),
in FileCheckedTimestamp BIGINT,
in FileSize BIGINT UNSIGNED,
in FilePath VARCHAR(5000),
in FileMimetype VARBINARY(255),
in FileStorageID VARBINARY(255),
in FileKey VARBINARY(40000),
in FileParentID INT UNSIGNED
)
BEGIN
INSERT INTO files
(file_id, parent_directory, hash, checked_timestamp, size, path,
mimetype, file_storage_id, file_key)
VALUES (FileID, FileParentID, unhex(FileHash), FileCheckedTimestamp,
FileSize, FilePath, FileMimetype, FileStorageID, FileKey);
END;
//
delimiter ;
...@@ -53,14 +53,14 @@ create procedure db_2_0.retrieveEntity( ...@@ -53,14 +53,14 @@ create procedure db_2_0.retrieveEntity(
in EntityID INT UNSIGNED, in EntityID INT UNSIGNED,
in Version VARBINARY(255)) in Version VARBINARY(255))
retrieveEntityBody: BEGIN retrieveEntityBody: BEGIN
DECLARE FilePath VARCHAR(255) DEFAULT NULL; DECLARE FilePath VARCHAR(5000) DEFAULT NULL;
DECLARE FileParentID INT UNSIGNED DEFAULT NULL; DECLARE FileParentID INT UNSIGNED DEFAULT NULL;
DECLARE FileSize VARCHAR(255) DEFAULT NULL; DECLARE FileSize BIGINT UNSIGNED DEFAULT NULL;
DECLARE FileHash VARCHAR(255) DEFAULT NULL; DECLARE FileHash VARCHAR(255) DEFAULT NULL;
DECLARE FileHashChecked BIGINT DEFAULT NULL; DECLARE FileHashChecked BIGINT DEFAULT NULL;
DECLARE FileMimetype VARBINARY(255) DEFAULT NULL; DECLARE FileMimetype VARBINARY(255) DEFAULT NULL;
DECLARE FileStorageID VARBINARY(255) DEFAULT NULL; DECLARE FileStorageID VARBINARY(255) DEFAULT NULL;
DECLARE FileKey VARBINARY(65525) DEFAULT NULL; DECLARE FileKey VARBINARY(40000) DEFAULT NULL;
DECLARE DatatypeID INT UNSIGNED DEFAULT NULL; DECLARE DatatypeID INT UNSIGNED DEFAULT NULL;
DECLARE CollectionName VARCHAR(255) DEFAULT NULL; DECLARE CollectionName VARCHAR(255) DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE; DECLARE IsHead BOOLEAN DEFAULT TRUE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment