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

FIX problems after merge of name_data changes from dev

parent 6cf1905b
Branches
Tags
No related merge requests found
Showing
with 120 additions and 122 deletions
...@@ -36,6 +36,40 @@ ...@@ -36,6 +36,40 @@
be lost afterwards.** And no, there is *no* additional prompt to ask if you be lost afterwards.** And no, there is *no* additional prompt to ask if you
are sure. If you `make drop-...`, you *actually* delete the database. are sure. If you `make drop-...`, you *actually* delete the database.
## Versioning
The versioning feature is still experimental. Therefore it is possible to turn
if on and off with a patch file and a special property.
### Procedures and Functions
The procedures which need to behave differently if the versioning is on or off
check the return value of `is_feature_config("ENTITY_VERSIONING", "ENABLED")`.
The `is_feature_config` function checks the `feature_config` table, which is
a key-value store.
Turn off versioning: Run `UPDATE feature_config SET _value = "DISABLED" WHERE
_key = "ENTITY_VERSIONING";` on your database.
Turn on versioning again: Run `UPDATE feature_config SET _value = "ENABLED"
WHERE _key = "ENTITY_VERSIONING";` on your database.
### Data
When the versioning patch is installed, the versioning is turned on by default
and all old entities become versioned entities with their current version as
the oldest known version. That is, they all need an entry in the
`entity_version` table. These entries are generated by the `_fix_unversioned`
procedure.
If you want to turn off the versioning for the time being you can just turn it
off for the procedures as described above. You should also empty the
`entity_version` table because the `_fix_unversioned` procedure is only
designed to cope with entities which do not have any versioning information at
all. The already recorded versioning information is of course lost then! If you
switch on the versioning at a some point in the future, the history begins anew
with the then current version of the stored entities.
## Unit tests ## Unit tests
* We use [MyTAP-1.0](https://hepabolu.github.io/mytap/) for unit tests. * We use [MyTAP-1.0](https://hepabolu.github.io/mytap/) for unit tests.
......
...@@ -106,7 +106,3 @@ END; ...@@ -106,7 +106,3 @@ END;
// //
delimiter ; delimiter ;
CALL _fix_unversioned();
DROP PROCEDURE _fix_unversioned;
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
# ** end header # ** end header
# #
# new entity_version table # new entity_version table
# Update mysql schema to version v3.0.0 # Update mysql schema to version v3.0.0-rc2
NEW_VERSION="v3.0.0" NEW_VERSION="v3.0.0-rc2"
OLD_VERSION="v2.1.2" OLD_VERSION="v3.0.0-rc1"
if [ -z "$UTILSPATH" ]; then if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils" UTILSPATH="../utils"
...@@ -38,7 +38,10 @@ check_version $OLD_VERSION ...@@ -38,7 +38,10 @@ check_version $OLD_VERSION
mysql_execute_file $PATCH_DIR/feature_config.sql mysql_execute_file $PATCH_DIR/feature_config.sql
mysql_execute_file $PATCH_DIR/versioning.sql mysql_execute_file $PATCH_DIR/versioning.sql
mysql_execute_file $PATCH_DIR/fix_unversioned.sql mysql_execute_file $PATCH_DIR/fix_unversioned.sql
mysql_execute "CALL _fix_unversioned()"
mysql_execute "DROP PROCEDURE _fix_unversioned"
update_version $NEW_VERSION update_version $NEW_VERSION
......
...@@ -282,7 +282,6 @@ CREATE TABLE archive_files ( ...@@ -282,7 +282,6 @@ CREATE TABLE archive_files (
CREATE TABLE archive_entities ( CREATE TABLE archive_entities (
id INT UNSIGNED NOT NULL, id INT UNSIGNED NOT NULL,
name VARCHAR(255) DEFAULT NULL,
description TEXT DEFAULT NULL, description TEXT DEFAULT NULL,
role ENUM('RECORDTYPE','RECORD','FILE','DOMAIN', role ENUM('RECORDTYPE','RECORD','FILE','DOMAIN',
'PROPERTY','DATATYPE','ROLE','QUERYTEMPLATE') NOT NULL, 'PROPERTY','DATATYPE','ROLE','QUERYTEMPLATE') NOT NULL,
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
*
* 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/>.
*
* ** end header
*/
#-- getFile(ID);
#--
#--
#-- FileID,
#-- FilePath,
#-- FileSize,
#-- FileHash,
#-- FileDescription,
#-- FileCreated,
#-- FileCreator,
#-- FileGenerator,
#-- FileOwner,
#-- FilePermission,
#-- FileChecksum
Drop Procedure if exists db_2_0.getFile;
Delimiter //
Create Procedure db_2_0.getFile (in FileID INT)
BEGIN
Select name, description, role into @name, @description, @role from entities where id=FileID LIMIT 1;
IF @role = 'file' Then
Select path, hash, size into @FilePath, @FileHash, @FileSize from files where file_id=FileID LIMIT 1;
Select timestamp, user_id, user_agent into @FileCreated, @FileCreator, @FileGenerator from history where entity_id=FileID AND event='insertion' LIMIT 1;
Select
FileID as FileID,
@FilePath as FilePath,
@FileSize as FileSize,
@FileHash as FileHash,
@FileDescription as FileDescription,
@FileCreated as FileCreated,
@FileCreator as FileCreator,
@FileGenerator as FileGenerator,
NULL as FileOwner,
NULL as FilePermission,
NULL as FileChecksum;
END IF;
END;
//
delimiter ;
...@@ -38,8 +38,8 @@ BEGIN ...@@ -38,8 +38,8 @@ BEGIN
SELECT COUNT(id) INTO ED FROM entities WHERE Role='DOMAIN' AND id!=0; SELECT COUNT(id) INTO ED FROM entities WHERE Role='DOMAIN' AND id!=0;
WHILE ED < amount DO WHILE ED < amount DO
INSERT INTO entities (name, description, role, acl) VALUES INSERT INTO entities (description, role, acl) VALUES
(NULL, "Multipurpose subdomain", 'DOMAIN', 0); (NULL, 'DOMAIN', 0);
SET ED = ED + 1; SET ED = ED + 1;
END WHILE; END WHILE;
......
...@@ -93,10 +93,19 @@ retrieveEntityBody: BEGIN ...@@ -93,10 +93,19 @@ retrieveEntityBody: BEGIN
LIMIT 1; LIMIT 1;
Select Select
(SELECT Name FROM entities WHERE id=DatatypeID) AS Datatype, ( SELECT value FROM
( SELECT value FROM name_data
WHERE domain_id = 0
AND entity_ID = DatatypeID
AND property_id = 20
UNION SELECT DatatypeID AS value
) AS tmp LIMIT 1 ) AS Datatype,
CollectionName AS Collection, CollectionName AS Collection,
EntityID AS EntityID, EntityID AS EntityID,
e.name AS EntityName, ( SELECT value FROM archive_name_data
WHERE domain_id = 0
AND entity_ID = EntityID
AND property_id = 20 LIMIT 1) AS EntityName,
e.description AS EntityDesc, e.description AS EntityDesc,
e.role AS EntityRole, e.role AS EntityRole,
FileSize AS FileSize, FileSize AS FileSize,
...@@ -118,40 +127,46 @@ retrieveEntityBody: BEGIN ...@@ -118,40 +127,46 @@ retrieveEntityBody: BEGIN
END IF; END IF;
Select path, size, hex(hash) Select path, size, hex(hash)
into FilePath, FileSize, FileHash INTO FilePath, FileSize, FileHash
from files FROM files
where file_id = EntityID WHERE file_id = EntityID
LIMIT 1; LIMIT 1;
Select datatype into DatatypeID Select datatype INTO DatatypeID
from data_type FROM data_type
where domain_id=0 WHERE domain_id=0
and entity_id=0 AND entity_id=0
and property_id=EntityID AND property_id=EntityID
LIMIT 1; LIMIT 1;
SELECT collection into CollectionName SELECT collection INTO CollectionName
from collection_type FROM collection_type
where domain_id=0 WHERE domain_id=0
and entity_id=0 AND entity_id=0
and property_id=EntityID AND property_id=EntityID
LIMIT 1; LIMIT 1;
Select Select
(Select name from entities where id=DatatypeID) as Datatype, ( SELECT value FROM name_data
CollectionName as Collection, WHERE domain_id = 0
EntityID as EntityID, AND entity_ID = DatatypeID
e.name as EntityName, AND property_id = 20 LIMIT 1 ) AS Datatype,
e.description as EntityDesc, CollectionName AS Collection,
e.role as EntityRole, EntityID AS EntityID,
FileSize as FileSize, ( SELECT value FROM name_data
FilePath as FilePath, WHERE domain_id = 0
FileHash as FileHash, AND entity_ID = EntityID
(SELECT acl FROM entity_acl as a WHERE a.id = e.acl) as ACL, AND property_id = 20 LIMIT 1) AS EntityName,
Version as Version, e.description AS EntityDesc,
VersionSeconds as VersionSeconds, e.role AS EntityRole,
VersionNanos as VersionNanos FileSize AS FileSize,
from entities e where id = EntityID LIMIT 1; FilePath AS FilePath,
FileHash AS FileHash,
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL,
Version AS Version,
VersionSeconds AS VersionSeconds,
VersionNanos AS VersionNanos
FROM entities e WHERE id = EntityID LIMIT 1;
END; END;
// //
......
...@@ -86,8 +86,13 @@ retrieveOverridesBody: BEGIN ...@@ -86,8 +86,13 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override, NULL AS collection_override,
NULL AS name_override, NULL AS name_override,
NULL AS desc_override, NULL AS desc_override,
(Select name FROM entities WHERE id=datatype LIMIT 1) ( SELECT value FROM
AS type_override, ( SELECT value FROM name_data
WHERE domain_id = 0
AND entity_ID = datatypeID
AND property_id = 20
UNION SELECT datatype AS value
) AS tmp LIMIT 1 ) AS type_override,
entity_id, entity_id,
property_id property_id
FROM archive_data_type FROM archive_data_type
...@@ -144,7 +149,10 @@ retrieveOverridesBody: BEGIN ...@@ -144,7 +149,10 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override, NULL AS collection_override,
NULL AS name_override, NULL AS name_override,
NULL AS desc_override, NULL AS desc_override,
(Select name FROM entities WHERE id=datatype LIMIT 1) AS type_override, ( SELECT value FROM name_data
WHERE domain_id = 0
AND entity_ID = datatype
AND property_id = 20 LIMIT 1 ) AS type_override,
entity_id, entity_id,
property_id property_id
FROM data_type FROM data_type
......
...@@ -77,7 +77,10 @@ retrieveEntityParentsBody: BEGIN ...@@ -77,7 +77,10 @@ retrieveEntityParentsBody: BEGIN
SELECT SELECT
i.parent AS ParentID, i.parent AS ParentID,
e.name AS ParentName, ( SELECT value FROM archive_name_data
WHERE domain_id = 0
AND entity_id = ParentID
AND property_id = 20 ) AS ParentName,
e.description AS ParentDescription, e.description AS ParentDescription,
e.role AS ParentRole, e.role AS ParentRole,
(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
...@@ -93,7 +96,10 @@ retrieveEntityParentsBody: BEGIN ...@@ -93,7 +96,10 @@ retrieveEntityParentsBody: BEGIN
SELECT SELECT
i.parent AS ParentID, i.parent AS ParentID,
e.name AS ParentName, ( SELECT value FROM name_data
WHERE domain_id = 0
AND entity_id = ParentID
AND property_id = 20 ) AS ParentName,
e.description AS ParentDescription, e.description AS ParentDescription,
e.role AS ParentRole, e.role AS ParentRole,
(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
......
...@@ -173,6 +173,7 @@ retrieveEntityPropertiesBody: BEGIN ...@@ -173,6 +173,7 @@ retrieveEntityPropertiesBody: BEGIN
FROM archive_name_data FROM archive_name_data
WHERE domain_id = DomainID WHERE domain_id = DomainID
AND entity_id = EntityID AND entity_id = EntityID
AND property_id != 20
AND _iversion = IVersion; AND _iversion = IVersion;
LEAVE retrieveEntityPropertiesBody; LEAVE retrieveEntityPropertiesBody;
...@@ -286,7 +287,8 @@ retrieveEntityPropertiesBody: BEGIN ...@@ -286,7 +287,8 @@ retrieveEntityPropertiesBody: BEGIN
pidx AS PropertyIndex pidx AS PropertyIndex
FROM name_data FROM name_data
WHERE domain_id = DomainID WHERE domain_id = DomainID
AND entity_id = EntityID; AND entity_id = EntityID
AND property_id != 20;
END; END;
......
...@@ -116,7 +116,6 @@ BEGIN ...@@ -116,7 +116,6 @@ BEGIN
WHERE domain_id=0 AND entity_id=0 AND property_id=EntityID; WHERE domain_id=0 AND entity_id=0 AND property_id=EntityID;
IF Datatype IS NOT NULL THEN IF Datatype IS NOT NULL THEN
INSERT INTO data_type (domain_id, entity_id, property_id, datatype)
INSERT INTO data_type (domain_id, entity_id, property_id, datatype) INSERT INTO data_type (domain_id, entity_id, property_id, datatype)
SELECT 0, 0, EntityID, SELECT 0, 0, EntityID,
( SELECT entity_id FROM name_data WHERE domain_id = 0 ( SELECT entity_id FROM name_data WHERE domain_id = 0
......
../patches/patch20200710-3.0.0-rc2/fix_unversioned.sql
\ No newline at end of file
...@@ -21,10 +21,10 @@ INSERT INTO transactions (srid,seconds,nanos,username,realm) VALUES ...@@ -21,10 +21,10 @@ INSERT INTO transactions (srid,seconds,nanos,username,realm) VALUES
("SRIDbla", 1234, 2345, "me", "home"), ("SRIDbla", 1234, 2345, "me", "home"),
("SRIDblub", 2345, 3465, "me", "home"), ("SRIDblub", 2345, 3465, "me", "home"),
("SRIDblieb", 3456, 4576, "you", "home"); ("SRIDblieb", 3456, 4576, "you", "home");
DELETE FROM entities WHERE name="EntityName"; DELETE FROM entities WHERE id > 99;
CALL entityACL(@ACLID1, "{acl1}"); CALL entityACL(@ACLID1, "{acl1}");
CALL insertEntity("EntityName", "EntityDesc", "RECORDTYPE", "{acl1}"); CALL insertEntity("EntityName", "EntityDesc", "RECORDTYPE", "{acl1}");
SELECT id INTO @EntityID FROM entities WHERE name="EntityName"; SELECT entity_id INTO @EntityID FROM name_data WHERE value="EntityName";
-- TEST insert_single_child_version -- TEST insert_single_child_version
...@@ -67,8 +67,9 @@ SELECT count(*) INTO @x FROM entity_version; ...@@ -67,8 +67,9 @@ SELECT count(*) INTO @x FROM entity_version;
SELECT tap.eq(@x, 0, "no versions there any more"); SELECT tap.eq(@x, 0, "no versions there any more");
-- TEARDOWN clean up a litte -- TEARDOWN clean up
DELETE FROM entities WHERE name="EntityName"; DELETE FROM name_data WHERE entity_id > 99;
DELETE FROM entities WHERE id > 99;
-- ##################################################################### -- #####################################################################
-- TEST the call of insert_single_child_version from within insertEntity -- TEST the call of insert_single_child_version from within insertEntity
...@@ -82,9 +83,9 @@ SELECT tap.eq(@x, 0, "before insertEntity, no versions there"); ...@@ -82,9 +83,9 @@ SELECT tap.eq(@x, 0, "before insertEntity, no versions there");
-- TEST insertEntity - should produce a version w/o parent -- TEST insertEntity - should produce a version w/o parent
SET @SRID = "SRIDbla"; SET @SRID = "SRIDbla";
CALL insertEntity("EntityName", "EntityDesc", "RECORDTYPE", "{acl1}"); CALL insertEntity("EntityName", "EntityDesc", "RECORDTYPE", "{acl1}");
SELECT id INTO @EntityID FROM entities WHERE name="EntityName"; SELECT entity_id INTO @EntityID FROM name_data WHERE value="EntityName";
CALL insertEntity("ParentName", "ParentDesc", "RECORDTYPE", "{acl1}"); CALL insertEntity("ParentName", "ParentDesc", "RECORDTYPE", "{acl1}");
SELECT id INTO @ParentID FROM entities WHERE name="ParentName"; SELECT entity_id INTO @ParentID FROM name_data WHERE value="ParentName";
CALL insertIsa(@EntityID, @ParentID); CALL insertIsa(@EntityID, @ParentID);
CALL insertEntityProperty(0, @EntityID, 17, "null_data", NULL, NULL, CALL insertEntityProperty(0, @EntityID, 17, "null_data", NULL, NULL,
"RECOMMENDED", NULL, "DescOverride", NULL, NULL, 0); "RECOMMENDED", NULL, "DescOverride", NULL, NULL, 0);
...@@ -189,7 +190,7 @@ DELETE FROM feature_config WHERE _key = "ENTITY_VERSIONING"; ...@@ -189,7 +190,7 @@ DELETE FROM feature_config WHERE _key = "ENTITY_VERSIONING";
CALL entityACL(@ACLID1, "{acl1}"); CALL entityACL(@ACLID1, "{acl1}");
CALL insertEntity("EntityName", "EntityDesc", "RECORDTYPE", "{acl1}"); CALL insertEntity("EntityName", "EntityDesc", "RECORDTYPE", "{acl1}");
SELECT count(*) INTO @NumOfEntities FROM entities; SELECT count(*) INTO @NumOfEntities FROM entities;
SELECT id INTO @EntityID FROM entities WHERE name="EntityName"; SELECT entity_id INTO @EntityID FROM name_data WHERE value="EntityName";
SET @TheUser = "TheUser"; -- used to identify the matching entry in transaction_log SET @TheUser = "TheUser"; -- used to identify the matching entry in transaction_log
-- fill transaction_log: one entity with two updates (and one insert) and another entity with insert and delete. -- fill transaction_log: one entity with two updates (and one insert) and another entity with insert and delete.
...@@ -243,8 +244,8 @@ CALL entityACL(@ACLID1, "{acl1}"); ...@@ -243,8 +244,8 @@ CALL entityACL(@ACLID1, "{acl1}");
CALL insertEntity("EntityName1", "EntityDesc1", "RECORDTYPE", "{acl1}"); CALL insertEntity("EntityName1", "EntityDesc1", "RECORDTYPE", "{acl1}");
CALL insertEntity("EntityName2", "EntityDesc2", "RECORDTYPE", "{acl1}"); CALL insertEntity("EntityName2", "EntityDesc2", "RECORDTYPE", "{acl1}");
SELECT count(*) INTO @NumOfEntities FROM entities; SELECT count(*) INTO @NumOfEntities FROM entities;
SELECT id INTO @EntityID1 FROM entities WHERE name="EntityName1"; SELECT entity_id INTO @EntityID1 FROM name_data WHERE value="EntityName1";
SELECT id INTO @EntityID2 FROM entities WHERE name="EntityName2"; SELECT entity_id INTO @EntityID2 FROM name_data WHERE value="EntityName2";
INSERT INTO transaction_log (transaction, entity_id, username, realm, seconds, INSERT INTO transaction_log (transaction, entity_id, username, realm, seconds,
nanos) nanos)
......
...@@ -56,7 +56,7 @@ function _execute_tests () { ...@@ -56,7 +56,7 @@ function _execute_tests () {
for tfile in $TESTS ; do for tfile in $TESTS ; do
echo "Running $tfile" echo "Running $tfile"
echo "----- $tfile -----" >> .TEST_RESULTS echo "----- $tfile -----" >> .TEST_RESULTS
cat $tfile | $MYSQL_CMD $(get_db_args_nodb) --disable-pager --batch --raw --skip-column-names --unbuffered >> .TEST_RESULTS 2>&1 cat $tfile | $MYSQL_CMD -D $UNITTEST_DATABASE $(get_db_args_nodb) --disable-pager --batch --raw --skip-column-names --unbuffered >> .TEST_RESULTS 2>&1
done; done;
popd popd
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment