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

Merge branch 'f-fix-server-85' into 'dev'

Fix self-inheritance in cache table

See merge request caosdb/caosdb-mysqlbackend!10
parents 079cf7b8 2471f53a
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright 2019 Daniel Hornung # Copyright (C) 2019-2020 Daniel Hornung
# Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -101,7 +102,8 @@ while test $# -gt 0; do ...@@ -101,7 +102,8 @@ while test $# -gt 0; do
esac esac
done done
source "$ENV_FILE" || true [[ -e "$ENV_FILE" ]] && source "$ENV_FILE" \
|| echo "No ENV_FILE in environment or not found: $ENV_FILE"
if [[ -z "$DATABASE_NAME" && -z "$MYSQL_CONNECTION" ]] if [[ -z "$DATABASE_NAME" && -z "$MYSQL_CONNECTION" ]]
then then
...@@ -187,6 +189,17 @@ function mysql_execute { ...@@ -187,6 +189,17 @@ function mysql_execute {
set -e set -e
} }
# Takes a filename with commands instead of command line arguments
function mysql_execute_file {
set +e
$CMD_MYSQL $MYSQL_CONNECTION < "$1"
ret=${PIPESTATUS[0]}
if [ "$ret" -ne 0 ]; then
failure "MYSQL ERROR"
fi
set -e
}
function redo_table { function redo_table {
$CMD_MYSQL $MYSQL_CONNECTION < ${DATABASE_NAME}.${1}.${OLD_VERSION}.dump.sql $CMD_MYSQL $MYSQL_CONNECTION < ${DATABASE_NAME}.${1}.${OLD_VERSION}.dump.sql
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -21,11 +22,18 @@ ...@@ -21,11 +22,18 @@
* ** end header * ** end header
*/ */
/* Delete a (sparse) Entity from the database.
Note that all properties, including is-a relationships of this Entity should
have been deleted before. This can be done for example with the
`deleteEntityProperties` procedure.
Parameters
==========
EntityID : UNSIGNED
The ID of the Entity.
*/
DROP PROCEDURE IF EXISTS db_2_0.deleteEntity; DROP PROCEDURE IF EXISTS db_2_0.deleteEntity;
delimiter // delimiter //
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -25,6 +26,19 @@ SET GLOBAL log_bin_trust_function_creators = 1; ...@@ -25,6 +26,19 @@ SET GLOBAL log_bin_trust_function_creators = 1;
DROP PROCEDURE IF EXISTS db_2_0.deleteIsa; DROP PROCEDURE IF EXISTS db_2_0.deleteIsa;
DELIMITER // DELIMITER //
/* Delete "is a" relations from the given entity towards ancestors.
Note that relations towards descendants are not deleted (they probably should have been deleted before).
After this procedure, there are no more entries in `isa_cache`, where the
parameter entity is a child or inside the rpath.
Parameters
==========
EntityID : UNSIGNED
Child entity for which all parental relations should be deleted.
*/
CREATE PROCEDURE db_2_0.deleteIsa(IN EntityID INT UNSIGNED) CREATE PROCEDURE db_2_0.deleteIsa(IN EntityID INT UNSIGNED)
BEGIN BEGIN
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -24,6 +25,21 @@ ...@@ -24,6 +25,21 @@
DROP PROCEDURE IF EXISTS db_2_0.insertEntity; DROP PROCEDURE IF EXISTS db_2_0.insertEntity;
delimiter // delimiter //
/* Insert an Entity
Parameters
==========
EntityName : VARCHAR(255)
EntityDesc : TEXT
EntityRole : VARCHAR(255)
Currently one of 'RECORDTYPE', 'RECORD', 'FILE', 'DOMAIN', 'PROPERTY',
'DATATYPE', 'ROLE', 'QUERYTEMPLATE'
ACL : VARBINARY(65525)
*/
CREATE PROCEDURE db_2_0.insertEntity(in EntityName VARCHAR(255), in EntityDesc TEXT, in EntityRole VARCHAR(255), in ACL VARBINARY(65525)) CREATE PROCEDURE db_2_0.insertEntity(in EntityName VARCHAR(255), in EntityDesc TEXT, in EntityRole VARCHAR(255), in ACL VARBINARY(65525))
BEGIN BEGIN
DECLARE NewEntityID INT UNSIGNED DEFAULT NULL; DECLARE NewEntityID INT UNSIGNED DEFAULT NULL;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -23,42 +24,61 @@ ...@@ -23,42 +24,61 @@
DROP PROCEDURE IF EXISTS db_2_0.insertIsa; DROP PROCEDURE IF EXISTS db_2_0.insertIsa;
DELIMITER // DELIMITER //
/* Insert an "is a" relation
This procedure fills the isa_cache table. All passed entities must be existing
in entities.id.
Parameters
==========
c : UNSIGNED
The child entity
p : UNSIGNED
The parent entity
*/
CREATE PROCEDURE db_2_0.insertIsa(IN c INT UNSIGNED, IN p INT UNSIGNED) CREATE PROCEDURE db_2_0.insertIsa(IN c INT UNSIGNED, IN p INT UNSIGNED)
BEGIN insert_is_a_proc: BEGIN
INSERT INTO isa_cache (child, parent, rpath) VALUES (c,p,c); INSERT INTO isa_cache (child, parent, rpath) VALUES (c, p, c);
-- foreach supertype of p IF p = c THEN
-- Any additional entries would be redundant.
LEAVE insert_is_a_proc;
END IF;
-- Insert ancestors older than parents:
-- for each supertype of p
-- INSERT (c, supertype, p); -- INSERT (c, supertype, p);
INSERT IGNORE INTO isa_cache SELECT INSERT IGNORE INTO isa_cache SELECT
c c
AS child, AS child, -- Current child
i.parent i.parent
AS parent, AS parent, -- Existing supertype
IF(p=i.rpath or i.rpath=parent, IF(p=i.rpath or i.rpath=parent, -- If ancestor=parent or parent = grandparent:
p, p, -- New parent (directly)
concat(p, ">", i.rpath)) concat(p, ">", i.rpath)) -- Else "p>super.rpath"
AS rpath AS rpath
FROM isa_cache AS i WHERE i.child = p; FROM isa_cache AS i WHERE i.child = p; -- Select rows with supertype
-- foreach subtype of c insert each supertype of p -- Propagate to descendants:
-- for each subtype of c: insert each supertype of p
INSERT IGNORE INTO isa_cache SELECT INSERT IGNORE INTO isa_cache SELECT
l.child, l.child, -- Descendant as found in isa_cache
r.parent, r.parent, -- Ancestor as found in isa_cache
if(l.rpath=l.child and r.rpath=c, if(l.rpath=l.child and r.rpath=c, -- if distance=1 for left and right:
c, c, -- rpath = current child
concat(if(l.rpath=l.child, concat(if(l.rpath=l.child, -- if dist=1 for descendant:
c, c, -- rpath starts with c
concat(l.rpath, '>', c)), concat(l.rpath, '>', c)), -- rpath starts with "desc.rpath > c"
if(r.rpath=c, if(r.rpath=c, -- if dist=1 for ancestor
'', '', -- rpath is finished
concat('>', r.rpath)))) concat('>', r.rpath)))) -- rpath continuees with " > ancest.rpath"
AS rpath AS rpath
FROM isa_cache as l FROM
INNER JOIN isa_cache as r ON (l.parent = r.child AND l.parent=c); isa_cache as l INNER JOIN isa_cache as r
ON (l.parent = c AND c = r.child); -- Left: descendants of c, right: ancestors
END; END;
// //
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -23,8 +24,33 @@ ...@@ -23,8 +24,33 @@
DROP PROCEDURE IF EXISTS db_2_0.retrieveEntityParents; DROP PROCEDURE IF EXISTS db_2_0.retrieveEntityParents;
delimiter // DELIMITER //
/* Retrieve the parents of an Entity.
Parameters
==========
EntityID : UNSIGNED
Child entity for which all parental relations should be deleted.
Returns
=======
ParentID : INT UNSIGNED
Each parent's ID
ParentName :
The parent's name.
ParentDescription :
The parent's description.
ParentRole :
The parent's Role.
ACL :
Access control list something
*/
CREATE PROCEDURE db_2_0.retrieveEntityParents(in EntityID INT UNSIGNED) CREATE PROCEDURE db_2_0.retrieveEntityParents(in EntityID INT UNSIGNED)
BEGIN BEGIN
...@@ -32,6 +58,7 @@ SELECT parent AS ParentID, name AS ParentName, description AS ParentDescription, ...@@ -32,6 +58,7 @@ SELECT parent AS ParentID, name AS ParentName, description AS ParentDescription,
END
//
END// DELIMITER ;
delimiter ;
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -29,11 +30,22 @@ source patches/utils/patch_header.sh ...@@ -29,11 +30,22 @@ source patches/utils/patch_header.sh
echo -n "updating rules ... " echo -n "updating rules ... "
set -e set -e
mysql_execute "$(sed s/db_2_0/$DATABASE_NAME/g rules.sql)" temp_rules_sql=$(tempfile --suffix=.sql)
sed s/db_2_0/$DATABASE_NAME/g rules.sql > "$temp_rules_sql"
mysql_execute_file "$temp_rules_sql"
# We keep this for debugging purposes...
# rm "$temp_rules_sql"
echo "[OK]" echo "[OK]"
echo -n "updating procedures ... " echo -n "updating procedures ... "
mysql_execute "$(sed s/db_2_0/$DATABASE_NAME/g procedures/*.sql procedures/query/*.sql)" temp_proc_sql=$(tempfile --suffix=.sql)
sed -e "s/db_2_0/$DATABASE_NAME/g" procedures/*.sql procedures/query/*.sql \
> "$temp_proc_sql"
mysql_execute_file "$temp_proc_sql"
# We keep this for debugging purposes...
# rm "$temp_proc_sql"
success success
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment