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

WIP: filesystem

parent 40fb1793
No related branches found
No related tags found
1 merge request!12DRAFT: ENH: file system: core
Pipeline #18867 failed
......@@ -12,7 +12,7 @@ DELETE FROM entities WHERE id = 50;
CREATE TABLE IF NOT EXISTS file_hashes (
file_id INT UNSIGNED,
digest VARBINARY(255) NOT NULL,
algorithm VARBINARY(255) NOT NULL DEFAULT "SHA-512",
algorithm VARBINARY(255) NOT NULL,
checked_timestamp BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (file_id, algorithm),
FOREIGN KEY (file_id) REFERENCES files (file_id)
......@@ -30,8 +30,8 @@ CREATE TABLE IF NOT EXISTS archive_file_hashes (
);
-- Move existing hash data to new tables...
INSERT INTO file_hashes (file_id, digest, checked_timestamp) SELECT file_id, hash, checked_timestamp FROM files WHERE hash IS NOT NULL;
INSERT INTO archive_file_hashes (file_id, _iversion, digest, checked_timestamp) SELECT file_id, _iversion, hash, checked_timestamp FROM archive_files WHERE hash IS NOT NULL;
INSERT INTO file_hashes (file_id, digest, algorithm, checked_timestamp) SELECT file_id, hash, "SHA-512", checked_timestamp FROM files WHERE hash IS NOT NULL;
INSERT INTO archive_file_hashes (file_id, _iversion, digest, algorithm, checked_timestamp) SELECT file_id, _iversion, hash, "SHA-512", checked_timestamp FROM archive_files WHERE hash IS NOT NULL;
-- and remove hash colums from the files and archive_files tables.
ALTER TABLE files DROP COLUMN hash;
......@@ -40,19 +40,21 @@ ALTER TABLE archive_files DROP COLUMN hash;
-- Add new fields to files table...
ALTER TABLE files ADD COLUMN IF NOT EXISTS (
hash_algorithm VARBINARY(255) NULL DEFAULT "SHA-512",
parent_directory INT UNSIGNED DEFAULT NULL,
mimetype VARBINARY(255) DEFAULT NULL,
file_storage_id VARBINARY(255) NOT NULL DEFAULT "DEFAULT",
file_key VARBINARY(16175) DEFAULT NULL
file_key VARBINARY(16000) DEFAULT NULL
);
-- ... and to the corresponding archive_files table.
ALTER TABLE archive_files ADD COLUMN IF NOT EXISTS (
checked_timestamp BIGINT NOT NULL DEFAULT 0,
hash_algorithm VARBINARY(255) NULL DEFAULT "SHA-512",
parent_directory INT UNSIGNED DEFAULT NULL,
mimetype VARBINARY(255) DEFAULT NULL,
file_storage_id VARBINARY(255) NOT NULL DEFAULT "DEFAULT",
file_key VARBINARY(16175) DEFAULT NULL,
checked_timestamp BIGINT NOT NULL DEFAULT 0
file_key VARBINARY(16000) DEFAULT NULL
);
-- no two files at the same path are allowed.
......@@ -68,54 +70,29 @@ ALTER TABLE entities MODIFY COLUMN `role` enum('RECORDTYPE','RECORD','FILE','DOM
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);
-- 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 files
(file_id, path, size, hash, checked_timestamp, mimetype, file_storage_id,
file_key, parent_directory)
VALUES (51, "", 0, NULL, 0, "inode/directory", "DEFAULT", "", NULL);
-- In the default file storage back-end the key is just the path.
UPDATE files SET file_key=path;
UPDATE archive_files SET file_key=path;
-- and now, set NOT NULL for the file_key column
ALTER TABLE files MODIFY COLUMN file_key VARBINARY(16175) NOT NULL;
ALTER TABLE archive_files MODIFY COLUMN file_key VARBINARY(16175) NOT NULL;
ALTER TABLE files MODIFY COLUMN file_key VARBINARY(16000) NOT NULL;
ALTER TABLE archive_files MODIFY COLUMN file_key VARBINARY(16000) NOT NULL;
-- Size may be NULL for directories
ALTER TABLE files MODIFY COLUMN size BIGINT UNSIGNED NULL DEFAULT NULL;
ALTER TABLE archive_files MODIFY COLUMN size BIGINT UNSIGNED NULL DEFAULT NULL;
-- More characters for long names
ALTER TABLE files MODIFY COLUMN path VARCHAR(16175) NOT NULL;
ALTER TABLE archive_files MODIFY COLUMN path VARCHAR(16175) NOT NULL;
-- Test data for the _create_dirs procedure...
-- INSERT INTO entities (id, role, acl) VALUES
-- (52, "FILE", 0),
-- (53, "FILE", 0),
-- (54, "FILE", 0),
-- (55, "FILE", 0),
-- (56, "FILE", 0),
-- (57, "FILE", 0),
-- (58, "FILE", 0),
-- (59, "FILE", 0),
-- (60, "FILE", 0);
-- INSERT INTO files
-- (file_id, path, size, hash, checked_timestamp, mimetype, file_storage_id,
-- file_key, parent_directory)
-- VALUES
-- (52, "file1", 0, NULL, 0, "bla", "DEFAULT", "", NULL),
-- (53, "file2", 0, NULL, 0, "bla", "DEFAULT", "", NULL),
-- (54, "A/B/file3", 0, NULL, 0, "bla", "DEFAULT", "", NULL),
-- (55, "A/B/file4", 0, NULL, 0, "bla", "DEFAULT", "", NULL),
-- (56, "A/B/C/file5", 0, NULL, 0, "bla", "DEFAULT", "", NULL),
-- (57, "A/B/C/file6", 0, NULL, 0, "bla", "DEFAULT", "", NULL),
-- (58, "B/C/D/file7", 0, NULL, 0, "bla", "DEFAULT", "", NULL),
-- (59, "B/C/D/file8", 0, NULL, 0, "bla", "DEFAULT", "", NULL),
-- (60, "B/C/file9", 0, NULL, 0, "bla", "DEFAULT", "", NULL);
ALTER TABLE files MODIFY COLUMN path VARCHAR(16000) NOT NULL;
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 files
(file_id, path, checked_timestamp, mimetype, file_storage_id,
file_key, parent_directory)
VALUES (51, "", 0, "inode/directory", "DEFAULT", "", NULL);
DROP PROCEDURE IF EXISTS _create_dirs;
DELIMITER //
......@@ -188,9 +165,9 @@ BEGIN
INSERT INTO entities (description, role, acl) VALUES (NULL, "DIRECTORY", 0);
SET dir_id = LAST_INSERT_ID();
-- ... then insert the FSODescriptor
INSERT INTO files (file_id, path, size, hash, checked_timestamp,
INSERT INTO files (file_id, path, checked_timestamp,
mimetype, file_storage_id, file_key, parent_directory)
VALUES (dir_id, dir_path_no_trailing_slash, 0, NULL, 0,
VALUES (dir_id, dir_path_no_trailing_slash, 0,
"inode/directory", "DEFAULT", dir_path_no_trailing_slash, parent_dir_id);
-- set the parent_dir_id for the next iteration
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment