Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • caosdb/src/caosdb-mysqlbackend
1 result
Select Git revision
Loading items
Show changes
Showing
with 741 additions and 265 deletions
No preview for this file type
......@@ -47,4 +47,5 @@ do
done
cd ../
$UTILSPATH/update_sql_procedures.sh
......@@ -35,7 +35,12 @@ fi
check_version $OLD_VERSION
mysql_execute 'DELETE FROM `entities` WHERE id=6; ALTER TABLE `entities` MODIFY COLUMN `role` ENUM("RECORDTYPE","RECORD","FILE","DOMAIN","PROPERTY","DATATYPE","ROLE","QUERYTEMPLATE") NOT NULL; INSERT INTO entities (id, name, description, role, acl) VALUES (8,"QUERYTEMPLATE","The QueryTemplate role.","ROLE",0); UPDATE `entities` SET role="ROLE" WHERE id<100 and name=role; CREATE TABLE `query_template_def` (id INT UNSIGNED PRIMARY KEY, definition MEDIUMTEXT NOT NULL, CONSTRAINT `query_template_def_ibfk_1` FOREIGN KEY (`id`) REFERENCES `entities` (`id`));'
mysql_execute '
DELETE FROM `entities` WHERE id=6;
ALTER TABLE `entities` MODIFY COLUMN `role` ENUM("RECORDTYPE","RECORD","FILE","DOMAIN","PROPERTY","DATATYPE","ROLE","QUERYTEMPLATE") NOT NULL;
INSERT INTO entities (id, name, description, role, acl) VALUES (8,"QUERYTEMPLATE","The QueryTemplate role.","ROLE",0);
UPDATE `entities` SET role="ROLE" WHERE id<100 and name=role;
CREATE TABLE `query_template_def` (id INT UNSIGNED PRIMARY KEY, definition MEDIUMTEXT NOT NULL, CONSTRAINT `query_template_def_ibfk_1` FOREIGN KEY (`id`) REFERENCES `entities` (`id`));'
update_version $NEW_VERSION
......
/*
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2022-2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2022-2023 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/>.
*/
-- a little bit of house keeping
DROP PROCEDURE IF EXISTS retrieveSubEntity;
DROP PROCEDURE IF EXISTS retrieveDatatype;
DROP PROCEDURE IF EXISTS retrieveGroup;
DROP PROCEDURE IF EXISTS getInfo;
DROP PROCEDURE IF EXISTS getRole;
DROP PROCEDURE IF EXISTS setPassword;
DROP PROCEDURE IF EXISTS initAutoIncrement;
DELETE FROM name_data WHERE entity_id=50;
DELETE FROM entities WHERE id=50;
DELETE FROM entities WHERE id=99;
-- this simply is the more appropriate name
ALTER TABLE entities MODIFY COLUMN
`role` enum('RECORDTYPE','RECORD','FILE','DOMAIN','PROPERTY','DATATYPE','ROLE','QUERYTEMPLATE', '_REPLACEMENT') COLLATE utf8_unicode_ci NOT NULL;
ALTER TABLE archive_entities MODIFY COLUMN
`role` enum('RECORDTYPE','RECORD','FILE','DOMAIN','PROPERTY','DATATYPE','ROLE','QUERYTEMPLATE', '_REPLACEMENT') COLLATE utf8_unicode_ci NOT NULL;
UPDATE entities SET role = "_REPLACEMENT" WHERE role="DOMAIN";
UPDATE archive_entities SET role = "_REPLACEMENT" WHERE role="DOMAIN";
ALTER TABLE entities MODIFY COLUMN
`role` enum('RECORDTYPE','RECORD','FILE','_REPLACEMENT','PROPERTY','DATATYPE','ROLE','QUERYTEMPLATE') COLLATE utf8_unicode_ci NOT NULL;
ALTER TABLE archive_entities MODIFY COLUMN
`role` enum('RECORDTYPE','RECORD','FILE','_REPLACEMENT','PROPERTY','DATATYPE','ROLE','QUERYTEMPLATE') COLLATE utf8_unicode_ci NOT NULL;
-- new entity_ids table
DROP TABLE IF EXISTS `entity_ids`;
CREATE TABLE `entity_ids` (
`id` VARCHAR(255) NOT NULL,
`internal_id` int(10) unsigned NOT NULL COMMENT 'Internal ID of an entity. This id is used internally in the *_data tables and elsewhere. This ID is never exposed via the CaosDB API.',
PRIMARY KEY `entity_ids_pk` (`id`),
CONSTRAINT `entity_ids_internal_id` FOREIGN KEY (`internal_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB COLLATE utf8mb4_bin;
-- fill all existing entities into the new entity_ids table.
INSERT INTO entity_ids (id, internal_id) SELECT id, id FROM entities WHERE id>0 AND role!="_REPLACEMENT";
ALTER TABLE transaction_log MODIFY COLUMN `entity_id` VARCHAR(255) COLLATE utf8mb4_bin NOT NULL;
ALTER TABLE user_info DROP FOREIGN KEY `subjects_ibfk_1`;
ALTER TABle user_info MODIFY COLUMN `entity` VARCHAR(255) COLLATE utf8mb4_bin DEFAULT NULL;
ALTER TABLE user_info ADD CONSTRAINT `subjects_ibfk_2` FOREIGN KEY (`entity`) REFERENCES `entity_ids` (`id`);
#!/bin/bash
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2023 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/>.
#
# Update mysql schema to version v5.0.0
# Drop the 'rules' table.
NEW_VERSION="v6.0.0-SNAPSHOT-EXTIDS"
OLD_VERSION="v5.0.0"
DROP_TABLE_PASSWORDS='DROP TABLE IF EXISTS passwords;'
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
mysql_execute "$DROP_TABLE_PASSWORDS"
mysql_execute_file $PATCH_DIR/create_entity_ids_table.sql
update_version $NEW_VERSION
success
#!/bin/bash
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2023 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/>.
#
# Update mysql schema to version v6.1.0
# No migration of the schema, updating procedures only
NEW_VERSION="v6.1.0"
OLD_VERSION="v6.0.0-SNAPSHOT-EXTIDS"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
# Drop insertUser procedure
mysql_execute "DROP PROCEDURE IF EXISTS insertUser;"
update_version $NEW_VERSION
success
#!/bin/bash
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2023 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/>.
#
# Update mysql schema to version v7.0.0
# No migration of the schema, updating procedures only
NEW_VERSION="v7.0.0"
OLD_VERSION="v6.1.0"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
update_version $NEW_VERSION
success
#!/bin/bash
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2023 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/>.
#
# Update mysql schema to version v7.0.1
# Removing remnant tables. This patch version also adds new sanity checks
# during installation/upgrade
NEW_VERSION="v7.0.1"
OLD_VERSION="v7.0.0"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
mysql_execute "DROP TABLE IF EXISTS groups";
mysql_execute "DROP TABLE IF EXISTS passwords";
mysql_execute "DROP TABLE IF EXISTS logging";
mysql_execute "DROP TABLE IF EXISTS isa";
update_version $NEW_VERSION
success
#!/bin/bash
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2023 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/>.
#
# Update mysql schema to version v7.0.2
# Patch the broken data_type table (fix id for file references as per
# https://gitlab.com/linkahead/linkahead-server/-/issues/246)
NEW_VERSION="v7.0.2"
OLD_VERSION="v7.0.1"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
mysql_execute "UPDATE data_type SET datatype=17 WHERE datatype=3"
update_version $NEW_VERSION
success
#!/bin/bash
#
# This file is a part of the LinkAhead Project.
#
# Copyright (C) 2024 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2024 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2024 Florian Spreckelsen <f.spreckelsen@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/>.
#
# Update mysql schema to version v8.0.0
#
# The patch is empty because the change has to be applied manually
# from ../../dump_updates/2024-10-02.dump_fix_mariadb_10_6.sh if necessary.
NEW_VERSION="v8.0.0"
OLD_VERSION="v7.0.2"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
update_version $NEW_VERSION
success
#!/bin/bash
#
# This file is a part of the Linkahead Project.
#
# Copyright (C) 2025 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2025 Daniel Hornung <d.hornung@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/>.
#
# Update mysql schema to version v8.1.0
#
# Set the collation so that accents on characters become relevant.
OLD_VERSION="v8.0.0"
NEW_VERSION="v8.1.0"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
# Update charsets and collations.
# Change database default.
mysql_execute "ALTER DATABASE \`$DATABASE_NAME\` COLLATE = 'uca1400_as_ci';"
# Some columns should be changed manually to prevent text length changes.
mysql_execute "ALTER TABLE desc_overrides MODIFY description TEXT CHARACTER SET utf8mb4;"
mysql_execute "ALTER TABLE entities MODIFY description TEXT CHARACTER SET utf8mb4;"
mysql_execute "ALTER TABLE permissions MODIFY permissions MEDIUMTEXT CHARACTER SET utf8mb4 NOT NULL;"
mysql_execute "ALTER TABLE query_template_def MODIFY definition MEDIUMTEXT CHARACTER SET utf8mb4 NOT NULL;"
mysql_execute "ALTER TABLE roles MODIFY description MEDIUMTEXT CHARACTER SET utf8mb4;"
mysql_execute "ALTER TABLE text_data MODIFY value TEXT CHARACTER SET utf8mb4 NOT NULL;"
# Remove some constraints first.
mysql_execute 'ALTER TABLE user_info DROP FOREIGN KEY `subjects_ibfk_2`;'
# Get all tables, drop first line, take first column
tables=$(mysql_execute "SHOW TABLE status where Collation='utf8mb3_unicode_ci';" -B | tail +2 | awk '{print $1}')
for table in $tables; do
mysql_execute "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE uca1400_as_ci;"
done
# Add constraints again.
mysql_execute 'ALTER TABLE user_info MODIFY COLUMN `entity` VARCHAR(255) COLLATE utf8mb4_bin DEFAULT NULL;'
mysql_execute 'ALTER TABLE user_info ADD CONSTRAINT `subjects_ibfk_2` FOREIGN KEY (`entity`) REFERENCES `entity_ids` (`id`);'
# Set custom collations for columns
mysql_execute "ALTER TABLE transaction_log MODIFY entity_id VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL;"
### Finished ###
update_version $NEW_VERSION
success
##### Useful commands #####
# cd git/caosdb-mysqlbackend/
# UTILSPATH=utils
# . utils/patch_header.sh
# show table status where Collation='utf8mb3_unicode_ci';
# name_data
# text_data
# show table status like 'name_data';
# select * from name_data where value like 'Yield%';
# update name_data SET value='Yield-stréss' where entity_id=354;
# update name_data SET value='Yield-strés😋s' where entity_id=354;
# select * from name_data where value='Yield-stress';
# # Unicode 14.0.0
# ALTER TABLE name_data CONVERT TO CHARACTER SET utf8mb4 COLLATE uca1400_as_ci;
# FULL_COLLATION_NAME: utf8mb4_uca1400_as_ci;
# COLLATION_NAME: uca1400_as_ci;
# mariadb -h sqldb -u caosdb -prandom1234 --default-character-set=utf8mb4 caosdb
/*
* ** 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
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020-2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 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
......@@ -18,8 +18,6 @@
*
* 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
*/
/* Delete a (sparse) Entity from the database.
......@@ -31,37 +29,43 @@ have been deleted before. This can be done for example with the
Parameters
==========
EntityID : UNSIGNED
EntityID : VARCHAR(255)
The ID of the Entity.
*/
DROP PROCEDURE IF EXISTS db_5_0.deleteEntity;
delimiter //
CREATE PROCEDURE db_5_0.deleteEntity(in EntityID INT UNSIGNED)
CREATE PROCEDURE db_5_0.deleteEntity(in EntityID VARCHAR(255))
BEGIN
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID from entity_ids WHERE id = EntityID;
-- detele file properties
DELETE FROM files where file_id=EntityID;
DELETE FROM files where file_id=InternalEntityID;
-- delete datatype stuff
DELETE FROM data_type
WHERE ( domain_id = 0
AND entity_id = 0
AND property_id = EntityID )
OR datatype = EntityID;
AND property_id = InternalEntityID )
OR datatype = InternalEntityID;
DELETE FROM collection_type
WHERE domain_id = 0
AND entity_id = 0
AND property_id = EntityID;
AND property_id = InternalEntityID;
-- delete primary name (in case this is called without a prior call to deleteEntityProperties)
DELETE FROM name_data
WHERE domain_id = 0
AND entity_id = EntityID
AND entity_id = InternalEntityID
AND property_id = 20;
DELETE FROM entities where id=EntityID;
DELETE FROM entity_ids
WHERE internal_id = InternalEntityID;
DELETE FROM entities where id=InternalEntityID;
-- clean up unused acl
DELETE FROM entity_acl
......
/*
* ** 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
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 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
......@@ -19,23 +18,34 @@
*
* 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
*/
DROP PROCEDURE IF EXISTS db_5_0.deleteEntityProperties;
delimiter //
CREATE PROCEDURE db_5_0.deleteEntityProperties(in EntityID INT UNSIGNED)
/*
* Delete all properties of an entity (i.e. remove them from the *_data tables
* and the isa_cache table).
*
* Parameters
* ==========
*
* EntityID : VARCHAR(255)
* The entity's id.
*/
CREATE PROCEDURE db_5_0.deleteEntityProperties(in EntityID VARCHAR(255))
BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID from entity_ids WHERE id = EntityID;
CALL deleteIsa(EntityID);
CALL deleteIsa(InternalEntityID);
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
SELECT max(e._iversion) INTO IVersion -- What's the latest version?
FROM entity_version AS e
WHERE e.entity_id = EntityID;
WHERE e.entity_id = InternalEntityID;
-- Copy the rows from *_data to archive_*_data ---------------------
INSERT INTO archive_reference_data (domain_id, entity_id,
......@@ -43,142 +53,142 @@ BEGIN
SELECT domain_id, entity_id, property_id, value, value_iversion,
status, pidx, IVersion AS _iversion
FROM reference_data
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_null_data (domain_id, entity_id,
property_id, status, pidx, _iversion)
SELECT domain_id, entity_id, property_id, status,
pidx, IVersion AS _iversion
FROM null_data
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_text_data (domain_id, entity_id,
property_id, value, status, pidx, _iversion)
SELECT domain_id, entity_id, property_id, value, status,
pidx, IVersion AS _iversion
FROM text_data
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_name_data (domain_id, entity_id,
property_id, value, status, pidx, _iversion)
SELECT domain_id, entity_id, property_id, value, status,
pidx, IVersion AS _iversion
FROM name_data
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_enum_data (domain_id, entity_id,
property_id, value, status, pidx, _iversion)
SELECT domain_id, entity_id, property_id, value, status,
pidx, IVersion AS _iversion
FROM enum_data
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_integer_data (domain_id, entity_id,
property_id, value, status, pidx, _iversion, unit_sig)
SELECT domain_id, entity_id, property_id, value, status,
pidx, IVersion AS _iversion, unit_sig
FROM integer_data
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_double_data (domain_id, entity_id,
property_id, value, status, pidx, _iversion, unit_sig)
SELECT domain_id, entity_id, property_id, value, status,
pidx, IVersion AS _iversion, unit_sig
FROM double_data
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_datetime_data (domain_id, entity_id,
property_id, value, value_ns, status, pidx, _iversion)
SELECT domain_id, entity_id, property_id, value, value_ns,
status, pidx, IVersion AS _iversion
FROM datetime_data
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_date_data (domain_id, entity_id,
property_id, value, status, pidx, _iversion)
SELECT domain_id, entity_id, property_id, value, status,
pidx, IVersion AS _iversion
FROM date_data
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_name_overrides (domain_id, entity_id,
property_id, name, _iversion)
SELECT domain_id, entity_id, property_id, name,
IVersion AS _iversion
FROM name_overrides
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_desc_overrides (domain_id, entity_id,
property_id, description, _iversion)
SELECT domain_id, entity_id, property_id, description,
IVersion AS _iversion
FROM desc_overrides
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_data_type (domain_id, entity_id,
property_id, datatype, _iversion)
SELECT domain_id, entity_id, property_id, datatype,
IVersion AS _iversion
FROM data_type
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_collection_type (domain_id, entity_id,
property_id, collection, _iversion)
SELECT domain_id, entity_id, property_id, collection,
IVersion AS _iversion
FROM collection_type
WHERE (domain_id = 0 AND entity_id = EntityID)
OR domain_id = EntityID;
WHERE (domain_id = 0 AND entity_id = InternalEntityID)
OR domain_id = InternalEntityID;
INSERT INTO archive_query_template_def (id, definition, _iversion)
SELECT id, definition, IVersion AS _iversion
FROM query_template_def
WHERE id = EntityID;
WHERE id = InternalEntityID;
END IF;
DELETE FROM reference_data
where (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
where (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM null_data
where (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
where (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM text_data
where (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
where (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM name_data
where (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
where (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM enum_data
where (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
where (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM integer_data
where (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
where (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM double_data
where (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
where (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM datetime_data
where (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
where (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM date_data
where (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
where (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM name_overrides
WHERE (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
WHERE (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM desc_overrides
WHERE (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
WHERE (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM data_type
WHERE (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
WHERE (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM collection_type
WHERE (domain_id=0 AND entity_id=EntityID) OR domain_id=EntityID;
WHERE (domain_id=0 AND entity_id=InternalEntityID) OR domain_id=InternalEntityID;
DELETE FROM query_template_def WHERE id=EntityID;
DELETE FROM query_template_def WHERE id=InternalEntityID;
END;
//
......
/*
* ** 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
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 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
......@@ -19,8 +18,6 @@
*
* 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
*/
SET GLOBAL log_bin_trust_function_creators = 1;
......@@ -38,30 +35,30 @@ parameter entity is a child or inside the rpath.
Parameters
==========
EntityID : UNSIGNED
InternalEntityID : UNSIGNED
Child entity for which all parental relations should be deleted.
*/
CREATE PROCEDURE db_5_0.deleteIsa(IN EntityID INT UNSIGNED)
CREATE PROCEDURE db_5_0.deleteIsa(IN InternalEntityID INT UNSIGNED)
BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
SELECT max(_iversion) INTO IVersion
FROM entity_version
WHERE entity_id = EntityID;
WHERE entity_id = InternalEntityID;
-- move to archive_isa before deleting
INSERT IGNORE INTO archive_isa (child, child_iversion, parent, direct)
SELECT e.child, IVersion AS child_iversion, e.parent, rpath = EntityID
SELECT e.child, IVersion AS child_iversion, e.parent, rpath = InternalEntityID
FROM isa_cache AS e
WHERE e.child = EntityID;
WHERE e.child = InternalEntityID;
END IF;
DELETE FROM isa_cache
WHERE child = EntityID
OR rpath = EntityID
OR rpath LIKE concat('%>', EntityID)
OR rpath LIKE concat('%>', EntityID, '>%');
WHERE child = InternalEntityID
OR rpath = InternalEntityID
OR rpath LIKE concat('%>', InternalEntityID)
OR rpath LIKE concat('%>', InternalEntityID, '>%');
END;
//
......
/*
* 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 file is a part of the LinkAhead Project.
*
* Copyright (C) 2020-2024 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2024 Daniel Hornung <d.hornung@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
......@@ -27,23 +27,23 @@ DROP PROCEDURE IF EXISTS db_5_0.insert_single_child_version //
*
* Parameters
* ----------
* EntityID
* The ID of the versioned entity.
* Hash
* InternalEntityID : INT UNSIGNED
* The internal ID of the versioned entity.
* Hash : VARBINARY(255)
* A hash of the entity. This is currently not implemented properly and only
* there for future use.
* Version
* Version : VARBINARY(255)
* The new version ID of the entity, must be produced by the caller. Must be unique for each
* EntityID.
* Parent
* Parent : VARBINARY(255)
* The version ID of the primary parent (i.e. predecessor). May be NULL; but if given, it must
* exist.
* Transaction
* Transaction : VARBINARY(255)
* The transaction ID which created this entity version (by inserting
* or updating an entity).
*/
CREATE PROCEDURE db_5_0.insert_single_child_version(
in EntityID INT UNSIGNED,
in InternalEntityID INT UNSIGNED,
in Hash VARBINARY(255),
in Version VARBINARY(255),
in Parent VARBINARY(255),
......@@ -57,12 +57,12 @@ BEGIN
IF Parent IS NOT NULL THEN
SELECT e._iversion INTO newipparent
FROM entity_version AS e
WHERE e.entity_id = EntityID
WHERE e.entity_id = InternalEntityID
AND e.version = Parent;
IF newipparent IS NULL THEN
-- throw error;
SELECT concat("This parent does not exists: ", Parent)
FROM nonexisting;
FROM parent_version_does_not_exist;
END IF;
END IF;
......@@ -70,7 +70,7 @@ BEGIN
-- generate _iversion
SELECT max(e._iversion)+1 INTO newiversion
FROM entity_version AS e
WHERE e.entity_id=EntityID;
WHERE e.entity_id=InternalEntityID;
IF newiversion IS NULL THEN
SET newiversion = 1;
END IF;
......@@ -78,7 +78,7 @@ BEGIN
INSERT INTO entity_version
(entity_id, hash, version, _iversion, _ipparent, srid)
VALUES
(EntityID, Hash, Version, newiversion, newipparent, Transaction);
(InternalEntityID, Hash, Version, newiversion, newipparent, Transaction);
......@@ -87,22 +87,28 @@ END;
DROP PROCEDURE IF EXISTS db_5_0.delete_all_entity_versions //
/* THIS PROCEDURE HAS NEVER BEEN USED (outside of the tests). Reactivate when
* versioning's FORGET is being implemented. */
/**
* Remove all records in the entity_version table for the given entity.
*
* Parameters
* ----------
* EntityID
* EntityID : VARCHAR(255)
* The id of the versioned entity.
*/
CREATE PROCEDURE db_5_0.delete_all_entity_versions(
in EntityID INT UNSIGNED)
/* CREATE PROCEDURE db_5_0.delete_all_entity_versions(
in EntityID VARCHAR(255))
BEGIN
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
DELETE FROM entity_version WHERE entity_id = EntityID;
DELETE FROM entity_version WHERE entity_id = InternalEntityID;
END;
//
*/
DROP FUNCTION IF EXISTS db_5_0.get_iversion //
......@@ -111,9 +117,9 @@ DROP FUNCTION IF EXISTS db_5_0.get_iversion //
*
* Parameters
* ----------
* EntityID
* The entity's id.
* Version
* InternalEntityID : INT UNSIGNED
* The entity's internal id.
* Version : VARBINARY(255)
* The (official, externally used) version id.
*
* Returns
......@@ -121,7 +127,7 @@ DROP FUNCTION IF EXISTS db_5_0.get_iversion //
* The internal version id.
*/
CREATE FUNCTION db_5_0.get_iversion(
EntityID INT UNSIGNED,
InternalEntityID INT UNSIGNED,
Version VARBINARY(255))
RETURNS INT UNSIGNED
READS SQL DATA
......@@ -129,7 +135,7 @@ BEGIN
RETURN (
SELECT e._iversion
FROM entity_version AS e
WHERE e.entity_id = EntityID
WHERE e.entity_id = InternalEntityID
AND e.version = Version
);
END;
......@@ -143,9 +149,9 @@ DROP FUNCTION IF EXISTS db_5_0.get_primary_parent_version //
*
* Parameters
* ----------
* EntityID
* EntityID : VARCHAR(255)
* The entity id.
* Version
* Version : VARBINARY(255)
* The version id.
*
* Returns
......@@ -153,17 +159,21 @@ DROP FUNCTION IF EXISTS db_5_0.get_primary_parent_version //
* The id of the given version's primary parent version.
*/
CREATE FUNCTION db_5_0.get_primary_parent_version(
EntityID INT UNSIGNED,
EntityID VARCHAR(255),
Version VARBINARY(255))
RETURNS VARBINARY(255)
READS SQL DATA
BEGIN
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
RETURN (
SELECT p.version
FROM entity_version AS e INNER JOIN entity_version AS p
ON (e._ipparent = p._iversion
AND e.entity_id = p.entity_id)
WHERE e.entity_id = EntityID
WHERE e.entity_id = InternalEntityID
AND e.version = Version
);
END;
......@@ -177,9 +187,9 @@ DROP FUNCTION IF EXISTS db_5_0.get_version_timestamp //
*
* Parameters
* ----------
* EntityID
* EntityID : VARCHAR(255)
* The entity id.
* Version
* Version : VARBINARY(255)
* The version id.
*
* Returns
......@@ -188,16 +198,20 @@ DROP FUNCTION IF EXISTS db_5_0.get_version_timestamp //
* Note that the dot `.` here is not necessarily a decimal separator.
*/
CREATE FUNCTION db_5_0.get_version_timestamp(
EntityID INT UNSIGNED,
EntityID VARCHAR(255),
Version VARBINARY(255))
RETURNS VARCHAR(255)
READS SQL DATA
BEGIN
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
RETURN (
SELECT concat(t.seconds, '.', t.nanos)
FROM entity_version AS e INNER JOIN transactions AS t
ON ( e.srid = t.srid )
WHERE e.entity_id = EntityID
WHERE e.entity_id = InternalEntityID
AND e.version = Version
);
END;
......@@ -210,7 +224,7 @@ DROP FUNCTION IF EXISTS db_5_0.get_head_version //
*
* Parameters
* ----------
* EntityID
* EntityID : VARCHAR(255)
* The entity id.
*
* Returns
......@@ -218,7 +232,7 @@ DROP FUNCTION IF EXISTS db_5_0.get_head_version //
* The version id of the HEAD.
*/
CREATE FUNCTION db_5_0.get_head_version(
EntityID INT UNSIGNED)
EntityID VARCHAR(255))
RETURNS VARBINARY(255)
READS SQL DATA
BEGIN
......@@ -233,15 +247,15 @@ DROP FUNCTION IF EXISTS db_5_0._get_head_iversion //
*
* Parameters
* ----------
* EntityID
* The entity id.
* InternalEntityID : INT UNSIGNED
* The entity's internal id.
*
* Returns
* -------
* The _iversion of the HEAD.
*/
CREATE FUNCTION db_5_0._get_head_iversion(
EntityID INT UNSIGNED)
InternalEntityID INT UNSIGNED)
RETURNS INT UNSIGNED
READS SQL DATA
BEGIN
......@@ -252,7 +266,7 @@ BEGIN
RETURN (
SELECT e._iversion
FROM entity_version AS e
WHERE e.entity_id = EntityID
WHERE e.entity_id = InternalEntityID
ORDER BY e._iversion DESC
LIMIT 1
);
......@@ -267,9 +281,9 @@ DROP FUNCTION IF EXISTS db_5_0.get_head_relative //
*
* Parameters
* ----------
* EntityID
* EntityID : VARCHAR(255)
* The entity id.
* Offset
* HeadOffset : INT UNSIGNED
* Distance in the sequence of primary parents of the entity. E.g. `0` is the
* HEAD itself. `1` is the primary parent of the HEAD. `2` is the primary
* parent of the primary parent of the HEAD, and so on.
......@@ -279,11 +293,15 @@ DROP FUNCTION IF EXISTS db_5_0.get_head_relative //
* The version id of the HEAD.
*/
CREATE FUNCTION db_5_0.get_head_relative(
EntityID INT UNSIGNED,
Offset INT UNSIGNED)
EntityID VARCHAR(255),
HeadOffset INT UNSIGNED)
RETURNS VARBINARY(255)
READS SQL DATA
BEGIN
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
-- This implementation assumes that the distance from the head equals the
-- difference between the _iversion numbers. This will not be correct anymore
-- as soon as branches may split and merge. Then, a walk over the primary
......@@ -291,9 +309,9 @@ BEGIN
RETURN (
SELECT e.version
FROM entity_version AS e
WHERE e.entity_id = EntityID
WHERE e.entity_id = InternalEntityID
ORDER BY e._iversion DESC
LIMIT 1 OFFSET Offset
LIMIT 1 OFFSET HeadOffset
);
END;
//
......@@ -304,24 +322,24 @@ DROP FUNCTION IF EXISTS db_5_0._get_version //
*
* Parameters
* ----------
* EntityID
* The entity id.
* InternalEntityID : INT UNSIGNED
* The entity's internal id.
* IVersion
* Internal version id (integer).
*
* Returns
* -------
* The version id.
* The (external) version id.
*/
CREATE FUNCTION db_5_0._get_version(
EntityID INT UNSIGNED,
InternalEntityID INT UNSIGNED,
IVersion INT UNSIGNED)
RETURNS VARBINARY(255)
READS SQL DATA
BEGIN
RETURN (
SELECT version FROM entity_version
WHERE entity_id = EntityID
WHERE entity_id = InternalEntityID
AND _iversion = IVersion
);
END;
......@@ -335,7 +353,7 @@ DROP PROCEDURE IF EXISTS db_5_0.get_version_history //
*
* Parameters
* ----------
* EntityID
* EntityID : VARCHAR(255)
* The entity id.
*
* Selects
......@@ -344,8 +362,12 @@ DROP PROCEDURE IF EXISTS db_5_0.get_version_history //
* child_realm). `child` and `parent` are version IDs.
*/
CREATE PROCEDURE db_5_0.get_version_history(
in EntityID INT UNSIGNED)
in EntityID VARCHAR(255))
BEGIN
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
-- retrieve root(s) (initial versions)
SELECT c.version AS child,
NULL as parent,
......@@ -355,7 +377,7 @@ BEGIN
t.realm AS child_realm
FROM entity_version AS c INNER JOIN transactions as t
ON ( c.srid = t.srid )
WHERE c.entity_id = EntityID
WHERE c.entity_id = InternalEntityID
AND c._ipparent is Null
-- TODO This first SELECT statement is necessary because the second one
......@@ -375,7 +397,7 @@ BEGIN
ON (c._ipparent = p._iversion
AND c.entity_id = p.entity_id
AND t.srid = c.srid)
WHERE p.entity_id = EntityID;
WHERE p.entity_id = InternalEntityID;
END;
//
......@@ -412,56 +434,6 @@ BEGIN
END //
DROP PROCEDURE IF EXISTS setFileProperties //
/**
* Insert/Update file properties.
*
* If ENTITY_VERSIONING is enabled the old file properties are moved to
* `archive_files`.
*
* Parameters
* ----------
* EntityID
* The file's id.
* FilePath
* Path of the file in the internal file system. If NULL, an existing file
* entity is simply deleted.
* FileSize
* Size of the file in bytes.
* FileHash
* A Sha512 Hash of the file.
*/
CREATE PROCEDURE setFileProperties (
in EntityID INT UNSIGNED,
in FilePath TEXT,
in FileSize BIGINT UNSIGNED,
in FileHash VARCHAR(255)
)
BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
SELECT max(e._iversion) INTO IVersion
FROM entity_version AS e
WHERE e.entity_id = EntityID;
INSERT INTO archive_files (file_id, path, size, hash,
_iversion)
SELECT file_id, path, size, hash, IVersion AS _iversion
FROM files
WHERE file_id = EntityID;
END IF;
DELETE FROM files WHERE file_id = EntityID;
IF FilePath IS NOT NULL THEN
INSERT INTO files (file_id, path, size, hash)
VALUES (EntityID, FilePath, FileSize, unhex(FileHash));
END IF;
END //
DROP PROCEDURE IF EXISTS retrieveQueryTemplateDef //
/**
......@@ -469,9 +441,9 @@ DROP PROCEDURE IF EXISTS retrieveQueryTemplateDef //
*
* Parameters
* ----------
* EntityID
* EntityID : VARCHAR(255)
* The QueryTemplate's id.
* Version
* Version : VARBINARY(255)
* The QueryTemplate's version's id.
*
* Returns
......@@ -480,12 +452,16 @@ DROP PROCEDURE IF EXISTS retrieveQueryTemplateDef //
* QueryTemplate.
*/
CREATE PROCEDURE retrieveQueryTemplateDef (
in EntityID INT UNSIGNED,
in EntityID VARCHAR(255),
in Version VARBINARY(255))
retrieveQueryTemplateDefBody: BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
-- Are we at the head?
......@@ -494,11 +470,7 @@ retrieveQueryTemplateDefBody: BEGIN
END IF;
IF IsHead IS FALSE THEN
-- TODO Use get_iversion(EntityID, Version) instead? Or will that be much slower?
SELECT e._iversion INTO IVersion
FROM entity_version as e
WHERE e.entity_id = EntityID
AND e.version = Version;
SET IVersion = get_iversion(InternalEntityID, Version);
IF IVersion IS NULL THEN
-- RETURN EARLY - Version does not exist.
......@@ -507,7 +479,7 @@ retrieveQueryTemplateDefBody: BEGIN
SELECT definition
FROM archive_query_template_def
WHERE id = EntityID
WHERE id = InternalEntityID
AND _iversion = IVersion;
LEAVE retrieveQueryTemplateDefBody;
......@@ -516,7 +488,7 @@ retrieveQueryTemplateDefBody: BEGIN
SELECT definition
FROM query_template_def
WHERE id = EntityID;
WHERE id = InternalEntityID;
END //
......
/*
* ** 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
* Copyright (C) 2023 IndiScale GmbH <www.indiscale.com>
* Copyright (C) 2023 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
......@@ -18,56 +19,76 @@
* 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
*/
DROP PROCEDURE IF EXISTS db_5_0.getDependentEntities;
delimiter //
CREATE PROCEDURE db_5_0.getDependentEntities(in EntityID INT UNSIGNED)
/*
* Return all entities which either reference the given entity, use the given
* reference as data type, or are direct children of the given entity.
*
* This function used to make sure that no entity can be deleted which
* is still needed by others.
*
* Parameters
* ----------
* EntityID : VARCHAR(255)
* The entity id.
*
* ResultSet
* ---------
* EntityID : VARCHAR(255)
*
*/
CREATE PROCEDURE db_5_0.getDependentEntities(in EntityID VARCHAR(255))
BEGIN
DROP TEMPORARY TABLE IF EXISTS refering;
CREATE TEMPORARY TABLE refering (
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
DROP TEMPORARY TABLE IF EXISTS referring;
CREATE TEMPORARY TABLE referring (
id INT UNSIGNED UNIQUE
);
INSERT IGNORE INTO refering (id) SELECT entity_id FROM reference_data WHERE (value=EntityID OR property_id=EntityID) AND domain_id=0 AND entity_id!=EntityID;
INSERT IGNORE INTO refering (id) SELECT domain_id FROM reference_data WHERE (value=EntityID OR property_id=EntityID) AND domain_id!=EntityID AND entity_id!=EntityID AND domain_id!=0;
SELECT internal_id INTO InternalEntityID from entity_ids WHERE id = EntityID;
INSERT IGNORE INTO referring (id) SELECT entity_id FROM reference_data WHERE (value=InternalEntityID OR property_id=InternalEntityID) AND domain_id=0 AND entity_id!=InternalEntityID;
INSERT IGNORE INTO referring (id) SELECT domain_id FROM reference_data WHERE (value=InternalEntityID OR property_id=InternalEntityID) AND domain_id!=InternalEntityID AND entity_id!=InternalEntityID AND domain_id!=0;
INSERT IGNORE INTO refering (id) SELECT entity_id FROM text_data WHERE property_id=EntityID AND domain_id=0 AND entity_id!=EntityID;
INSERT IGNORE INTO refering (id) SELECT domain_id FROM text_data WHERE property_id=EntityID AND domain_id!=EntityID AND entity_id!=EntityID AND domain_id!=0;
INSERT IGNORE INTO referring (id) SELECT entity_id FROM text_data WHERE property_id=InternalEntityID AND domain_id=0 AND entity_id!=InternalEntityID;
INSERT IGNORE INTO referring (id) SELECT domain_id FROM text_data WHERE property_id=InternalEntityID AND domain_id!=InternalEntityID AND entity_id!=InternalEntityID AND domain_id!=0;
INSERT IGNORE INTO refering (id) SELECT entity_id FROM enum_data WHERE property_id=EntityID AND domain_id=0 AND entity_id!=EntityID;
INSERT IGNORE INTO refering (id) SELECT domain_id FROM enum_data WHERE property_id=EntityID AND domain_id!=EntityID AND entity_id!=EntityID AND domain_id!=0;
INSERT IGNORE INTO referring (id) SELECT entity_id FROM enum_data WHERE property_id=InternalEntityID AND domain_id=0 AND entity_id!=InternalEntityID;
INSERT IGNORE INTO referring (id) SELECT domain_id FROM enum_data WHERE property_id=InternalEntityID AND domain_id!=InternalEntityID AND entity_id!=InternalEntityID AND domain_id!=0;
INSERT IGNORE INTO refering (id) SELECT entity_id FROM name_data WHERE property_id=EntityID AND domain_id=0 AND entity_id!=EntityID;
INSERT IGNORE INTO refering (id) SELECT domain_id FROM name_data WHERE property_id=EntityID AND domain_id!=EntityID AND entity_id!=EntityID AND domain_id!=0;
INSERT IGNORE INTO referring (id) SELECT entity_id FROM name_data WHERE property_id=InternalEntityID AND domain_id=0 AND entity_id!=InternalEntityID;
INSERT IGNORE INTO referring (id) SELECT domain_id FROM name_data WHERE property_id=InternalEntityID AND domain_id!=InternalEntityID AND entity_id!=InternalEntityID AND domain_id!=0;
INSERT IGNORE INTO refering (id) SELECT entity_id FROM integer_data WHERE property_id=EntityID AND domain_id=0 AND entity_id!=EntityID;
INSERT IGNORE INTO refering (id) SELECT domain_id FROM integer_data WHERE property_id=EntityID AND domain_id!=EntityID AND entity_id!=EntityID AND domain_id!=0;
INSERT IGNORE INTO referring (id) SELECT entity_id FROM integer_data WHERE property_id=InternalEntityID AND domain_id=0 AND entity_id!=InternalEntityID;
INSERT IGNORE INTO referring (id) SELECT domain_id FROM integer_data WHERE property_id=InternalEntityID AND domain_id!=InternalEntityID AND entity_id!=InternalEntityID AND domain_id!=0;
INSERT IGNORE INTO refering (id) SELECT entity_id FROM double_data WHERE property_id=EntityID AND domain_id=0 AND entity_id!=EntityID;
INSERT IGNORE INTO refering (id) SELECT domain_id FROM double_data WHERE property_id=EntityID AND domain_id!=EntityID AND entity_id!=EntityID AND domain_id!=0;
INSERT IGNORE INTO referring (id) SELECT entity_id FROM double_data WHERE property_id=InternalEntityID AND domain_id=0 AND entity_id!=InternalEntityID;
INSERT IGNORE INTO referring (id) SELECT domain_id FROM double_data WHERE property_id=InternalEntityID AND domain_id!=InternalEntityID AND entity_id!=InternalEntityID AND domain_id!=0;
INSERT IGNORE INTO refering (id) SELECT entity_id FROM datetime_data WHERE property_id=EntityID AND domain_id=0 AND entity_id!=EntityID;
INSERT IGNORE INTO refering (id) SELECT domain_id FROM datetime_data WHERE property_id=EntityID AND domain_id!=EntityID AND entity_id!=EntityID AND domain_id!=0;
INSERT IGNORE INTO referring (id) SELECT entity_id FROM datetime_data WHERE property_id=InternalEntityID AND domain_id=0 AND entity_id!=InternalEntityID;
INSERT IGNORE INTO referring (id) SELECT domain_id FROM datetime_data WHERE property_id=InternalEntityID AND domain_id!=InternalEntityID AND entity_id!=InternalEntityID AND domain_id!=0;
INSERT IGNORE INTO refering (id) SELECT entity_id FROM date_data WHERE property_id=EntityID AND domain_id=0 AND entity_id!=EntityID;
INSERT IGNORE INTO refering (id) SELECT domain_id FROM date_data WHERE property_id=EntityID AND domain_id!=EntityID AND entity_id!=EntityID AND domain_id!=0;
INSERT IGNORE INTO referring (id) SELECT entity_id FROM date_data WHERE property_id=InternalEntityID AND domain_id=0 AND entity_id!=InternalEntityID;
INSERT IGNORE INTO referring (id) SELECT domain_id FROM date_data WHERE property_id=InternalEntityID AND domain_id!=InternalEntityID AND entity_id!=InternalEntityID AND domain_id!=0;
INSERT IGNORE INTO refering (id) SELECT entity_id FROM null_data WHERE property_id=EntityID AND domain_id=0 AND entity_id!=EntityID;
INSERT IGNORE INTO refering (id) SELECT domain_id FROM null_data WHERE property_id=EntityID AND domain_id!=EntityID AND entity_id!=EntityID AND domain_id!=0;
INSERT IGNORE INTO referring (id) SELECT entity_id FROM null_data WHERE property_id=InternalEntityID AND domain_id=0 AND entity_id!=InternalEntityID;
INSERT IGNORE INTO referring (id) SELECT domain_id FROM null_data WHERE property_id=InternalEntityID AND domain_id!=InternalEntityID AND entity_id!=InternalEntityID AND domain_id!=0;
INSERT IGNORE INTO refering (id) SELECT entity_id from data_type WHERE datatype=EntityID AND domain_id=0 AND entity_id!=EntityID;
INSERT IGNORE INTO refering (id) SELECT domain_id from data_type WHERE datatype=EntityID;
INSERT IGNORE INTO referring (id) SELECT entity_id from data_type WHERE datatype=InternalEntityID AND domain_id=0 AND entity_id!=InternalEntityID;
INSERT IGNORE INTO referring (id) SELECT domain_id from data_type WHERE datatype=InternalEntityID;
INSERT IGNORE INTO referring (id) SELECT child FROM isa_cache WHERE parent = InternalEntityID AND rpath = child;
Select id from refering WHERE id!=0 and id!=EntityID;
SELECT e.id FROM referring AS r LEFT JOIN entity_ids AS e ON r.id = e.internal_id WHERE r.id!=0 AND e.internal_id!=InternalEntityID;
DROP TEMPORARY TABLE refering;
DROP TEMPORARY TABLE referring;
END;
//
......
/*
* ** 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
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 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
......@@ -17,16 +18,27 @@
*
* 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
*/
Drop Procedure if exists db_5_0.getFileIdByPath;
Delimiter //
Create Procedure db_5_0.getFileIdByPath (in FilePath VARCHAR(255))
/*
* Return a file's id for a given path or nothing if the path is unknown.
*
* Parameters
* ----------
* FilePath : TEXT
* The file's path.
*
* Returns
* -------
* EntityID : VARCHAR(255)
*/
Create Procedure db_5_0.getFileIdByPath (in FilePath TEXT)
BEGIN
Select file_id as FileID from files where path=FilePath LIMIT 1;
SELECT e.id AS FileID FROM files AS f LEFT JOIN entity_ids ON e.internal_in = f.file_id WHERE f.path=FilePath LIMIT 1;
END;
//
......
/*
* ** 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
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 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
......@@ -17,31 +16,48 @@
*
* 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
*/
DROP PROCEDURE IF EXISTS db_5_0.getIdByName;
DELIMITER //
DROP PROCEDURE IF EXISTS db_5_0.retrieveSubEntity //
/**
CREATE PROCEDURE db_5_0.retrieveSubEntity(in EntityID INT UNSIGNED, in DomainID INT UNSIGNED)
/*
* Return the Entity id(s) for a given name. Optionally, filter by role and set
* a limit.
*
* Parameters
* ----------
* Name : VARCHAR(255)
* The entity's name.
* Role : VARCHAR(255)
* E.g. RecordType, Record, Property,...
* Lmt : INT UNSIGNED
* Limit the number of returned entity ids.
*
* Returns
* -------
* EntityID : VARCHAR(255)
*/
CREATE PROCEDURE db_5_0.getIdByName(in Name VARCHAR(255), in Role VARCHAR(255), in Lmt INT UNSIGNED)
BEGIN
DECLARE FilePath VARCHAR(255) DEFAULT NULL;
DECLARE FileSize VARCHAR(255) DEFAULT NULL;
DECLARE FileHash VARCHAR(255) DEFAULT NULL;
Select path, size, hex(hash) into FilePath, FileSize, FileHash from files where file_id = EntityID LIMIT 1;
Select DomainID as DomainID,
EntityID as EntityID,
e.name as EntityName,
e.description as EntityDesc,
e.role as EntityRole,
FileSize as FileSize,
FilePath as FilePath,
FileHash as FileHash
from entities e where id = EntityID LIMIT 1;
SET @stmtStr = "SELECT e.id AS id FROM name_data AS n JOIN entity_ids AS e ON (n.domain_id=0 AND n.property_id=20 AND e.internal_id = n.entity_id) JOIN entities AS i ON (i.id = e.internal_id) WHERE n.value = ?";
IF Role IS NULL THEN
SET @stmtStr = CONCAT(@stmtStr, " AND i.role!='ROLE'");
ELSE
SET @stmtStr = CONCAT(@stmtStr, " AND i.role='", Role, "'");
END IF;
IF Lmt IS NOT NULL THEN
SET @stmtStr = CONCAT(@stmtStr, " LIMIT ", Lmt);
END IF;
SET @vName = Name;
PREPARE stmt FROM @stmtStr;
EXECUTE stmt USING @vName;
DEALLOCATE PREPARE stmt;
END;
//
**/
DELIMITER ;
/*
* ** 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
*/
#-- old procedure.
Drop Procedure if exists db_5_0.getInfo;
/*
* ** 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
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale
* Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -19,8 +18,6 @@
*
* 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
*/
......@@ -31,12 +28,14 @@ delimiter //
Parameters
==========
EntityID : VARCHAR(255)
The entity id.
EntityName : VARCHAR(255)
EntityDesc : TEXT
EntityRole : VARCHAR(255)
Currently one of 'RECORDTYPE', 'RECORD', 'FILE', 'DOMAIN', 'PROPERTY',
Currently one of 'RECORDTYPE', 'RECORD', 'FILE', 'PROPERTY',
'DATATYPE', 'ROLE', 'QUERYTEMPLATE'
ACL : VARBINARY(65525)
......@@ -44,17 +43,17 @@ ACL : VARBINARY(65525)
Select
======
A tuple (EntityID, Version)
(Version)
*/
CREATE PROCEDURE db_5_0.insertEntity(in EntityName VARCHAR(255), in EntityDesc TEXT, in EntityRole VARCHAR(255), in ACL VARBINARY(65525))
CREATE PROCEDURE db_5_0.insertEntity(in EntityID VARCHAR(255), in EntityName VARCHAR(255), in EntityDesc TEXT, in EntityRole VARCHAR(255), in ACL VARBINARY(65525))
BEGIN
DECLARE NewEntityID INT UNSIGNED DEFAULT NULL;
DECLARE NewACLID INT UNSIGNED DEFAULT NULL;
DECLARE Hash VARBINARY(255) DEFAULT NULL;
DECLARE Version VARBINARY(255) DEFAULT NULL;
DECLARE Transaction VARBINARY(255) DEFAULT NULL;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
-- insert the acl. the new acl id is being written (c-style) into the
-- insert the acl. The new acl id is written (c-style) into the
-- variable NewACLID.
call entityACL(NewACLID, ACL);
......@@ -63,13 +62,15 @@ BEGIN
VALUES (EntityDesc, EntityRole, NewACLID);
-- ... and return the generated id
SET NewEntityID = LAST_INSERT_ID();
SET InternalEntityID = LAST_INSERT_ID();
INSERT INTO entity_ids (internal_id, id) VALUES (InternalEntityID, EntityID);
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
-- TODO this is transaction-scoped variable. Is this a good idea?
SET Transaction = @SRID;
SET Version = SHA1(UUID());
CALL insert_single_child_version(NewEntityID, Hash, Version, Null, Transaction);
CALL insert_single_child_version(InternalEntityID, Hash, Version, Null, Transaction);
END IF;
-- insert the name of the entity into name_data table
......@@ -77,10 +78,10 @@ BEGIN
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);
VALUES (0, InternalEntityID, 20, EntityName, "FIX", 0);
END IF;
SELECT NewEntityID as EntityID, Version as Version;
SELECT Version as Version;
END;
//
......