Commit cbe51861 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added snake_case notation for the file catalog columns + minor fixes.

parent 0af4ce86
Loading
Loading
Loading
Loading
Loading
+35 −35
Original line number Diff line number Diff line
@@ -32,55 +32,55 @@ CREATE EXTENSION IF NOT EXISTS ltree;
CREATE TYPE NodeType AS ENUM ('container', 'data', 'link');

CREATE TABLE Node (
    nodeID           BIGSERIAL     NOT NULL,
    parentPath       LTREE         default NULL,
    node_id           BIGSERIAL     NOT NULL,
    parent_path       LTREE         default NULL,
    name              VARCHAR       NOT NULL,
    type              NodeType      NOT NULL,
    format            VARCHAR       default NULL,
    -- format serve per distinguere unstuctured (format=NULL) da structured che hanno un formato noto
    asyncTrans       BOOLEAN       default NULL,
    -- asyncTransf serve per indicare se il nodo e` ospitato da un cold storage e deve essere necessariamente 
    async_trans       BOOLEAN       default NULL,
    -- async_trans serve per indicare se il nodo e` ospitato da un cold storage e deve essere necessariamente 
    -- trasferito con un trasferimento asincrono 
    busyState        BOOLEAN       default NULL,
    ownerID          VARCHAR       NOT NULL,
    creatorID        VARCHAR       NOT NULL,
    groupRead        VARCHAR[]     default NULL,
    groupWrite       VARCHAR[]     default NULL,
    isPublic         BOOLEAN       default NULL,
    busy_state        BOOLEAN       default NULL,
    owner_id          VARCHAR       NOT NULL,
    creator_id        VARCHAR       NOT NULL,
    group_read        VARCHAR[]     default NULL,
    group_write       VARCHAR[]     default NULL,
    is_public         BOOLEAN       default NULL,
    delta             BIGINT        default NULL,
    /* potrebbe essere un delta di dati trasferito durante un trasferimento asincrono.
       Dovrebbe stare sul servizio che fa il trasferimento  (es. redis) */
    contentType      VARCHAR       default NULL,
    contentEncoding  VARCHAR       default NULL,
    contentLength    BIGINT        default NULL,
    contentMD5       TEXT          default NULL,
    createdOn        TIMESTAMP     default CURRENT_TIMESTAMP,
    lastModified     TIMESTAMP     default NULL,
    content_type      VARCHAR       default NULL,
    content_encoding  VARCHAR       default NULL,
    content_length    BIGINT        default NULL,
    content_md5       TEXT          default NULL,
    created_on        TIMESTAMP     default CURRENT_TIMESTAMP,
    last_modified     TIMESTAMP     default NULL,
    -- link             TEXT          default NULL,
    acceptViews      TEXT[]        default NULL,
    provideViews     TEXT[]        default NULL,
    accept_views      TEXT[]        default NULL,
    provide_views     TEXT[]        default NULL,
    -- serve per mappare il nome del servizio di storage da interrogare per accedere al contenuto di questo nodo 
    -- storageID        VARCHAR,    
    -- storage_id       VARCHAR,    
    protocols         TEXT[]        default NULL,
    PRIMARY KEY (nodeID)
    PRIMARY KEY (node_id)
);


CREATE TABLE NodeProperty (
    nodeID           BIGSERIAL,
    propertyURI      VARCHAR       NOT NULL,
    propertyValue    VARCHAR       default NULL,
    lastModified     TIMESTAMP     default CURRENT_TIMESTAMP,
    node_id           BIGSERIAL,
    property_uri      VARCHAR       NOT NULL,
    property_value    VARCHAR       default NULL,
    last_modified     TIMESTAMP     default CURRENT_TIMESTAMP,
    -- support replication with a fake primary key
    -- _rep_support     BIGINT       NOT NULL PRIMARY KEY,
    foreign key (nodeID) references Node (nodeID)
    foreign key (node_id) references Node (node_id)
);


CREATE TABLE DeletedNode (
    nodeID           BIGSERIAL     NOT NULL,
    node_id           BIGSERIAL     NOT NULL,
    name              VARCHAR       NOT NULL,
    ownerID          VARCHAR       NOT NULL,
    lastModified     TIMESTAMP     default CURRENT_TIMESTAMP,
    PRIMARY KEY (nodeID)
    owner_id          VARCHAR       NOT NULL,
    last_modified     TIMESTAMP     default CURRENT_TIMESTAMP,
    PRIMARY KEY (node_id)
);
 No newline at end of file
