diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dfbaf119f3aaef061aa76b7547c5f4f54d46e004..5a3f06c0068b199f00d8bc395b1e9a5e0d03e0ba 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,6 +22,7 @@ services: - mariadb:10.2 variables: + DEPLOY_REF: dev CI_REGISTRY_IMAGE: $CI_REGISTRY/caosdb/caosdb-mysqlbackend/testenv:latest MYSQL_ROOT_PASSWORD: caosdb1234 @@ -38,10 +39,11 @@ trigger_build: script: - /usr/bin/curl -X POST -F token=$DEPLOY_TRIGGER_TOKEN + -F "variables[F_BRANCH]=$CI_COMMIT_REF_NAME" -F "variables[MYSQLBACKEND]=$CI_COMMIT_REF_NAME" -F "variables[TriggerdBy]=MYSQLBACKEND" -F "variables[TriggerdByHash]=$CI_COMMIT_SHORT_SHA" - -F ref=dev https://gitlab.indiscale.com/api/v4/projects/14/trigger/pipeline + -F ref=$DEPLOY_REF https://gitlab.indiscale.com/api/v4/projects/14/trigger/pipeline unittests: tags: [ docker ] diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a54a853961591182de86aa3ecbb52c2d0d07c57..e1e47cc3fb77bba21850528c07f079176edbf77b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). @@ -16,4 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### +* POV with the 'name' property, e.g. `FIND ENTITY WITH name = something` + [caosdb-server#51](https://gitlab.com/caosdb/caosdb-server/-/issues/51) - Fixed several bugs when an Entity inherits from itself (#18, caosdb-server #85). + +### Security ### diff --git a/patches/patch20200615-3.0.0rc1/move_names.sql b/patches/patch20200615-3.0.0rc1/move_names.sql new file mode 100644 index 0000000000000000000000000000000000000000..872256f3892fc999e271556b62df2c1fedaddafb --- /dev/null +++ b/patches/patch20200615-3.0.0rc1/move_names.sql @@ -0,0 +1,38 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> + * + * 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/>. + */ + +/* + * This patch moves all names of existing entities from the entities table into + * the name_data table. + */ + + +-- unique key adds savety in writing transactions and performance in reading +-- transactions. +ALTER TABLE name_data ADD UNIQUE KEY (domain_id, entity_id, property_id); + +-- copy names of old entities. 20 is the (hard-coded) id of the name property +-- itself. status is "FIX" because names are not to be inherited (by default). +-- pidx 0 is irrelevant here because the primary names have no "order" in which +-- they appear. +INSERT INTO name_data (domain_id, entity_id, property_id, value, status, pidx) SELECT 0, id, 20, name, "FIX", 0 FROM entities WHERE name IS NOT NULL; + +-- delete the name column and effectively all the names from entities table. +ALTER TABLE entities DROP COLUMN name; diff --git a/patches/patch20200615-3.0.0rc1/patch.sh b/patches/patch20200615-3.0.0rc1/patch.sh new file mode 100755 index 0000000000000000000000000000000000000000..315ede2d8d2b0cabf9a26d365db8cc0e2e583b90 --- /dev/null +++ b/patches/patch20200615-3.0.0rc1/patch.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# +# ** 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 +# + +# Refactors the entities table and move all names to name_data +# Update mysql schema to version v3.0.0-rc1 +NEW_VERSION="v3.0.0-rc1" +OLD_VERSION="v2.1.2" + +if [ -z "$UTILSPATH" ]; then + UTILSPATH="../utils" +fi + +. $UTILSPATH/patch_header.sh $* + + +check_version $OLD_VERSION + +mysql_execute_file $PATCH_DIR/move_names.sql + +update_version $NEW_VERSION + +success + diff --git a/procedures/insertEntity.sql b/procedures/insertEntity.sql index 8e307a840ebf4a8ec0a04b2753457bcce49f48b1..cfe5700855540c7b8fa67f8bfe0cc98761ac5ec1 100644 --- a/procedures/insertEntity.sql +++ b/procedures/insertEntity.sql @@ -45,11 +45,25 @@ BEGIN DECLARE NewEntityID INT UNSIGNED DEFAULT NULL; DECLARE NewACLID INT UNSIGNED DEFAULT NULL; + -- insert the acl. the new acl id is being written (c-style) into the + -- variable NewACLID. call entityACL(NewACLID, ACL); - INSERT INTO entities (name, description, role, acl) VALUES (EntityName, EntityDesc, EntityRole, NewACLID); + -- insert the description, role, and acl into entities table... + INSERT INTO entities (description, role, acl) + VALUES (EntityDesc, EntityRole, NewACLID); + + -- ... and return the generated id SET NewEntityID = LAST_INSERT_ID(); + -- insert the name of the entity into name_data table + -- 20 is the (hard-coded) id of the 'name' property. + IF EntityName IS NOT NULL THEN + INSERT INTO name_data + (domain_id, entity_id, property_id, value, status, pidx) + VALUES (0, NewEntityID, 20, EntityName, "FIX", 0); + END IF; + Select NewEntityID as EntityID; END; diff --git a/procedures/query/applyPOV.sql b/procedures/query/applyPOV.sql index eefee066d8b72b7d13cc24ec6c56fa5b6150f061..bf49d930a7daab9d1cd81de482b5dc6d8dd4f462 100644 --- a/procedures/query/applyPOV.sql +++ b/procedures/query/applyPOV.sql @@ -55,6 +55,7 @@ CREATE PROCEDURE db_2_0.applyPOV(in sourceSet VARCHAR(255), /* (?) Name of the t POV_LABEL: BEGIN DECLARE data TEXT DEFAULT NULL; /*data subselect statement string*/ DECLARE sTextData VARCHAR(20000) DEFAULT NULL; /*SELECT PREFIX for data subselect plus WHERE CLAUSE for text_data*/ + DECLARE sNameData VARCHAR(20000) DEFAULT NULL; /*WHERE CLAUSE for name_data*/ DECLARE sEnumData VARCHAR(20000) DEFAULT NULL; /*WHERE CLAUSE for enum_data*/ DECLARE sIntData VARCHAR(20000) DEFAULT NULL; /*WHERE CLAUSE for integer_data*/ DECLARE sDoubleData VARCHAR(20000) DEFAULT NULL; /*WHERE CLAUSE for double_data*/ @@ -86,6 +87,7 @@ POV_LABEL: BEGIN SET vText = NULL; /* Union of the following tables: text_data + name_data enum_data integer_data date_data @@ -96,7 +98,7 @@ POV_LABEL: BEGIN SELECT DISTINCT -> No duplicate values UNION ALL -> Allow also duplicate values */ - SET sTextData = 'SELECT DISTINCT domain_id, entity_id, property_id FROM `text_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `enum_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `integer_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `double_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `date_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `datetime_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `reference_data` AS subdata WHERE subdata.value IS NOT NULL'; + SET sTextData = 'SELECT DISTINCT domain_id, entity_id, property_id FROM `text_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `name_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `enum_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `integer_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `double_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `date_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `datetime_data` AS subdata WHERE subdata.value IS NOT NULL UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `reference_data` AS subdata WHERE subdata.value IS NOT NULL'; ELSEIF o = "(" or o = "!(" THEN SET sTextData = IF(vText IS NULL, ' SELECT DISTINCT domain_id, entity_id, property_id FROM `date_data`', @@ -144,6 +146,7 @@ POV_LABEL: BEGIN ELSE #-- generate statement parts SET sTextData = IF(vText IS NULL, 'SELECT DISTINCT domain_id, entity_id, property_id FROM `text_data`', CONCAT('SELECT DISTINCT domain_id, entity_id, property_id FROM `text_data` AS subdata WHERE subdata.value ',o,' ?')); + SET sNameData = IF(vText IS NULL, ' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `name_data`', CONCAT(' UNION SELECT DISTINCT domain_id, entity_id, property_id FROM `name_data` AS subdata WHERE subdata.value ', o, ' ?')); SET sEnumData = IF(vText IS NULL, ' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `enum_data`', CONCAT(' UNION SELECT DISTINCT domain_id, entity_id, property_id FROM `enum_data` AS subdata WHERE subdata.value ', o, ' ?')); SET sIntData = IF(vText IS NULL, ' UNION ALL SELECT DISTINCT subdata.domain_id, subdata.entity_id, subdata.property_id FROM `integer_data` AS subdata', IF(vInt IS NULL AND vDoubleStdUnit IS NULL, NULL, CONCAT(' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `integer_data` AS subdata WHERE ', getDoubleWhereClause(vInt, unit_sig, vDoubleStdUnit, stdUnit_sig, o)))); SET sDoubleData = IF(vText IS NULL, ' UNION ALL SELECT DISTINCT subdata.domain_id, subdata.entity_id, subdata.property_id FROM `double_data` AS subdata', IF(vDouble IS NULL, NULL, CONCAT(' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `double_data` AS subdata WHERE ', getDoubleWhereClause(vDouble,unit_sig,vDoubleStdUnit,stdUnit_sig,o)))); @@ -155,6 +158,7 @@ POV_LABEL: BEGIN END IF; SET data = CONCAT('(',sTextData, + IF(sNameData IS NULL, '', sNameData), IF(sEnumData IS NULL, '', sEnumData), IF(sDoubleData IS NULL, '', sDoubleData), IF(sIntData IS NULL, '', sIntData), @@ -187,7 +191,7 @@ POV_LABEL: BEGIN EXECUTE stmtPOVkeepTbl; ELSE SET @vText = vText; - EXECUTE stmtPOVkeepTbl USING @vText, @vText; + EXECUTE stmtPOVkeepTbl USING @vText, @vText, @vText; END IF; EXECUTE stmt3; DEALLOCATE PREPARE stmt3; diff --git a/procedures/query/initEntity.sql b/procedures/query/initEntity.sql index b1f1a9d690ef5b87bbf8357a5fcbd174a3e59377..f8877303a6d47a3cbf620b45c2fd8484caa1804b 100644 --- a/procedures/query/initEntity.sql +++ b/procedures/query/initEntity.sql @@ -26,36 +26,48 @@ DELIMITER // CREATE PROCEDURE db_2_0.initEntity(in eid INT UNSIGNED, in ename VARCHAR(255), in enameLike VARCHAR(255), in enameRegexp VARCHAR(255), in resultset VARCHAR(255)) initEntityLabel: BEGIN - SET @initEntityStmtStr = NULL; + SET @initEntityStmtStr = NULL; - IF ename IS NOT NULL THEN - SET @initEntityStmtStr = CONCAT('INSERT IGNORE INTO `',resultset,'` (id) SELECT id FROM entities WHERE name=? and id>=100 UNION ALL SELECT entity_id FROM name_data WHERE value=?;'); - SET @query_param = ename; - ELSEIF enameLike IS NOT NULL THEN - SET @initEntityStmtStr = CONCAT('INSERT IGNORE INTO `',resultset,'` (id) SELECT id FROM entities WHERE name LIKE ? and id>=100 UNION ALL SELECT entity_id FROM name_data WHERE value LIKE ?;'); - SET @query_param = enameLike; - ELSEIF enameRegexp IS NOT NULL THEN - SET @initEntityStmtStr = CONCAT('INSERT IGNORE INTO `',resultset,'` (id) SELECT id FROM entities WHERE name REGEXP ? and id>=100 UNION ALL SELECT entity_id FROM name_data WHERE value REGEXP ?;'); - SET @query_param = enameRegexp; + -- Prepare a statement which resolves the name or pattern to ids. The ids + -- are collected in a temporary table (resultset). + IF ename IS NOT NULL THEN + SET @initEntityStmtStr = CONCAT( + 'INSERT IGNORE INTO `', + resultset, + '` (id) SELECT entity_id FROM name_data WHERE value=?; '); + SET @query_param = ename; + ELSEIF enameLike IS NOT NULL THEN + SET @initEntityStmtStr = CONCAT( + 'INSERT IGNORE INTO `', + resultset, + '` (id) SELECT entity_id FROM name_data WHERE value LIKE ?;'); + SET @query_param = enameLike; + ELSEIF enameRegexp IS NOT NULL THEN + SET @initEntityStmtStr = CONCAT( + 'INSERT IGNORE INTO `', + resultset, + '` (id) SELECT entity_id FROM name_data WHERE value REGEXP ?;'); + SET @query_param = enameRegexp; END IF; - IF @initEntityStmtStr IS NOT NULL THEN - PREPARE initEntityStmt FROM @initEntityStmtStr; - EXECUTE initEntityStmt USING @query_param, @query_param; - DEALLOCATE PREPARE initEntityStmt; + -- execute the statement + IF @initEntityStmtStr IS NOT NULL THEN + PREPARE initEntityStmt FROM @initEntityStmtStr; + EXECUTE initEntityStmt USING @query_param; + DEALLOCATE PREPARE initEntityStmt; END IF; - + IF eid IS NOT NULL THEN - SET @initEntityStmtStr = CONCAT('INSERT IGNORE INTO `',resultset,'` (id) SELECT id FROM entities WHERE id=',eid,';'); - PREPARE initEntityStmt FROM @initEntityStmtStr; - EXECUTE initEntityStmt; - DEALLOCATE PREPARE initEntityStmt; + SET @initEntityStmtStr = CONCAT('INSERT IGNORE INTO `',resultset,'` (id) SELECT id FROM entities WHERE id=',eid,';'); + PREPARE initEntityStmt FROM @initEntityStmtStr; + EXECUTE initEntityStmt; + DEALLOCATE PREPARE initEntityStmt; END IF; - - IF @initEntityStmtStr IS NOT NULL THEN - call getChildren(resultset); - END IF; + + IF @initEntityStmtStr IS NOT NULL THEN + call getChildren(resultset); + END IF; END; // diff --git a/procedures/query/initPOV.sql b/procedures/query/initPOV.sql index 1d7c75a7d53190511212409b68dbfd9cdbe3a192..d1fa16300e4ef36902fd702739e389d336f1b3f5 100644 --- a/procedures/query/initPOV.sql +++ b/procedures/query/initPOV.sql @@ -41,12 +41,12 @@ BEGIN IF pname is NOT NULL THEN SELECT conv( concat( substring(uid,16,3), substring(uid,10,4), substring(uid,1,8)),16,10) div 10000 - (141427 * 24 * 60 * 60 * 1000) as current_mills INTO t1 from (select uuid() uid) as alias; call createTmpTable2(propertiesTable); - - -- fill in all properties named "pname" - SET @initPOVPropertiesTableStmt1 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) SELECT id, 0, 0 FROM entities WHERE name = ? UNION ALL SELECT property_id, entity_id, domain_id from name_overrides WHERE name = ? UNION ALL SELECT entity_id, domain_id, 0 FROM name_data WHERE value = ?;'); + + -- fill in all properties named "pname" + SET @initPOVPropertiesTableStmt1 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) SELECT property_id, entity_id, domain_id from name_overrides WHERE name = ? UNION ALL SELECT entity_id, domain_id, 0 FROM name_data WHERE value = ?;'); PREPARE stmt FROM @initPOVPropertiesTableStmt1; SET @pname = pname; - EXECUTE stmt USING @pname, @pname, @pname; + EXECUTE stmt USING @pname, @pname; SET ecount = ROW_COUNT(); -- fill in all properties with id="pid" diff --git a/procedures/query/initSubEntity.sql b/procedures/query/initSubEntity.sql index 2c3aefb3f7061efed43a5c4d36d4e413dca97786..543a0ce0f4745561ad0fa489da580d5e30fc3267 100644 --- a/procedures/query/initSubEntity.sql +++ b/procedures/query/initSubEntity.sql @@ -37,15 +37,13 @@ BEGIN SET @stmtStr = CONCAT('INSERT IGNORE INTO `', tableName, - '` (id) SELECT id FROM entities WHERE name ', - op, - ' ? UNION ALL SELECT entity_id FROM name_data WHERE value ', + '` (id) SELECT entity_id FROM name_data WHERE value ', op, ' ? AND domain_id=0;'); PREPARE stmt FROM @stmtStr; SET @ename = ename; - EXECUTE stmt USING @ename, @ename; + EXECUTE stmt USING @ename; SET ecount = ROW_COUNT(); DEALLOCATE PREPARE stmt; diff --git a/procedures/registerSubdomain.sql b/procedures/registerSubdomain.sql index ac7eebb90294a9e8699227cf993152ae6184dad1..60311f3ab9b2ca17e8e2c91b325f263ab7f19c61 100644 --- a/procedures/registerSubdomain.sql +++ b/procedures/registerSubdomain.sql @@ -37,7 +37,7 @@ BEGIN Select COUNT(id) INTO ED FROM entities WHERE Role='DOMAIN' AND id!=0; WHILE ED < Count DO - INSERT INTO entities (name, description, role, acl) VALUES (NULL, "Multipurpose subdomain", 'DOMAIN', 0); + INSERT INTO entities (description, role, acl) VALUES ("Multipurpose subdomain", 'DOMAIN', 0); SET ED = ED + 1; END WHILE; diff --git a/procedures/retrieveEntity.sql b/procedures/retrieveEntity.sql index 1e2621b090ee3caf12c1aa1a9aec6a73abebcfe0..0fbab94715a1903282ae18875c2184857357c23a 100644 --- a/procedures/retrieveEntity.sql +++ b/procedures/retrieveEntity.sql @@ -41,16 +41,16 @@ BEGIN SELECT collection into CollectionName from collection_type where domain_id=0 and entity_id=0 and property_id=EntityID LIMIT 1; Select - (Select name from entities where id=DatatypeID) as Datatype, + (SELECT value FROM name_data WHERE domain_id = 0 AND entity_ID = DatatypeID AND property_id = 20 LIMIT 1) as Datatype, CollectionName as Collection, EntityID as EntityID, - e.name as EntityName, + (SELECT value FROM name_data WHERE domain_id = 0 AND entity_ID = EntityID AND property_id = 20 LIMIT 1) as EntityName, e.description as EntityDesc, e.role as EntityRole, FileSize as FileSize, FilePath as FilePath, FileHash as FileHash, - (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 LIMIT 1) as ACL from entities e where id = EntityID LIMIT 1; END; // diff --git a/procedures/retrieveEntityOverrides.sql b/procedures/retrieveEntityOverrides.sql index f1f1bddbbe759862036a3789d20247f3e6699842..3c7421ccb639e9f709706fb1cf2fd28bb2bb9f01 100644 --- a/procedures/retrieveEntityOverrides.sql +++ b/procedures/retrieveEntityOverrides.sql @@ -29,7 +29,7 @@ BEGIN SELECT NULL as collection_override, name as name_override, NULL as desc_override, NULL as type_override, entity_id, property_id from name_overrides where domain_id=DomainID and entity_id=EntityID UNION ALL SELECT NULL as collection_override, NULL as name_override, description as desc_override, NULL as type_override, entity_id, property_id from desc_overrides where domain_id=DomainID and entity_id=EntityID UNION ALL - SELECT NULL as collection_override, NULL as name_override, NULL as desc_override, (Select name from entities where id=datatype LIMIT 1) as type_override, entity_id, property_id from data_type where domain_id=DomainID and entity_id=EntityID UNION ALL + SELECT NULL as collection_override, NULL as name_override, NULL as desc_override, (SELECT value FROM name_data WHERE domain_id = 0 AND entity_ID = datatype AND property_id = 20) as type_override, entity_id, property_id from data_type where domain_id=DomainID and entity_id=EntityID UNION ALL SELECT collection as collection_override, NULL as name_override, NULL as desc_override, NULL as type_override, entity_id, property_id from collection_type where domain_id=DomainID and entity_id=EntityID; diff --git a/procedures/retrieveEntityParents.sql b/procedures/retrieveEntityParents.sql index ffd9f13799b066c251b3941ffb8438e283014ebc..27d8719e8b680ec48e85e769315a192e82014a0e 100644 --- a/procedures/retrieveEntityParents.sql +++ b/procedures/retrieveEntityParents.sql @@ -54,7 +54,7 @@ ACL : CREATE PROCEDURE db_2_0.retrieveEntityParents(in EntityID INT UNSIGNED) BEGIN -SELECT parent AS ParentID, name AS ParentName, description AS ParentDescription, role AS ParentRole, (SELECT acl from entity_acl as a WHERE a.id=e.acl) AS ACL FROM isa_cache AS i JOIN entities AS e ON (i.parent=e.id AND i.child=EntityID and i.rpath=EntityID); +SELECT parent AS ParentID, (SELECT value FROM name_data WHERE domain_id = 0 AND entity_ID = ParentID AND property_id = 20) AS ParentName, description AS ParentDescription, role AS ParentRole, (SELECT acl from entity_acl as a WHERE a.id=e.acl) AS ACL FROM isa_cache AS i JOIN entities AS e ON (i.parent=e.id AND i.child=EntityID and i.rpath=EntityID); diff --git a/procedures/retrieveEntityProperties.sql b/procedures/retrieveEntityProperties.sql index 8df949a44978b91f822a2e3de7535f678f1ff62d..be778745b215f896fad4e3bca0ad932a965406de 100644 --- a/procedures/retrieveEntityProperties.sql +++ b/procedures/retrieveEntityProperties.sql @@ -79,7 +79,7 @@ BEGIN #-- name properties Select - property_id as PropertyID, value as PropertyValue, status as PropertyStatus, pidx as PropertyIndex from name_data where domain_id = DomainID and entity_id = EntityID; + property_id as PropertyID, value as PropertyValue, status as PropertyStatus, pidx as PropertyIndex from name_data where domain_id = DomainID and entity_id = EntityID and property_id!=20; diff --git a/procedures/updateEntity.sql b/procedures/updateEntity.sql index 7fa903a09fbc486d8428879e95b6c9381f766ff1..cdcacffbe0964518d7caf285d1efb0c1770afb20 100644 --- a/procedures/updateEntity.sql +++ b/procedures/updateEntity.sql @@ -33,19 +33,23 @@ delimiter // CREATE PROCEDURE db_2_0.updateEntity(in EntityID INT UNSIGNED, in EntityName VARCHAR(255), in EntityDescription TEXT, in EntityRole VARCHAR(255), in Datatype VARCHAR(255), in Collection VARCHAR(255), in ACL VARBINARY(65525)) BEGIN - DECLARE ACLID INT UNSIGNED DEFAULT NULL; - call entityACL(ACLID, ACL); + DECLARE ACLID INT UNSIGNED DEFAULT NULL; + call entityACL(ACLID, ACL); - UPDATE entities e SET e.name = EntityName, e.description = EntityDescription, e.role=EntityRole, e.acl = ACLID where e.id = EntityID; + UPDATE entities e SET e.description = EntityDescription, e.role=EntityRole, e.acl = ACLID where e.id = EntityID; - DELETE from data_type where domain_id=0 AND entity_id=0 AND property_id=EntityID; + IF EntityName IS NOT NULL THEN + INSERT INTO name_data (domain_id, entity_id, property_id, value, status, pidx) VALUES (0, EntityID, 20, EntityName, "FIX", 0); + END IF; + + DELETE from data_type where domain_id=0 AND entity_id=0 AND property_id=EntityID; DELETE from collection_type where domain_id=0 AND entity_id=0 AND property_id=EntityID; IF Datatype IS NOT NULL THEN - INSERT INTO data_type (domain_id, entity_id, property_id, datatype) SELECT 0, 0, EntityID, ( SELECT id from entities where name = Datatype LIMIT 1); - IF Collection IS NOT NULL THEN - INSERT INTO collection_type (domain_id, entity_id, property_id, collection) SELECT 0, 0, EntityID, Collection; - END IF; + INSERT INTO data_type (domain_id, entity_id, property_id, datatype) SELECT 0, 0, EntityID, ( SELECT entity_id FROM name_data WHERE domain_id = 0 AND property_id = 20 AND value = Datatype LIMIT 1 ); + IF Collection IS NOT NULL THEN + INSERT INTO collection_type (domain_id, entity_id, property_id, collection) SELECT 0, 0, EntityID, Collection; + END IF; END IF; END; diff --git a/tests/test_autotap.sql b/tests/test_autotap.sql index f60bb3fca85cceda5956dac74e9fa9948b13a707..0e550c221552515b6b73170baf53fcaca307aa0a 100644 --- a/tests/test_autotap.sql +++ b/tests/test_autotap.sql @@ -625,7 +625,7 @@ SELECT tap.table_collation_is('_caosdb_schema_unit_tests','entities','utf8_unico SELECT tap.table_engine_is('_caosdb_schema_unit_tests','entities','InnoDB',''); -- COLUMNS -SELECT tap.columns_are('_caosdb_schema_unit_tests','entities','`id`,`name`,`description`,`role`,`acl`',''); +SELECT tap.columns_are('_caosdb_schema_unit_tests','entities','`id`,`description`,`role`,`acl`',''); -- COLUMN entities.id @@ -636,15 +636,6 @@ SELECT tap.col_default_is('_caosdb_schema_unit_tests','entities','id',NULL,''); SELECT tap.col_charset_is('_caosdb_schema_unit_tests','entities','id',NULL,''); SELECT tap.col_collation_is('_caosdb_schema_unit_tests','entities','id',NULL,''); --- COLUMN entities.name - -SELECT tap.has_column('_caosdb_schema_unit_tests','entities','name',''); -SELECT tap.col_column_type_is('_caosdb_schema_unit_tests','entities','name','varchar(255)',''); -SELECT tap.col_extra_is('_caosdb_schema_unit_tests','entities','name','',''); -SELECT tap.col_default_is('_caosdb_schema_unit_tests','entities','name','NULL',''); -SELECT tap.col_charset_is('_caosdb_schema_unit_tests','entities','name','utf8',''); -SELECT tap.col_collation_is('_caosdb_schema_unit_tests','entities','name','utf8_unicode_ci',''); - -- COLUMN entities.description SELECT tap.has_column('_caosdb_schema_unit_tests','entities','description',''); @@ -1222,7 +1213,7 @@ SELECT tap.index_is_type('_caosdb_schema_unit_tests','name_data','value','BTREE' SELECT tap.is_indexed('_caosdb_schema_unit_tests','name_data','`value`',''); -- CONSTRAINTS -SELECT tap.constraints_are('_caosdb_schema_unit_tests','name_data','`name_data_domain_id_entity`,`name_data_entity_id_entity`,`name_data_property_id_entity`',''); +SELECT tap.constraints_are('_caosdb_schema_unit_tests','name_data','`name_data_domain_id_entity`,`domain_id_2`,`name_data_entity_id_entity`,`name_data_property_id_entity`',''); -- CONSTRAINT name_data.name_data_domain_id_entity @@ -1231,6 +1222,11 @@ SELECT tap.constraint_type_is('_caosdb_schema_unit_tests','name_data','name_data SELECT tap.fk_on_delete('_caosdb_schema_unit_tests','name_data','name_data_domain_id_entity','RESTRICT',''); SELECT tap.fk_on_update('_caosdb_schema_unit_tests','name_data','name_data_domain_id_entity','RESTRICT',''); +-- CONSTRAINT name_data.domain_id_2 + +SELECT tap.has_constraint('_caosdb_schema_unit_tests','name_data','domain_id_2',''); +SELECT tap.constraint_type_is('_caosdb_schema_unit_tests','name_data','domain_id_2','UNIQUE',''); + -- CONSTRAINT name_data.name_data_entity_id_entity SELECT tap.has_constraint('_caosdb_schema_unit_tests','name_data','name_data_entity_id_entity',''); diff --git a/utils/patch_header.sh b/utils/patch_header.sh index 488b7a0f4df0c20bde1909872d923ea4c352cacc..c50846ed2a03677c86ccd056dab111a04a8f4903 100644 --- a/utils/patch_header.sh +++ b/utils/patch_header.sh @@ -88,6 +88,7 @@ while test $# -gt 0; do ;; --patch*) PATCH="${1#--*=}" + PATCH_DIR=$(dirname $PATCH) shift ;; --backupdir*)