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

Target

Select target project
  • caosdb/src/caosdb-mysqlbackend
1 result
Show changes
Commits on Source (63)
Showing
with 660 additions and 237 deletions
version: '3.6'
services:
sqldb:
image: mariadb:10.5
volumes:
- type: volume
source: "caosdb-sqldata"
target: /var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: caosdb1234
networks:
# available on port 3306, host name 'sqldb'
- caosnet
ports:
- 3306:3306
# A well-defined network for caosdb
volumes:
caosdb-sqldata:
networks:
caosnet:
driver: bridge
......@@ -62,21 +62,6 @@ unittests-mariadb:
script:
- make pipeline-test SQL_HOST=mariadb
# Run the unit tests with MySQL 8
unittests-mysql-8:
tags: [ docker ]
stage: test
# Should not stop the pipeline from continuing.
allow_failure: true
services:
- name: mysql:8.0
command: ["--default-authentication-plugin=mysql_native_password"]
script:
- sed "s/NO_AUTO_CREATE_USER,//" -i tests/example.dump.sql
- rm tests/test_autotap.sql
- make pipeline-test SQL_HOST=mysql
# Run the unit tests with MySQL 5
unittests-mysql-5:
tags: [ docker ]
......@@ -84,7 +69,7 @@ unittests-mysql-5:
# Should not stop the pipeline from continuing.
allow_failure: true
services:
- name: mysql:5.7
- name: mysql:5.7.36
command: ["--default-authentication-plugin=mysql_native_password"]
script:
......
## Summary
*Please give a short summary of what the issue is.*
## Expected Behavior
*What did you expect how the software should behave?*
## Actual Behavior
*What did the software actually do?*
## Steps to Reproduce the Problem
*Please describe, step by step, how others can reproduce the problem. Please try these steps for yourself on a clean system.*
1.
2.
3.
## Specifications
- Version: *Which version of this software?*
- Platform: *Which operating system, which other relevant software versions?*
## Possible fixes
*Do you have ideas how the issue can be resolved?*
# Summary
*Insert a meaningful description for this merge request here: What is the new/changed behavior?
Which bug has been fixed? Are there related issues?*
# Focus
*Point the reviewer to the core of the code change. Where should they start reading? What should
they focus on (e.g. security, performance, maintainability, user-friendliness, compliance with the
specs, finding more corner cases, concrete questions)?*
# Test Environment
*How to set up a test environment for manual testing?*
# Check List for the Author
Please, prepare your MR for a review. Be sure to write a summary and a focus and create gitlab
comments for the reviewer. They should guide the reviewer through the changes, explain your changes
and also point out open questions. For further good practices have a look at [our review
guidelines](https://gitlab.com/caosdb/caosdb/-/blob/dev/REVIEW_GUIDELINES.md)
- [ ] All automated tests pass
- [ ] Reference related issues
- [ ] Up-to-date CHANGELOG.md (or not necessary)
- [ ] Up-to-date JSON schema (or not necessary)
- [ ] Appropriate user and developer documentation (or not necessary)
- Update / write published documentation (`make doc`).
- How do I use the software? Assume "stupid" users.
- How do I develop or debug the software? Assume novice developers.
- [ ] Annotations in code (Gitlab comments)
- Intent of new code
- Problems with old code
- Why this implementation?
# Check List for the Reviewer
- [ ] I understand the intent of this MR
- [ ] All automated tests pass
- [ ] Up-to-date CHANGELOG.md (or not necessary)
- [ ] Appropriate user and developer documentation (or not necessary), also in published
documentation.
- [ ] The test environment setup works and the intended behavior is reproducible in the test
environment
- [ ] In-code documentation and comments are up-to-date.
- [ ] Check: Are there specifications? Are they satisfied?
For further good practices have a look at [our review guidelines](https://gitlab.com/caosdb/caosdb/-/blob/dev/REVIEW_GUIDELINES.md).
/assign me
/target_branch dev
......@@ -19,16 +19,112 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security ###
## [5.0.0] - 2021-10-28 ##
## [7.0.1] - 2023-11-01
(Timm Fitschen)
### Added ###
* #33 CI pipeline for MySQL (was only MariaDB before).
* Sanity checks during `make install` and `make upgrade`.
## [7.0.0] - 2023-10-25 ##
(Timm Fitschen)
### Changed ###
* Change signature of procedure `insertEntityDataType`: expect the data type ID
instead of the name.
* Change result set of procedure `retrieveEntity`: Rename column `Datatype` to
`DatatypeName` and add column `DatatypeID`.
* Change result set of procedure `retrieveOverrides`: Rename column
`type_override` to `type_name_override` and add `type_id_override`.
* Change signature of procedure `updateEntity`: expect the data type ID instead
to the name.
* Internal ids, when returned by `retrieveEntityProperties`,
`registerReplacementIds`, or `retrieveOverrides`, are prefixed by a special
character which serves as a ephemeral marker. Currently this is `$` but this
may change in the future if there is a more suitable candidate.
### Deprecated ###
* MySQL Support. Last version which is known to work well with LinkAhead is MySQL 5.7.36
### Fixed ###
* Unknown Server Error when inserting an Entity.
[linkahead-mariadbbackend#48](https://gitlab.indiscale.com/caosdb/src/caosdb-mysqlbackend/-/issues/48).
* Fix broken `initEntity` procedure (and change the first parameters type from
INT UNSIGNED to VARCHAR(255) which is non-breaking).
## [6.0.1 2023-10-18] ##
### Fixed ###
* Old passwords table is removed from dumps where it still exists.
## [6.0.0 2023-10-17] ##
This is a major update. Switching from integer ids for internal and external use to string ids for the external use while keeping the old integer ids for internal use.
### Added ###
* Table `entity_ids`
* Procedure `getIdByName`
* Procedure `insertEntityDataType` and `insertEntityCollection`
* Procedure `setFileProperties`.
### Changed ###
* Rename PROCEDURE `registerSubdomain` to `registerReplacementIds`.
* Change column `entities.role` datatype: replace 'DOMAIN' enum value with `_REPLACEMENT`.
* Change column `transactions_log.entity_id` to VARCHAR(255)
* Change column `user_info.entity` to VARCHAR(255)
* Change signature of procedure `applyIDFilter` - `EntityID VARCHAR(255)`
* Change signature of procedure `initBackreference` - `EntityID VARCHAR(255)` and `PropertyID VARCHAR(255)`
* Change signature of procedure `initPOVPropertiesTable` - `PropertyID VARCHAR(255)`
* Change signature of procedure `initPOVRefidsTable` - `PropertyID VARCHAR(255)`
* Change signature of procedure `initSubEntity` - `EntityID VARCHAR(255)`
* Change signature of procedure `deleteEntity` - `EntityID VARCHAR(255)`
* Change signature of procedure `deleteEntityProperties` - `EntityID VARCHAR(255)`
* Change signature of procedure `get_primary_parent_version` - `EntityID VARCHAR(255)`
* Change signature of procedure `get_version_timestamp` - `EntityID VARCHAR(255)`
* Change signature of procedure `get_head_version` - `EntityID VARCHAR(255)`
* Change signature of procedure `get_head_relative` - `EntityID VARCHAR(255)`
* Change signature of procedure `get_version_history` - `EntityID VARCHAR(255)`
* Change signature of procedure `retrieveQueryTemplateDef` - `EntityID VARCHAR(255)`
* Change signature of procedure `getDependentEntities` - `EntityID VARCHAR(255)`
* Change signature of procedure `insertEntity` - Add parameter `EntityID VARCHAR(255)`
* Change signature of procedure `insertEntityProperty` - `EntityID VARCHAR(255)` and `PropertyID VARCHAR(255)`, `DomainID VARCHAR(255)`, `DatatypeOverride VARCHAR(255)`
* Change signature of procedure `insertIsa` - `ChildID VARCHAR(255)`, `ParentID VARCHAR(255)`.
* Change signature of procedure `isSubtype` - `ChildID VARCHAR(255)`, `ParentID VARCHAR(255)`.
* Change signature of procedure `retrieveEntity` - `EntityID VARCHAR(255)`
* Change signature of procedure `retrieveOverrides` - `EntityID VARCHAR(255)`, `DomainID VARCHAR(255)`
* Change signature of procedure `retrieveEntityParents` - `EntityID VARCHAR(255)`
* Change signature of procedure `retrieveEntityProperties` - `EntityID VARCHAR(255)`, `DomainID VARCHAR(255)`
* Change signature of procedure `updateEntity` - `EntityID VARCHAR(255)`
### Removed ###
* Deactivate procedure `delete_all_entity_versions`. This might be used in the
future, that is why we keep the code in a comment.
* Drop procedure `retrieveSubEntity`
* Drop procedure `retrieveDatatype`
* Drop procedure `retrieveGroup`
* Drop procedure `getInfo`
* Drop procedure `getRole`
* Drop procedure `setPassword`
* Drop procedure `initAutoIncrement`
* Delete special entity 50 (SQLite Datatype)
* Delete special entity 99 (Work-around for the auto-increment)
### Fixed ###
* Change signature of procedure `getFileIdByPath` - `FilePath TEXT` - this length is needed for the path column of `file_entities`.
## [5.0.0] - 2021-10-28 ##
### Added ###
* #33 CI pipeline for MySQL (was only MariaDB before).
### Removed ###
* `getRules` procedure and the `rules` table. The jobs rules are being
......@@ -41,8 +137,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* #32 Removed unused `groups` table from installation routines which prevented
the installation with MySQL 8.
### Security ###
## [4.1.0] - 2021-06-11 ##
### Added ###
......@@ -80,8 +174,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `createTmpTable`
* Added a `direct` column to `archive_isa` table
### Deprecated ###
### Removed ###
* unused procedures:
......@@ -107,8 +199,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
version resultet in an error. See corresponding test in `caosdb-pyinttest`
`tests/test_versioning.py::test_datatype_without_name`
### Security ###
## [3.0.0] - 2020-09-01 ##
### Added ###
......@@ -162,5 +252,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Bug in `updateEntity.sql` (when updating the primary name without a prior call
to `deleteEntityProperties`). Same thing for `deleteEntity`.
* #21 Bug which prevented deletion of deeply inheriting entities, if versioning was enabled.
### Security ###
......@@ -34,6 +34,7 @@ test-connection:
.PHONY: upgrade
upgrade:
@cd patches; ./applyPatches.sh --env=../.config
@./utils/make_db sanity_check
.PHONY: install
install: _install _grant upgrade
......@@ -88,4 +89,5 @@ pipeline-test:
sleep 10
make install
./utils/make_db restore_db tests/example.dump.sql
make upgrade
./tests/test_utils.sh
......@@ -3,8 +3,8 @@
## Welcome
This is the **CaosDB MySQL Backend** repository and a part of the
CaosDB project.
This is the **LinkAhead MySQL Backend** repository and a part of the
LinkAhead project.
## Setup
......@@ -18,24 +18,26 @@ Please refer to the [official documentation](https://docs.indiscale.com/caosdb-m
## Contributing
Thank you very much to all contributers—[past, present](https://gitlab.com/caosdb/caosdb/-/blob/dev/HUMANS.md), and prospective ones.
Thank you very much to all contributers—[past,
present](https://gitlab.com/linkahead/linkahead/-/blob/main/HUMANS.md), and prospective
ones.
### Code of Conduct
By participating, you are expected to uphold our [Code of Conduct](https://gitlab.com/caosdb/caosdb/-/blob/dev/CODE_OF_CONDUCT.md).
By participating, you are expected to uphold our [Code of
Conduct](https://gitlab.com/linkahead/linkahead/-/blob/main/CODE_OF_CONDUCT.md).
### How to Contribute
* You found a bug, have a question, or want to request a feature? Please
[create an issue](https://gitlab.com/caosdb/caosdb-mysqlbackend/-/issues).
* You want to contribute code? Please fork the repository and create a merge
request in GitLab and choose this repository as target. Make sure to select
"Allow commits from members who can merge the target branch" under Contribution
when creating the merge request. This allows our team to work with you on your request.
- If you have a suggestion for the [documentation](https://docs.indiscale.com/caosdb-mysqlbackend/),
the preferred way is also a merge request as describe above (the documentation resides in `src/doc`).
However, you can also create an issue for it.
- You can also contact us at **info (AT) caosdb.org**.
* You found a bug, have a question, or want to request a feature? Please
[create an issue](https://gitlab.com/linkahead/linkahead-mariadbbackend/-/issues).
* You want to contribute code?
* **Forking:** Please fork the repository and create a merge request in GitLab and choose this repository as
target. Make sure to select "Allow commits from members who can merge the target branch" under
Contribution when creating the merge request. This allows our team to work with you on your
request.
* You can also join the LinkAhead community on
[#linkahead:matrix.org](https://matrix.to/#/!unwwlTfOznjEnMMXxf:matrix.org).
## License
......
# Setup of the CaosDB SQL back end
## Dependencies
* `MariaDB Client 10.1`, `MySQL Client 5.5`, or later versions. In the case of
MySQL, version 5.6 is recommended.
- make
* `MariaDB Client 10.1` or later, `MySQL Client >=5.5, <=5.7.36`.
* make
## Create the configuration
* Create an empty `.config` file. For the default values and the meaning of
......@@ -87,6 +87,19 @@ with the then current version of the stored entities.
* Alternatively, to run the tests in a containerized MariaDB instance, run `make test-docker`,
followed by `make test-docker-stop`.
### Running in a Docker Container
You can use `.docker/docker-compose.yml` to start a docker container
(`docker-compose -f .docker/docker-compose.yml up -d`) that runs
mariadb. You need appropriate settings in `.config`.
Due to [a Bug](https://gitlab.com/linkahead/linkahead-mariadbbackend/-/issues/33)
`MYSQL_CMD="mariadb -h localhost -P3306"` and
`DATABASE_USER_HOST_LIST=%,`
After the first start, you need to install the database: `make install`.
Then, you can connect to it with
`mariadb -h localhost -P3306 -u caosdb -prandom1234 caosdb`.
### Troubleshooting
#### MySQL has failing tests
......
......@@ -2,7 +2,7 @@
This document specifies release guidelines in addition to the general release
guidelines of the CaosDB Project
([RELEASE_GUIDELINES.md](https://gitlab.com/caosdb/caosdb/blob/dev/RELEASE_GUIDELINES.md))
([RELEASE_GUIDELINES.md](https://gitlab.com/caosdb/caosdb-meta/-/blob/dev/RELEASE_GUIDELINES.md))
## General Prerequisites
......@@ -19,10 +19,20 @@ guidelines of the CaosDB Project
2. Check all general prerequisites.
4. Merge the release branch into the main branch.
3. Assure that the latest patch actually updates the CaosDBVersion() procedure
and that the version matches the version you are about to release.
5. Tag the latest commit of the main branch with `v<VERSION>`.
4. Update version in `doc/conf.py`.
6. Delete the release branch.
5. Merge the release branch into the main branch.
7. Merge the main branch back into the dev branch.
6. Wait for the main branch pipeline to pass.
7. Tag the latest commit of the main branch with `v<VERSION>`.
8. Delete the release branch.
9. Merge the main branch back into the dev branch and add the `[UNRELEASED]`
section to the CHANGELOG.
10. Create a release at the [gitlab repo](https://gitlab.com/linkahead/linkahead-mariadbbackend/-/releases)
......@@ -26,9 +26,9 @@ copyright = '2021, IndiScale GmbH'
author = 'Daniel Hornung'
# The short X.Y version
version = '5.1'
version = '7.0.1'
# The full version, including alpha/beta/rc tags
release = '5.1.0-SNAPSHOT'
release = '7.0.1'
# -- General configuration ---------------------------------------------------
......@@ -46,7 +46,7 @@ extensions = [
'sphinx.ext.todo',
"sphinx.ext.autodoc",
"recommonmark", # For markdown files.
# 'autoapi.extension',
# 'autoapi.extension',
# 'sphinx.ext.intersphinx',
# 'sphinx.ext.napoleon', # For Google style docstrings
"sphinx_rtd_theme",
......
No preview for this file type
/*
* 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
/*
* ** 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
The ID of the Entity.
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
Child entity for which all parental relations should be deleted.
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>
* 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
......@@ -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;
DELETE FROM entity_version WHERE entity_id = EntityID;
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE 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
* Offset : 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,
EntityID VARCHAR(255),
Offset 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,7 +309,7 @@ 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
);
......@@ -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 //
......