+5 −5
Original line number Diff line number Diff line
@@ -3,14 +3,14 @@
    Email: sonia.zorba@inaf.it
*/

-- Generates the path from parentPath and id
CREATE OR REPLACE FUNCTION path(parentPath ltree, id bigint) RETURNS ltree AS
-- Generates the path from parent_path and id
CREATE OR REPLACE FUNCTION path(parent_path ltree, id bigint) RETURNS ltree AS
$func$
BEGIN
    RETURN text2ltree(CASE
        WHEN parentPath IS NULL THEN ''
        WHEN parentPath::varchar = '' THEN id::varchar
        ELSE (parentPath::varchar || '.' || id::varchar)
        WHEN parent_path IS NULL THEN ''
        WHEN parent_path::varchar = '' THEN id::varchar
        ELSE (parent_path::varchar || '.' || id::varchar)
    END);
END
$func$ LANGUAGE plpgsql IMMUTABLE; 
+4 −4
Original line number Diff line number Diff line
@@ -8,13 +8,13 @@ CREATE OR REPLACE FUNCTION get_ltree_path(input_os_path character varying) RETUR
BEGIN
    RETURN 
    ltree_path FROM (
        SELECT nodeID, string_agg(name, '/') AS os_path, first_value(path) over() ltree_path FROM (
            SELECT f1.name, f2.path, f2.nodeID
        SELECT node_id, string_agg(name, '/') AS os_path, first_value(path) over() ltree_path FROM (
            SELECT f1.name, f2.path, f2.node_id
            FROM Node f1 
            JOIN Node f2 ON f1.path @> f2.path
            WHERE f2.name = (string_to_array(input_os_path, '/'))[cardinality(string_to_array(input_os_path, '/'))]
            ORDER BY f2.nodeID, length(f1.path::varchar) ASC
        ) AS t1 GROUP BY nodeID, path
            ORDER BY f2.node_id, length(f1.path::varchar) ASC
        ) AS t1 GROUP BY node_id, path
    ) AS t2 WHERE os_path = input_os_path;
END;
$$ LANGUAGE plpgsql;
+3 −3
Original line number Diff line number Diff line
@@ -5,10 +5,10 @@

CREATE INDEX file_name_idx ON Node USING btree(name);

CREATE INDEX file_parent_path_gist_idx ON Node USING GIST(parentPath);
CREATE INDEX file_parent_path_idx ON Node USING btree(parentPath);
CREATE INDEX file_parent_path_gist_idx ON Node USING GIST(parent_path);
CREATE INDEX file_parent_path_idx ON Node USING btree(parent_path);

ALTER TABLE Node ADD COLUMN path ltree GENERATED ALWAYS AS (path(parentPath, nodeID)) STORED;
ALTER TABLE Node ADD COLUMN path ltree GENERATED ALWAYS AS (path(parent_path, node_id)) STORED;
CREATE INDEX file_path_gist_idx ON Node USING GIST(path);
CREATE UNIQUE INDEX file_path_idx ON Node USING btree(path);

+6 −6
Original line number Diff line number Diff line
@@ -3,19 +3,19 @@
    Email: sonia.zorba@inaf.it
*/

-- generate the os_path from the Node id
-- it could be used for initializing the os_path generated column
-- Generate the os_path from the Node id
-- It could be used for initializing the os_path generated column
CREATE OR REPLACE FUNCTION get_os_path(input_id int) RETURNS varchar AS
$func$
SELECT string_agg(name, '/') FROM (
    WITH RECURSIVE paths AS (
            SELECT nodeID, name, path, parentPath, 1 AS level
            SELECT node_id, name, path, parent_path, 1 AS level
            FROM Node
            WHERE nodeID = input_id
            WHERE node_id = input_id
        UNION ALL
            SELECT f.nodeID, f.name, f.path, f.parentPath, p.level + 1
            SELECT f.node_id, f.name, f.path, f.parent_path, p.level + 1
            FROM Node f
            INNER JOIN paths p ON p.parentPath = f.path
            INNER JOIN paths p ON p.parent_path = f.path
    ) SELECT name FROM paths ORDER BY LEVEL DESC
) AS names;
$func$ LANGUAGE sql;
Loading