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

Initial Commit

AGPLv3 Veröffentlichung gemäß Dienstanweisung vom 15. August 2018.
parents
No related branches found
No related tags found
No related merge requests found
Showing
with 1247 additions and 0 deletions
# dot files
.*
!/.gitignore
# dumps
*.dump.sql
This diff is collapsed.
# Welcome
This is the **CaosDB MySQL Back-end** repository and a part of the CaosDB
project.
# Setup
Please read the [README_SETUP.md](README_SETUP.md) for instructions on how to
setup this code.
# Further Reading
Please refer to the [official gitlab repository of the CaosDB
project](https://gitlab.gwdg.de/bmp-caosdb/caosdb) for more information.
# License
Copyright (C) 2018 Research Group Biomedical Physics, Max Planck Institute for
Dynamics and Self-Organization Göttingen.
All files in this repository are licensed under a [GNU Affero General Public
License](LICENCE.md) (version 3 or later).
# Setup the CaosDB MySQL Back-end
## Dependencies
* `MariaDB Client 10.1`, `MySQL Client 5.5`, or later versions. MySQL 5.6 is recommended.
## Configuration
* Run `./configure`. For the default values and the meaning of these default values see [config.defaults](config.defaults). The `configure` script also promts for a (new) user password. Remember that one, since it will be the password of the mysql user which is used by the caosdb server.
* If there is no `mysql-config-editor` (`MySQL 5.5`. and `MariaDB`) then the user is promted for the `MYSQL_USER_PASSWORD`, that is the password of the `MYSQL_USER`. The plain password is stored in the `.config` file. So make sure nobody else can read it.
* If you are using MariaDB and your `root` user uses pam authentication, no pasword string is required. When promted for the `MYSQL_USER_PASSWORD` just leave it blank and hit enter. But you need be login as root for the installation and upgrade process.
## Install
* Run `make install`. If a there is a database with the name you have choosen during the configuration, you need to reconfigure or delete the database first.
## Upgrade
* Run `make upgrade`. Upgrades the database to the last version.
## Drop Database
* If you want to delete your database, run `make drop-$DATABASE_NAME`. **Use this with caution!!!** If you did not backup your database, **everything will be lost afterwards.** And no, there is no addional promt "Are you sure, that you want to do this?". If you do this, you *actually* do this.
# Versioning
Starting with version `TODO: the next version`, the versions of the CaosDB MySQL Back-end must follow the principles of [Semantic Versioning 2.0.0](https://semver.org). In summary:
> Given a version number MAJOR.MINOR.PATCH, increment the:
>
> 1. MAJOR version when you make incompatible API changes,
> 2. MINOR version when you add functionality in a backwards-compatible manner, and
> 3. PATCH version when you make backwards-compatible bug fixes.
>
> Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
## §1 API Changes.
1. All tables, stored procedures and stored functions which names do not begin with the character `_` belong to the api and are not implementation specific.
2. Specifically, that means for all components of the API:
1. Changes to the design of existing tables or their colums (name, datatype, etc.) MUST always result in anew MAJOR version. The only exception from this rule are changes to the description of a table or column.
2. Deleting tables is an incompatible API change and results in a new MAJOR version.
3. Changes to the stored procedures and functions, which change the signature (i.e the list of parameters) is an incompatible change, and results in a new MAJOR version.
4. Adding new stored functions, procedures or tables results in a new MINOR version.
5. Changing just a bit of code inside a stored procedure or function results in a new PATCH version.
## §2 Other Changes.
1. Changes to any non-API tables, functions and procedures results in a new PATCH version.
#!/bin/bash
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
#dump a database with all procedures, permissions, structure and data
BACKUPDIR=./backup #The directory which the dump is to be stored to. Do not change it here. Use the --backupdir=./my/dir/ option!
PRINT_HELP="--backupdir=BACKUPDIR\n\tThe directory which the dump is to be stored to. (Defaults to ./backup)"
# load useful stuff - scans the parameters and so on...
. patches/utils/patch_header.sh
#create backup dir if not exists
[ -d $BACKUPDIR ] || mkdir $BACKUPDIR
function backup {
# parameters: login-path, database, outfile
if [ -e "$3" ]; then
failure "dumpfile already exists."
fi
echo -n "Dumping database $3 to $4 ... "
$CMD_MYSQL_DUMP --opt --default-character-set=utf8 --routines --login-path=$1 $2 > ${3}
success
}
##test dump file exists
#touch dumpfile.tmp
#backup 0 1 2 "dumpfile.tmp"
#rm dumpfile.tmp
DATE=$(date -u --rfc-3339=ns | sed 's/ /T/g')
BACKUPFILE=${BACKUPDIR}/${DATABASE}.${DATE}.dump.sql
backup $LOGIN_PATH $DATABASE $BACKUPFILE
#
# ** header v2.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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
# Commands
MYSQL_CMD=$(command -v mysql) # The MySQL client program.
MYSQLADMIN_CMD=$(command -v mysqladmin) # The mysqladmin program which comes with the MySQL client.
MYSQLDUMP_CMD=$(command -v mysqldump) # The mysqldump program which comes with the MySQL client.
MYSQL_CONFIG_EDITOR_CMD=$(command -v mysql_config_editor) # The mysql_config_editor program which is used to store the credentials.
# MySQL Connection
MYSQL_HOST=localhost #The host of the MySQL server.
MYSQL_USER=root # The user for the installation. Note: This is not the user which will then be used by the CaosDB Server.
# DATABASE
DATABASE_NAME=caosdb #The name of the database.
DATABASE_USER=caosdb_user #The user which is used by the CaosDB Server for the connection.
DATABASE_USER_HOST_LIST=localhost, # A comma-separated list of hosts from which MySQL will accept logins. This option follows the MySQL-style for host-names and ip addresses. E.g. `%` is a wildcard for all hosts, `192.168.0.%` permits logins from the local network etc.
#!/bin/bash
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
# defaults
source config.defaults
OPTIONS=$(sed -r '/^(#|\s*$)/d' config.defaults | sed -r 's/=.*$//g')
# override with old config
if [ -e .config ]; then
source .config
fi
# DEBUG - print all options:
# for opt in $OPTIONS; do echo $opt = ${!opt}; done
# Promt the user to specify an option.
for opt in $OPTIONS; do
opt_default=$(echo "${!opt}" | sed 's/#.*$//g')
read -p "$opt [$opt_default]: " val
if [ ! ${#val} -eq 0 ]; then
eval "$opt=\"$val\""
fi
done
# check all options
printf "\n\n--- checking your configuration ---"
for opt in $OPTIONS; do
if [ -z "$opt" ]; then echo "${!opt} is not defined." ; fi ;
if [ "CMD" = "${opt:(-3)}" ]; then
printf "\n${opt} "
if test $(command -v ${!opt}) ; then
printf ". . . [OK]"
else
printf ". . . [FAILURE - could not find ${!opt}]"
fi
fi
done
printf "\n"
printf "\n\n--- finishing up ---"
if test $(command -v ${MYSQL_CONFIG_EDITOR_CMD}) ; then
LOGIN_PATH=caosdb_login_to_$DATABASE_NAME
OPTIONS=$(printf "$OPTIONS\nLOGIN_PATH")
$MYSQL_CONFIG_EDITOR_CMD remove --login-path=$LOGIN_PATH
printf "\nFor user $MYSQL_USER - "
$MYSQL_CONFIG_EDITOR_CMD set --login_path=$LOGIN_PATH --host=$MYSQL_HOST --user=root --password
else
printf "\nBecause there is no mysql_config_editor avaible, we need the password for the mysql user '$MYSQL_USER'.\n"
read -p "MYSQL_USER_PASSWORD []: " MYSQL_USER_PASSWORD
OPTIONS=$(printf "$OPTIONS\nMYSQL_USER_PASSWORD")
fi
# DEBUG - print all options:
# for opt in $OPTIONS; do echo $opt = ${!opt}; done
# write to .config
rm -f .config
for opt in $OPTIONS; do
esc_hash=${!opt//#/\\\#}
esc_dollar=${esc_hash//\$/'$$'}
esc_dq=${esc_dollar//\"/\\\"}
esc_sq=${esc_dq//\'/\\\'}
echo "$opt=$esc_sq" >> .config
done
/*
* ** 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
*/
#-- MySQL batch stack to create the CaosDB database structure, v2.0.1
#-- AUTHOR: Timm Fitschen (timm.fitschen@ds.mpg.de)
#-- DATE: 2015-10-22
#--
#--
#--
#-- *************
#-- Drop database
#-- *************
DROP DATABASE IF EXISTS db_2_0;
#-- ***************
#-- Create database
#-- ***************
CREATE DATABASE IF NOT EXISTS db_2_0 DEFAULT CHARSET=utf8 DEFAULT COLLATE=utf8_unicode_ci;
USE db_2_0;
#-- ***********************
#-- Create function version
#-- ***********************
CREATE FUNCTION CaosDBVersion() RETURNS VARCHAR(255) DETERMINISTIC
RETURN 'v2.0.1';
#-- ************************
#-- Create table entities
#-- ************************
CREATE TABLE IF NOT EXISTS entities (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier.',
name VARCHAR(255) NULL COMMENT 'Name of the entity.',
description VARCHAR(255) NULL COMMENT 'Description of the entity.',
role ENUM('RECORDTYPE', 'RECORD', 'FILE', 'DOMAIN', 'PROPERTY', 'USER', 'GROUP', 'UNIT', 'DATATYPE')
NULL COMMENT 'Role of the entity',
acl INT UNSIGNED NULL COMMENT 'Access Control List for the entity.'
#-- , CONSTRAINT `ent_acl_acl_id` FOREIGN KEY (`acl`) REFERENCES `acl` (`id`)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS name_overrides (
domain_id INT UNSIGNED,
entity_id INT UNSIGNED,
name VARCHAR(255),
UNIQUE KEY (domain_id, entity_id),
CONSTRAINT `nameov_d_ent_id` FOREIGN KEY (`domain_id`) REFERENCES `entities` (`id`),
CONSTRAINT `nameov_e_ent_id` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- ************************************
#-- Create table is-a
#-- ************************************
CREATE TABLE IF NOT EXISTS isa (
child INT UNSIGNED NOT NULL COMMENT 'Child',
parent INT UNSIGNED NOT NULL COMMENT 'Parent',
type Enum('INHERITANCE', 'SUBTYPING')
NOT NULL COMMENT 'Type of is-a relation.',
UNIQUE KEY (child, parent),
CONSTRAINT `parent_entity` FOREIGN KEY (`parent`) REFERENCES `entities` (`id`),
CONSTRAINT `child_entity` FOREIGN KEY (`child`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- ***************************
#-- Create table reference_data
#-- ***************************
CREATE TABLE IF NOT EXISTS reference_data (
domain_id INT UNSIGNED NOT NULL COMMENT 'Domain.',
entity_id INT UNSIGNED NOT NULL COMMENT 'Entity.',
property_id INT UNSIGNED NOT NULL COMMENT 'Property.',
value INT UNSIGNED NULL COMMENT 'Value.',
status Enum('OBLIGATORY', 'RECOMMENDED', 'SUGGESTED', 'FIX', 'REPLACEMENT')
NOT NULL COMMENT 'Status of this statement.',
pidx TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Index of the property.',
INDEX(entity_id,property_id),
CONSTRAINT `ref_domain_id_entity` FOREIGN KEY (`domain_id`) REFERENCES `entities` (`id`),
CONSTRAINT `ref_entity_id_entity` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`),
CONSTRAINT `ref_property_id_entity` FOREIGN KEY (`property_id`) REFERENCES `entities` (`id`),
CONSTRAINT `ref_value_entity` FOREIGN KEY (`value`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- *************************
#-- Create table integer_data
#-- *************************
CREATE TABLE IF NOT EXISTS integer_data (
domain_id INT UNSIGNED NOT NULL COMMENT 'Domain.',
entity_id INT UNSIGNED NOT NULL COMMENT 'Entity.',
property_id INT UNSIGNED NOT NULL COMMENT 'Property.',
value INT NULL COMMENT 'Value.',
status Enum('OBLIGATORY', 'RECOMMENDED', 'SUGGESTED', 'FIX', 'REPLACEMENT')
NOT NULL COMMENT 'Status of this statement.',
pidx TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Index of the property.',
INDEX(domain_id,entity_id),
CONSTRAINT `int_domain_id_entity` FOREIGN KEY (`domain_id`) REFERENCES `entities` (`id`),
CONSTRAINT `int_entity_id_entity` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`),
CONSTRAINT `int_property_id_entity` FOREIGN KEY (`property_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- ************************
#-- Create table double_data
#-- ************************
CREATE TABLE IF NOT EXISTS double_data (
domain_id INT UNSIGNED NOT NULL COMMENT 'Domain.',
entity_id INT UNSIGNED NOT NULL COMMENT 'Entity.',
property_id INT UNSIGNED NOT NULL COMMENT 'Property.',
value DOUBLE NULL COMMENT 'Value.',
status Enum('OBLIGATORY', 'RECOMMENDED', 'SUGGESTED', 'FIX', 'REPLACEMENT')
NOT NULL COMMENT 'Status of this statement.',
pidx TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Index of the property.',
INDEX(domain_id,entity_id),
CONSTRAINT `dou_domain_id_entity` FOREIGN KEY (`domain_id`) REFERENCES `entities` (`id`),
CONSTRAINT `dou_entity_id_entity` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`),
CONSTRAINT `dou_property_id_entity` FOREIGN KEY (`property_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- **************************
#-- Create table datetime_data
#-- **************************
CREATE TABLE IF NOT EXISTS datetime_data (
domain_id INT UNSIGNED NOT NULL COMMENT 'Domain.',
entity_id INT UNSIGNED NOT NULL COMMENT 'Entity.',
property_id INT UNSIGNED NOT NULL COMMENT 'Property.',
value DATETIME NULL COMMENT 'Value.',
status Enum('OBLIGATORY', 'RECOMMENDED', 'SUGGESTED', 'FIX', 'REPLACEMENT')
NOT NULL COMMENT 'Status of this statement.',
pidx TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Index of the property.',
INDEX(domain_id,entity_id),
CONSTRAINT `dat_domain_id_entity` FOREIGN KEY (`domain_id`) REFERENCES `entities` (`id`),
CONSTRAINT `dat_entity_id_entity` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`),
CONSTRAINT `dat_property_id_entity` FOREIGN KEY (`property_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- **********************
#-- Create table text_data
#-- **********************
CREATE TABLE IF NOT EXISTS text_data (
domain_id INT UNSIGNED NOT NULL COMMENT 'Domain.',
entity_id INT UNSIGNED NOT NULL COMMENT 'Entity.',
property_id INT UNSIGNED NOT NULL COMMENT 'Property.',
value TEXT NULL COMMENT 'Value.',
status Enum('OBLIGATORY', 'RECOMMENDED', 'SUGGESTED', 'FIX', 'REPLACEMENT')
NOT NULL COMMENT 'Status of this statement.',
pidx TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Index of the property.',
INDEX(domain_id,entity_id),
CONSTRAINT `str_domain_id_entity` FOREIGN KEY (`domain_id`) REFERENCES `entities` (`id`),
CONSTRAINT `str_entity_id_entity` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`),
CONSTRAINT `str_property_id_entity` FOREIGN KEY (`property_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- **********************
#-- Create table data_type
#-- **********************
CREATE TABLE IF NOT EXISTS data_type (
domain_id INT UNSIGNED NOT NULL COMMENT 'Domain.',
entity_id INT UNSIGNED NOT NULL COMMENT 'Entity.',
datatype INT UNSIGNED NOT NULL COMMENT 'Datatype.',
UNIQUE INDEX(domain_id,entity_id),
CONSTRAINT `dt_domain_id_entity` FOREIGN KEY (`domain_id`) REFERENCES `entities` (`id`),
CONSTRAINT `dt_entity_id_entity` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`),
CONSTRAINT `dt_datatype_id_entity` FOREIGN KEY (`datatype`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- *******************
#-- Create table files
#-- *******************
CREATE TABLE IF NOT EXISTS files (
file_id INT UNSIGNED NOT NULL PRIMARY KEY COMMENT 'The file\'s ID.',
path VARCHAR(255) NOT NULL COMMENT 'Directory of the file.',
size BIGINT UNSIGNED NOT NULL COMMENT 'Size in kB (oktet bytes).',
hash BINARY(64) NOT NULL COMMENT 'SHA-512 Hash of the file.',
CONSTRAINT `fil_file_id_entity` FOREIGN KEY (`file_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- ******************
#-- Create table passwords
#-- ******************
CREATE TABLE IF NOT EXISTS passwords (
entity_id INT UNSIGNED NOT NULL PRIMARY KEY COMMENT 'User ID.',
password VARCHAR(255) NOT NULL COMMENT 'Password.',
CONSTRAINT `use_entity_id_entity` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- *******************
#-- Create table groups
#-- *******************
CREATE TABLE IF NOT EXISTS groups (
user_id INT UNSIGNED NOT NULL,
group_id INT UNSIGNED NOT NULL,
UNIQUE KEY(user_id, group_id)
, CONSTRAINT `user_id_entities_id` FOREIGN KEY (`user_id`) REFERENCES `entities` (`id`)
, CONSTRAINT `group_id_entities_id` FOREIGN KEY (`group_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- ********************
#-- Create table history
#-- ********************
CREATE TABLE IF NOT EXISTS transaction_log (
transaction VARCHAR(255) NOT NULL COMMENT 'Transaction.',
user_id INT UNSIGNED NOT NULL COMMENT 'User.',
date INT NOT NULL COMMENT 'Date of transaction.',
time MEDIUMINT UNSIGNED NOT NULL COMMENT 'Time of transaction.',
ns INT UNSIGNED NULL COMMENT 'Nanosecond part of transaction time.',
entity_id INT UNSIGNED NOT NULL COMMENT 'Entity ID.',
INDEX (entity_id), INDEX (date, time)
) ENGINE=InnoDB;
#-- ******************
#-- Create table rules
#-- ******************
CREATE TABLE IF NOT EXISTS rules (
domain_id INT UNSIGNED NOT NULL,
entity_id INT UNSIGNED NOT NULL,
transaction ENUM('INSERT', 'RETRIEVE', 'UPDATE', 'DELETE') NOT NULL,
criterion VARCHAR(255) NOT NULL,
#--ENUM('UNIT_PRESENT', 'ROLE_PRESENT', 'NAME_PRESENT', 'DESC_PRESENT', 'REFID_PRESENT', 'REFID_VALID', 'REFID_ISA_PAR_REFID', 'PROP_PRESENT') NOT NULL,
modus ENUM('MUST', 'SHOULD', 'SHOULDNT', 'MUSTNOT') NOT NULL,
CONSTRAINT `rule_entity_id_entity` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`),
CONSTRAINT `rule_domain_id_entity` FOREIGN KEY (`domain_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#-- magic stuff
ALTER TABLE entities AUTO_INCREMENT=100;
INSERT INTO entities (id, name, description, role, acl) VALUES (1,'DOMAIN', 'The default domain.', 'domain', 0);
UPDATE entities SET id=0 where name='domain';
INSERT INTO entities (id, name, description, role, acl) VALUES (1,'RECORDTYPE', 'The default recordtype.', 'recordtype', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (2,'RECORD', 'The default record.', 'record', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (3,'FILE', 'The default file.', 'file', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (4,'PROPERTY', 'The default property.', 'PROPERTY', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (5,'USER', 'The default user.', 'USER', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (6,'UNIT', 'The default unit.', 'UNIT', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (7,'DATATYPE', 'The default datatype.', 'DATATYPE', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (8,'GROUP', 'The default group.', 'GROUP', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (11,'REFERENCE', 'The default reference data type.', 'DATATYPE', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (12,'INTEGER', 'The default integer data type.', 'DATATYPE', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (13,'DOUBLE', 'The default double data type.', 'DATATYPE', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (14,'TEXT', 'The default text data type.', 'DATATYPE', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (15,'DATETIME', 'The default datetime data type.', 'DATATYPE', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (16,'TIMESPAN', 'The default timespan data type.', 'DATATYPE', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (17,'FILE', 'The default file reference data type.', 'DATATYPE', 0);
#--INSERT INTO data_type (domain_id, entity_id, datatype) VALUES (0, 17, 17);
#--INSERT INTO data_type (domain_id, entity_id, datatype) VALUES (0, 11, 11);
INSERT INTO entities (id, name, description, role, acl) VALUES (20,'name', 'Name of an entity', 'PROPERTY', 0);
INSERT INTO data_type (domain_id, entity_id, datatype) VALUES (0, 20, 14);
INSERT INTO entities (id, name, description, role, acl) VALUES (21,'unit', 'Unit of an entity.', 'PROPERTY', 0);
INSERT INTO data_type (domain_id, entity_id, datatype) VALUES (0, 21, 14);
INSERT INTO entities (id, name, description, role, acl) VALUES (22,'exponent', 'Unit prefix exponent of an entity.', 'PROPERTY', 0);
INSERT INTO data_type (domain_id, entity_id, datatype) VALUES (0, 22, 12);
INSERT INTO entities (id, name, description, role, acl) VALUES (24,'description', 'Description of an entity.', 'PROPERTY', 0);
INSERT INTO data_type (domain_id, entity_id, datatype) VALUES (0, 24, 14);
INSERT INTO entities (id, name, description, role, acl) VALUES (25,'refid', 'Refid of an entity.', 'PROPERTY', 0);
INSERT INTO data_type (domain_id, entity_id, datatype) VALUES (0, 25, 11);
#--INSERT INTO entities (id, name, description, role, acl) VALUES (23,'role', 'Role of an entity.', 'PROPERTY', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (50,'SQLITE', 'The SQLite file data type.', 'DATATYPE', 0);
#-- USER STUFF
INSERT INTO entities (id, name, description, role, acl) VALUES (98, 'heartdb', 'The anonymous user.', 'USER', 0);
INSERT INTO entities (id, name, description, role, acl) VALUES (99, 'administration', 'The admin users.', 'GROUP', 0);
INSERT INTO passwords (entity_id, password) VALUES (98, '37d7bd8a833261b4e4653644ee0a065f522b92b3738ca9ae2cb43a83844bf352c4a59c386a44965997a508c61988c9484c093775027425091d6d3d435c3c0e0c');
INSERT INTO passwords (entity_id, password) VALUES (99, '37d7bd8a833261b4e4653644ee0a065f522b92b3738ca9ae2cb43a83844bf352c4a59c386a44965997a508c61988c9484c093775027425091d6d3d435c3c0e0c');
makefile 0 → 100644
#
# ** 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
#
SHELL=/bin/bash
include .config
INSTALL_SQL_FILE=db_2_0.sql
ifdef LOGIN_PATH
MYSQL_CONNECTION=--login-path=$(LOGIN_PATH)
else
MYSQL_CONNECTION=--user="$(MYSQL_USER)" --password="$(MYSQL_USER_PASSWORD)"
endif
.PHONY: test-connection
test-connection:
@$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "select 0;"
.PHONY: upgrade
upgrade:
@cd patches; ./applyPatches.sh $(MYSQL_CONNECTION) --database=$(DATABASE_NAME)
.PHONY: install
install: _install _grant upgrade
.PHONY: _install
_install:
@if $(MAKE) _exists > /dev/null 2>&1; then \
printf "\n\nA database with with the name \"$(DATABASE_NAME)\" does already exist.\nCall 'make drop-$(DATABASE_NAME)' to delete that database or reconfigure with './configure'.\n"; \
exit 1; \
else sed 's/db_2_0/$(DATABASE_NAME)/g' $(INSTALL_SQL_FILE) | $(MYSQL_CMD) $(MYSQL_CONNECTION); fi
comma:=,
.PHONY: _grant
_grant:
@while true; do \
printf "\n Please enter the password for $(DATABASE_USER): "; read -s password; \
printf "\nPlease repeat the password for $(DATABASE_USER): "; read -s password2; \
if [ "$$password" != "$$password2" ]; then printf "\n\nThe passwords didn't match. Try again." ; else break ; fi; \
done ; \
printf "\n$$password\n" ; \
for host in $(subst $(comma), ,$(DATABASE_USER_HOST_LIST)); do \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "CREATE USER '$(DATABASE_USER)'@'$$host' identified by '$$password';"; \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "GRANT USAGE ON *.* TO '$(DATABASE_USER)'@'$$host';"; \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "GRANT ALL PRIVILEGES ON *.* TO '$(DATABASE_USER)'@'$$host' WITH GRANT OPTION;"; \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "GRANT EXECUTE ON *.* TO '$(DATABASE_USER)'@'$$host';"; \
done
.PHONY: drop-%
drop-%:
@for host in $(subst $(comma), ,$(DATABASE_USER_HOST_LIST)); do \
$(MYSQL_CMD) $(MYSQL_CONNECTION) -e "DROP USER '$(DATABASE_USER)'@'$$host';" || true ; \
done
@$(MYSQLADMIN_CMD) $(MYSQL_CONNECTION) -f drop $(patsubst drop-%,%,$@)
.PHONY: _exists
_exists:
@if $(MYSQL_CMD) $(MYSQL_CONNECTION) -D "$(DATABASE_NAME)" -e "show tables;" > /dev/null 2>&1 ; then \
echo "$(DATABASE_NAME) does exist." ; exit 0 ; \
else echo "$(DATABASE_NAME) does not exist." ; exit 1; fi
#!/bin/bash
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
#apply all available patches.
set -e
. ./utils/patch_header.sh
PATCHES="./patch*/patch.sh"
export UTILSPATH="./utils"
for p in $PATCHES
do
$p $MYSQL_CONNECTION --database=$DATABASE --patch=$p
done
cd ../
./update_sql_procedures.sh $MYSQL_CONNECTION --database=$DATABASE
#!/bin/bash
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
# this patch introduces the mysql stored funtion 'CaosDBVersion' with a initial value of 2.0.0
# Update mysql schema to version v2.0.0
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh
VERSIONTEST=$(mysql $MYSQL_CONNECTION -D $DATABASE -e "Select CaosDBVersion();" 2>/dev/null || echo "1")
if [[ "$VERSIONTEST" != "1" ]]; then
uptodate
fi
# install function CaosDBVersion()
mysql $MYSQL_CONNECTION -D $DATABASE -e "CREATE FUNCTION CaosDBVersion() RETURNS VARCHAR(255) DETERMINISTIC RETURN 'v2.0.0';"
# create transaction_log table with new schema
mysql $MYSQL_CONNECTION -D $DATABASE -e "CREATE TABLE new_transaction_log (
transaction VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'TRANSACTION.',
user_id INT UNSIGNED NOT NULL COMMENT 'User.',
date INT NOT NULL COMMENT 'Date of transaction.',
time MEDIUMINT UNSIGNED NOT NULL COMMENT 'Time of transaction.',
ns INT UNSIGNED NULL COMMENT 'Nanosecond part of transaction time.',
entity_id INT UNSIGNED NOT NULL COMMENT 'Entity ID.',
INDEX (entity_id), INDEX (date, time)
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;"
# copy from old transaction_log
mysql $MYSQL_CONNECTION -D $DATABASE -e "INSERT INTO new_transaction_log SELECT transaction, user_id, (Year(timestamp) * 10000 + Month(timestamp) * 100 + Day(timestamp)) as date, ((Hour(timestamp) + 1) * 10000 + (Minute(timestamp) + 1)*100 + Second(timestamp) + 1 ) as time, NULL as ns, entity_id from transaction_log";
# check if both have same number of rows
ROWSTEST=$(mysql $MYSQL_CONNECTION -D $DATABASE -e "SELECT count(*) from new_transaction_log into @newRows; SELECT count(*) from transaction_log into @oldRows; Select (@newRows = @oldRows) as test" | sed -e ':a;N;$!ba;s/[^01]//g')
if [ 0 -eq "$ROWSTEST" ]; then
failure "The rows do not match. Something went wrong."
fi
# delete old transaction_log
mysql $MYSQL_CONNECTION -D $DATABASE -e "DROP TABLE transaction_log;"
# rename new_transaction_log to transaction_log
mysql $MYSQL_CONNECTION -D $DATABASE -e "ALTER TABLE new_transaction_log RENAME TO transaction_log"
success
#!/bin/bash
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
# this patch introduces the pidx colums for the five *_data tables
# Update mysql schema from version v2.0.0 to version v2.0.1
NEW_VERSION="v2.0.1"
OLD_VERSION="v2.0.0"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
function addIdx {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e "ALTER TABLE $1 ADD COLUMN pidx TINYINT UNSIGNED NOT NULL DEFAULT 0;"
}
addIdx "reference_data"
addIdx "double_data"
addIdx "integer_data"
addIdx "datetime_data"
addIdx "text_data"
update_version $NEW_VERSION
success
#!/bin/bash
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
# this patch enhances the datetime table
# Update mysql schema from version v2.0.1 to version v2.0.2
NEW_VERSION="v2.0.2"
OLD_VERSION="v2.0.1"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
dump_table 'datetime_data'
function add_value_ns {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e "ALTER TABLE datetime_data ADD COLUMN value_ns INT UNSIGNED NULL DEFAULT NULL;"
}
function add_temp_column {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e "ALTER TABLE datetime_data ADD COLUMN value_temp INT UNSIGNED NULL DEFAULT NULL;"
}
function convert_datetime_to_secs {
leap_secs=('1972-06-30' '1972-12-31' '1973-12-31' '1974-12-31' '1975-12-31' '1976-12-31' '1977-12-31' '1978-12-31' '1979-12-31' '1981-06-30' '1982-06-30' '1983-06-30' '1985-06-30' '1987-12-31' '1989-12-31' '1990-12-31' '1992-06-30' '1993-06-30' '1994-06-30' '1995-12-31' '1997-06-30' '1998-12-31' '2005-12-31' '2008-12-31' '2012-06-30' '2015-06-30')
# for l in "${leap_secs[@]}"; do
# $CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e "INSERT INTO datetime_data (domain_id, entity_id, property_id, value, pidx, status) VALUES (0,0,0,'$l 23:59:59',0,'FIX');"
# done
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e "UPDATE datetime_data SET value_temp=UNIX_TIMESTAMP(value)-7200 WHERE value is not null;"
# add leap second correction
for l in "${leap_secs[@]}"; do
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e "UPDATE datetime_data SET value_temp=value_temp+1 WHERE value>'$l 23:59:59';"
done
}
function drop_rename {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e "ALTER TABLE datetime_data DROP COLUMN value;"
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e "ALTER TABLE datetime_data CHANGE value_temp value INT UNSIGNED NULL DEFAULT NULL;"
}
add_value_ns
add_temp_column
convert_datetime_to_secs
drop_rename
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
*
* 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
*/
CREATE TABLE IF NOT EXISTS desc_overrides (
domain_id INT UNSIGNED,
entity_id INT UNSIGNED,
description VARCHAR(255),
UNIQUE KEY (domain_id, entity_id),
CONSTRAINT `descov_d_ent_id` FOREIGN KEY (`domain_id`) REFERENCES `entities` (`id`),
CONSTRAINT `descov_e_ent_id` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
#!/bin/bash
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
# this patch adds a desc_override_table
# Update mysql schema from version v2.0.2 to version v2.0.3
NEW_VERSION="v2.0.3"
OLD_VERSION="v2.0.2"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
dump_table 'datetime_data'
function add_desc_override_table {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'CREATE TABLE IF NOT EXISTS desc_overrides (
domain_id INT UNSIGNED,
entity_id INT UNSIGNED,
description VARCHAR(255),
UNIQUE KEY (domain_id, entity_id),
CONSTRAINT `descov_d_ent_id` FOREIGN KEY (`domain_id`) REFERENCES `entities` (`id`),
CONSTRAINT `descov_e_ent_id` FOREIGN KEY (`entity_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;'
}
add_desc_override_table
update_version $NEW_VERSION
success
#!/bin/bash
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
# changes description columns from VARCHAR(255) to VARCHAR(65535)
# Update mysql schema from version v2.0.3 to version v2.0.4
NEW_VERSION="v2.0.4"
OLD_VERSION="v2.0.3"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
function modify_desc_columns {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'ALTER TABLE entities MODIFY COLUMN description VARCHAR(65535) NULL DEFAULT NULL;'
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'ALTER TABLE desc_overrides MODIFY COLUMN description VARCHAR(65535) NULL DEFAULT NULL;'
}
modify_desc_columns
update_version $NEW_VERSION
success
#!/bin/bash
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
# adds a property_id column to name_overrides and desc_overrides.
# Update mysql schema to version v2.0.5
NEW_VERSION="v2.0.5"
OLD_VERSION="v2.0.4"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
function create_new_table {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'CREATE TABLE name_overrides2 (
domain_id INT UNSIGNED,
entity_id INT UNSIGNED,
property_id INT UNSIGNED,
name VARCHAR(255),
INDEX `name_ov_dom_ent_idx` (domain_id,entity_id),
FOREIGN KEY `name_ov_forkey_dom` (`domain_id`) REFERENCES `entities` (`id`),
FOREIGN KEY `name_ov_forkey_ent` (`entity_id`) REFERENCES `entities` (`id`),
FOREIGN KEY `name_ov_forkey_pro` (`property_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
'
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'CREATE TABLE desc_overrides2 (
domain_id INT UNSIGNED,
entity_id INT UNSIGNED,
property_id INT UNSIGNED,
description VARCHAR(65535),
INDEX `desc_ov_dom_ent_idx` (domain_id,entity_id),
FOREIGN KEY `desc_ov_forkey_dom` (`domain_id`) REFERENCES `entities` (`id`),
FOREIGN KEY `desc_ov_forkey_ent` (`entity_id`) REFERENCES `entities` (`id`),
FOREIGN KEY `desc_ov_forkey_pro` (`property_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
'
}
function copy_old {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'INSERT INTO name_overrides2 (domain_id, entity_id, property_id, name) SELECT 0, domain_id, entity_id, name FROM name_overrides;'
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'INSERT INTO desc_overrides2 (domain_id, entity_id, property_id, description) SELECT 0, domain_id, entity_id, description FROM desc_overrides;'
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'UPDATE name_overrides2,reference_data SET name_overrides2.domain_id=reference_data.domain_id WHERE name_overrides2.entity_id=reference_data.entity_id and name_overrides2.property_id=reference_data.value and status="REPLACEMENT" and reference_data.domain_id!=0;'
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'UPDATE desc_overrides2,reference_data SET desc_overrides2.domain_id=reference_data.domain_id WHERE desc_overrides2.entity_id=reference_data.entity_id and desc_overrides2.property_id=reference_data.value and status="REPLACEMENT" and reference_data.domain_id!=0;'
}
function delete_rename {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'DROP TABLE name_overrides;'
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'DROP TABLE desc_overrides;'
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'ALTER TABLE name_overrides2 RENAME name_overrides;'
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'ALTER TABLE desc_overrides2 RENAME desc_overrides;'
}
function set_idx {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'ALTER TABLE name_overrides ADD UNIQUE KEY `name_ov_ukey` (domain_id,entity_id,property_id);'
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'ALTER TABLE desc_overrides ADD UNIQUE KEY `desc_ov_ukey` (domain_id,entity_id,property_id);'
}
create_new_table
copy_old
delete_rename
set_idx
update_version $NEW_VERSION
success
#!/bin/bash
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
# adds a property_id column to data_type.
# Update mysql schema to version v2.0.5
NEW_VERSION="v2.0.6"
OLD_VERSION="v2.0.5"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
function create_new_table {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'CREATE TABLE data_type2 (
domain_id INT UNSIGNED,
entity_id INT UNSIGNED,
property_id INT UNSIGNED,
datatype INT UNSIGNED,
INDEX `name_ov_dom_ent_idx` (domain_id,entity_id),
FOREIGN KEY `datatype_forkey_dom` (`domain_id`) REFERENCES `entities` (`id`),
FOREIGN KEY `datatype_forkey_ent` (`entity_id`) REFERENCES `entities` (`id`),
FOREIGN KEY `datatype_forkey_pro` (`property_id`) REFERENCES `entities` (`id`),
FOREIGN KEY `datatype_forkey_type` (`datatype`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
'
}
function copy_old {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'INSERT INTO data_type2 (domain_id, entity_id, property_id, datatype) SELECT 0, domain_id, entity_id, datatype FROM data_type;'
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'UPDATE data_type2,reference_data SET data_type2.domain_id=reference_data.domain_id WHERE data_type2.entity_id=reference_data.entity_id and data_type2.property_id=reference_data.value and status="REPLACEMENT" and reference_data.domain_id!=0;'
}
function delete_rename {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'DROP TABLE data_type;'
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'ALTER TABLE data_type2 RENAME data_type;'
}
function set_idx {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'ALTER TABLE data_type ADD UNIQUE KEY `datatype_ukey` (domain_id,entity_id,property_id);'
}
create_new_table
copy_old
delete_rename
set_idx
update_version $NEW_VERSION
success
#!/bin/bash
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
# adds a enum_data table and the boolean datatype.
# Update mysql schema to version v2.0.7
NEW_VERSION="v2.0.7"
OLD_VERSION="v2.0.6"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
function create_new_table {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'CREATE TABLE enum_data (
domain_id INT UNSIGNED,
entity_id INT UNSIGNED,
property_id INT UNSIGNED,
value VARBINARY(255),
status enum("OBLIGATORY","RECOMMENDED","SUGGESTED","FIX"),
pidx TINYINT UNSIGNED DEFAULT NULL,
INDEX `enum_ov_dom_ent_idx` (domain_id,entity_id),
FOREIGN KEY `enum_ov_forkey_dom` (`domain_id`) REFERENCES `entities` (`id`),
FOREIGN KEY `enum_ov_forkey_ent` (`entity_id`) REFERENCES `entities` (`id`),
FOREIGN KEY `enum_ov_forkey_pro` (`property_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
'
}
function add_datatype_boolean {
$CMD_MYSQL $MYSQL_CONNECTION -D $DATABASE -e 'INSERT INTO entities (id, name, description, role, acl) VALUES (18,"BOOLEAN","The defaulf boolean data type","DATATYPE",0);'
}
create_new_table
add_datatype_boolean
update_version $NEW_VERSION
success
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment