From 3923064d07c7972c92c1f7f530c41ef53b9d6ff1 Mon Sep 17 00:00:00 2001 From: Luciano Righetti Date: Fri, 7 Jan 2022 14:37:04 +0100 Subject: [PATCH] chg: migrate mysql.sql initial schema to a phinx migration --- INSTALL/INSTALL.md | 6 - INSTALL/mysql.sql | 408 ----- .../20210311000000_InitialSchema.php | 1464 +++++++++++++++++ debian/install | 1 - docker/README.md | 17 - docker/docker-compose.yml | 1 - tests/bootstrap.php | 14 +- 7 files changed, 1469 insertions(+), 442 deletions(-) delete mode 100644 INSTALL/mysql.sql create mode 100644 config/Migrations/20210311000000_InitialSchema.php diff --git a/INSTALL/INSTALL.md b/INSTALL/INSTALL.md index fc6e131..f4cef5f 100644 --- a/INSTALL/INSTALL.md +++ b/INSTALL/INSTALL.md @@ -74,12 +74,6 @@ sudo mysql -e "GRANT ALL PRIVILEGES ON cerebrate.* to cerebrate@localhost;" sudo mysql -e "FLUSH PRIVILEGES;" ``` -Load the default table structure into the database - -```bash -sudo mysql -u cerebrate -p cerebrate < /var/www/cerebrate/INSTALL/mysql.sql -``` - create your local configuration and set the db credentials ```bash diff --git a/INSTALL/mysql.sql b/INSTALL/mysql.sql deleted file mode 100644 index ed39991..0000000 --- a/INSTALL/mysql.sql +++ /dev/null @@ -1,408 +0,0 @@ --- MySQL dump 10.16 Distrib 10.1.44-MariaDB, for debian-linux-gnu (x86_64) --- --- Host: localhost Database: cerebrate --- ------------------------------------------------------ --- Server version 10.1.44-MariaDB-0ubuntu0.18.04.1 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8mb4 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `alignment_tags` --- - -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE IF NOT EXISTS `alignment_tags` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `alignment_id` int(10) unsigned NOT NULL, - `tag_id` int(10) unsigned NOT NULL, - PRIMARY KEY (`id`), - KEY `alignment_id` (`alignment_id`), - KEY `tag_id` (`tag_id`), - CONSTRAINT `alignment_tags_ibfk_1` FOREIGN KEY (`alignment_id`) REFERENCES `alignments` (`id`), - CONSTRAINT `alignment_tags_ibfk_10` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`), - CONSTRAINT `alignment_tags_ibfk_11` FOREIGN KEY (`alignment_id`) REFERENCES `alignments` (`id`), - CONSTRAINT `alignment_tags_ibfk_12` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`), - CONSTRAINT `alignment_tags_ibfk_2` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`), - CONSTRAINT `alignment_tags_ibfk_3` FOREIGN KEY (`alignment_id`) REFERENCES `alignments` (`id`), - CONSTRAINT `alignment_tags_ibfk_4` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`), - CONSTRAINT `alignment_tags_ibfk_5` FOREIGN KEY (`alignment_id`) REFERENCES `alignments` (`id`), - CONSTRAINT `alignment_tags_ibfk_6` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`), - CONSTRAINT `alignment_tags_ibfk_7` FOREIGN KEY (`alignment_id`) REFERENCES `alignments` (`id`), - CONSTRAINT `alignment_tags_ibfk_8` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`), - CONSTRAINT `alignment_tags_ibfk_9` FOREIGN KEY (`alignment_id`) REFERENCES `alignments` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `alignments` --- - -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE IF NOT EXISTS `alignments` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `individual_id` int(10) unsigned NOT NULL, - `organisation_id` int(10) unsigned NOT NULL, - `type` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT 'member', - PRIMARY KEY (`id`), - KEY `individual_id` (`individual_id`), - KEY `organisation_id` (`organisation_id`), - CONSTRAINT `alignments_ibfk_1` FOREIGN KEY (`individual_id`) REFERENCES `individuals` (`id`), - CONSTRAINT `alignments_ibfk_2` FOREIGN KEY (`organisation_id`) REFERENCES `organisations` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `auth_keys` --- - -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE IF NOT EXISTS `auth_keys` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `uuid` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL, - `authkey` varchar(72) CHARACTER SET ascii DEFAULT NULL, - `authkey_start` varchar(4) CHARACTER SET ascii DEFAULT NULL, - `authkey_end` varchar(4) CHARACTER SET ascii DEFAULT NULL, - `created` int(10) unsigned NOT NULL, - `expiration` int(10) unsigned NOT NULL, - `user_id` int(10) unsigned NOT NULL, - `comment` text COLLATE utf8mb4_unicode_ci, - PRIMARY KEY (`id`), - KEY `authkey_start` (`authkey_start`), - KEY `authkey_end` (`authkey_end`), - KEY `created` (`created`), - KEY `expiration` (`expiration`), - KEY `user_id` (`user_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `broods` --- - -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE IF NOT EXISTS `broods` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `uuid` varchar(40) CHARACTER SET ascii DEFAULT NULL, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `url` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `description` text COLLATE utf8mb4_unicode_ci, - `organisation_id` int(10) unsigned NOT NULL, - `trusted` tinyint(1) DEFAULT NULL, - `pull` tinyint(1) DEFAULT NULL, - `skip_proxy` tinyint(1) DEFAULT NULL, - `authkey` varchar(40) CHARACTER SET ascii DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `uuid` (`uuid`), - KEY `name` (`name`), - KEY `url` (`url`), - KEY `authkey` (`authkey`), - KEY `organisation_id` (`organisation_id`), - FOREIGN KEY (`organisation_id`) REFERENCES `organisations` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `encryption_keys` --- - -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE IF NOT EXISTS `encryption_keys` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `uuid` varchar(40) CHARACTER SET ascii DEFAULT NULL, - `type` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `encryption_key` text COLLATE utf8mb4_unicode_ci, - `revoked` tinyint(1) DEFAULT NULL, - `expires` int(10) unsigned DEFAULT NULL, - `owner_id` int(10) unsigned DEFAULT NULL, - `owner_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - KEY `uuid` (`uuid`), - KEY `type` (`type`), - KEY `expires` (`expires`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `individual_encryption_keys` --- - -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE IF NOT EXISTS `individual_encryption_keys` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `individual_id` int(10) unsigned NOT NULL, - `encryption_key_id` int(10) unsigned NOT NULL, - PRIMARY KEY (`id`), - KEY `individual_id` (`individual_id`), - KEY `encryption_key_id` (`encryption_key_id`), - CONSTRAINT `individual_encryption_keys_ibfk_1` FOREIGN KEY (`individual_id`) REFERENCES `individuals` (`id`), - CONSTRAINT `individual_encryption_keys_ibfk_2` FOREIGN KEY (`encryption_key_id`) REFERENCES `encryption_keys` (`id`), - CONSTRAINT `individual_encryption_keys_ibfk_3` FOREIGN KEY (`individual_id`) REFERENCES `individuals` (`id`), - CONSTRAINT `individual_encryption_keys_ibfk_4` FOREIGN KEY (`encryption_key_id`) REFERENCES `encryption_keys` (`id`), - CONSTRAINT `individual_encryption_keys_ibfk_5` FOREIGN KEY (`individual_id`) REFERENCES `individuals` (`id`), - CONSTRAINT `individual_encryption_keys_ibfk_6` FOREIGN KEY (`encryption_key_id`) REFERENCES `encryption_keys` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `individuals` --- - -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE IF NOT EXISTS `individuals` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `uuid` varchar(40) CHARACTER SET ascii DEFAULT NULL, - `email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `first_name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `last_name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `position` text COLLATE utf8mb4_unicode_ci, - PRIMARY KEY (`id`), - KEY `uuid` (`uuid`), - KEY `email` (`email`), - KEY `first_name` (`first_name`), - KEY `last_name` (`last_name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `local_tools` --- - -CREATE TABLE IF NOT EXISTS `local_tools` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `connector` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `settings` text COLLATE utf8mb4_unicode_ci, - `exposed` tinyint(1) NOT NULL, - `description` text COLLATE utf8mb4_unicode_ci, - PRIMARY KEY (`id`), - KEY `name` (`name`), - KEY `connector` (`connector`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - --- --- Table structure for table `organisation_encryption_keys` --- - -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE IF NOT EXISTS `organisation_encryption_keys` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `organisation_id` int(10) unsigned NOT NULL, - `encryption_key_id` int(10) unsigned NOT NULL, - PRIMARY KEY (`id`), - KEY `organisation_id` (`organisation_id`), - KEY `encryption_key_id` (`encryption_key_id`), - CONSTRAINT `organisation_encryption_keys_ibfk_1` FOREIGN KEY (`organisation_id`) REFERENCES `organisations` (`id`), - CONSTRAINT `organisation_encryption_keys_ibfk_2` FOREIGN KEY (`encryption_key_id`) REFERENCES `encryption_keys` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `organisations` --- - -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE IF NOT EXISTS `organisations` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `uuid` varchar(40) CHARACTER SET ascii DEFAULT NULL, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `url` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `nationality` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `sector` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `type` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `contacts` text COLLATE utf8mb4_unicode_ci, - PRIMARY KEY (`id`), - KEY `uuid` (`uuid`), - KEY `name` (`name`), - KEY `url` (`url`), - KEY `nationality` (`nationality`), - KEY `sector` (`sector`), - KEY `type` (`type`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `roles` --- - -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE IF NOT EXISTS `roles` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `uuid` varchar(40) CHARACTER SET ascii DEFAULT NULL, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `is_default` tinyint(1) DEFAULT NULL, - `perm_admin` tinyint(1) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `name` (`name`), - KEY `uuid` (`uuid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `tags` --- - -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE IF NOT EXISTS `tags` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `description` text COLLATE utf8mb4_unicode_ci, - `colour` varchar(6) CHARACTER SET ascii NOT NULL, - PRIMARY KEY (`id`), - KEY `name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `users` --- - -CREATE TABLE IF NOT EXISTS `users` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `uuid` varchar(40) CHARACTER SET ascii DEFAULT NULL, - `username` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `password` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `role_id` int(11) unsigned NOT NULL, - `individual_id` int(11) unsigned NOT NULL, - `disabled` tinyint(1) DEFAULT '0', - PRIMARY KEY (`id`), - KEY `uuid` (`uuid`), - KEY `role_id` (`role_id`), - KEY `individual_id` (`individual_id`), - CONSTRAINT `users_ibfk_1` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`), - CONSTRAINT `users_ibfk_2` FOREIGN KEY (`individual_id`) REFERENCES `individuals` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -CREATE TABLE IF NOT EXISTS `sharing_groups` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `uuid` varchar(40) CHARACTER SET ascii DEFAULT NULL, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `releasability` text DEFAULT NULL, - `description` text DEFAULT NULL, - `organisation_id` int(10) unsigned NOT NULL, - `user_id` int(10) unsigned NOT NULL, - `active` tinyint(1) DEFAULT '1', - `local` tinyint(1) DEFAULT '1', - PRIMARY KEY (`id`), - KEY `uuid` (`uuid`), - KEY `user_id` (`user_id`), - KEY `organisation_id` (`organisation_id`), - KEY `name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -CREATE TABLE IF NOT EXISTS `sgo` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `sharing_group_id` int(10) unsigned NOT NULL, - `organisation_id` int(10) unsigned NOT NULL, - `deleted` tinyint(1) DEFAULT 0, - PRIMARY KEY (`id`), - KEY `sharing_group_id` (`sharing_group_id`), - KEY `organisation_id` (`organisation_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -CREATE TABLE IF NOT EXISTS `meta_fields` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `scope` varchar(191) NOT NULL, - `parent_id` int(10) unsigned NOT NULL, - `field` varchar(191) NOT NULL, - `value` varchar(191) NOT NULL, - `uuid` varchar(40) CHARACTER SET ascii DEFAULT NULL, - `meta_template_id` int(10) unsigned NOT NULL, - `meta_template_field_id` int(10) unsigned NOT NULL, - `is_default` tinyint(1) NOT NULL DEFAULT 0, - PRIMARY KEY (`id`), - KEY `scope` (`scope`), - KEY `uuid` (`uuid`), - KEY `parent_id` (`parent_id`), - KEY `field` (`field`), - KEY `value` (`value`), - KEY `meta_template_id` (`meta_template_id`), - KEY `meta_template_field_id` (`meta_template_field_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -CREATE TABLE IF NOT EXISTS `meta_templates` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `scope` varchar(191) NOT NULL, - `name` varchar(191) NOT NULL, - `namespace` varchar(191) NOT NULL, - `description` text, - `version` varchar(191) NOT NULL, - `uuid` varchar(40) CHARACTER SET ascii, - `source` varchar(191), - `enabled` tinyint(1) DEFAULT 0, - `is_default` tinyint(1) NOT NULL DEFAULT 0, - PRIMARY KEY (`id`), - KEY `scope` (`scope`), - KEY `source` (`source`), - KEY `name` (`name`), - KEY `namespace` (`namespace`), - KEY `version` (`version`), - KEY `uuid` (`uuid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -CREATE TABLE IF NOT EXISTS `meta_template_fields` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `field` varchar(191) NOT NULL, - `type` varchar(191) NOT NULL, - `meta_template_id` int(10) unsigned NOT NULL, - `regex` text, - `multiple` tinyint(1) DEFAULT 0, - `enabled` tinyint(1) DEFAULT 0, - PRIMARY KEY (`id`), - CONSTRAINT `meta_template_id` FOREIGN KEY (`meta_template_id`) REFERENCES `meta_templates` (`id`), - KEY `field` (`field`), - KEY `type` (`type`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -CREATE TABLE IF NOT EXISTS `audit_logs` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created` datetime NOT NULL, - `user_id` int(10) unsigned DEFAULT NULL, - `authkey_id` int(10) unsigned DEFAULT NULL, - `request_ip` varbinary(16) DEFAULT NULL, - `request_type` tinyint NOT NULL, - `request_id` varchar(191) DEFAULT NULL, - `request_action` varchar(20) NOT NULL, - `model` varchar(80) NOT NULL, - `model_id` int(10) unsigned DEFAULT NULL, - `model_title` text DEFAULT NULL, - `change` blob, - PRIMARY KEY (`id`), - KEY `user_id` (`user_id`), - KEY `request_ip` (`request_ip`), - KEY `model` (`model`), - KEY `request_action` (`request_action`), - KEY `model_id` (`model_id`), - KEY `created` (`created`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2020-06-22 14:30:02 diff --git a/config/Migrations/20210311000000_InitialSchema.php b/config/Migrations/20210311000000_InitialSchema.php new file mode 100644 index 0000000..d1e2ed1 --- /dev/null +++ b/config/Migrations/20210311000000_InitialSchema.php @@ -0,0 +1,1464 @@ +execute('SET unique_checks=0; SET foreign_key_checks=0;'); + $this->execute("ALTER DATABASE CHARACTER SET 'utf8mb4';"); + $this->execute("ALTER DATABASE COLLATE='utf8mb4_general_ci';"); + $this->table('broods', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('uuid', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 40, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'id', + ]) + ->addColumn('name', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'uuid', + ]) + ->addColumn('url', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'name', + ]) + ->addColumn('description', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'url', + ]) + ->addColumn('organisation_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'description', + ]) + ->addColumn('trusted', 'boolean', [ + 'null' => true, + 'default' => null, + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'organisation_id', + ]) + ->addColumn('pull', 'boolean', [ + 'null' => true, + 'default' => null, + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'trusted', + ]) + ->addColumn('skip_proxy', 'boolean', [ + 'null' => true, + 'default' => null, + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'pull', + ]) + ->addColumn('authkey', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 40, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'skip_proxy', + ]) + ->addIndex(['uuid'], [ + 'name' => 'uuid', + 'unique' => false, + ]) + ->addIndex(['name'], [ + 'name' => 'name', + 'unique' => false, + ]) + ->addIndex(['url'], [ + 'name' => 'url', + 'unique' => false, + ]) + ->addIndex(['authkey'], [ + 'name' => 'authkey', + 'unique' => false, + ]) + ->addIndex(['organisation_id'], [ + 'name' => 'organisation_id', + 'unique' => false, + ]) + ->addForeignKey('organisation_id', 'organisations', 'id', [ + 'constraint' => 'broods_ibfk_1', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->create(); + $this->table('sharing_groups', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('uuid', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 40, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'id', + ]) + ->addColumn('name', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'uuid', + ]) + ->addColumn('releasability', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'name', + ]) + ->addColumn('description', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'releasability', + ]) + ->addColumn('organisation_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'description', + ]) + ->addColumn('user_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'organisation_id', + ]) + ->addColumn('active', 'boolean', [ + 'null' => true, + 'default' => '1', + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'user_id', + ]) + ->addColumn('local', 'boolean', [ + 'null' => true, + 'default' => '1', + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'active', + ]) + ->addIndex(['uuid'], [ + 'name' => 'uuid', + 'unique' => false, + ]) + ->addIndex(['user_id'], [ + 'name' => 'user_id', + 'unique' => false, + ]) + ->addIndex(['organisation_id'], [ + 'name' => 'organisation_id', + 'unique' => false, + ]) + ->addIndex(['name'], [ + 'name' => 'name', + 'unique' => false, + ]) + ->create(); + $this->table('alignment_tags', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('alignment_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'id', + ]) + ->addColumn('tag_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'alignment_id', + ]) + ->addIndex(['alignment_id'], [ + 'name' => 'alignment_id', + 'unique' => false, + ]) + ->addIndex(['tag_id'], [ + 'name' => 'tag_id', + 'unique' => false, + ]) + ->addForeignKey('alignment_id', 'alignments', 'id', [ + 'constraint' => 'alignment_tags_ibfk_1', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('tag_id', 'tags', 'id', [ + 'constraint' => 'alignment_tags_ibfk_10', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('alignment_id', 'alignments', 'id', [ + 'constraint' => 'alignment_tags_ibfk_11', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('tag_id', 'tags', 'id', [ + 'constraint' => 'alignment_tags_ibfk_12', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('tag_id', 'tags', 'id', [ + 'constraint' => 'alignment_tags_ibfk_2', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('alignment_id', 'alignments', 'id', [ + 'constraint' => 'alignment_tags_ibfk_3', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('tag_id', 'tags', 'id', [ + 'constraint' => 'alignment_tags_ibfk_4', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('alignment_id', 'alignments', 'id', [ + 'constraint' => 'alignment_tags_ibfk_5', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('tag_id', 'tags', 'id', [ + 'constraint' => 'alignment_tags_ibfk_6', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('alignment_id', 'alignments', 'id', [ + 'constraint' => 'alignment_tags_ibfk_7', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('tag_id', 'tags', 'id', [ + 'constraint' => 'alignment_tags_ibfk_8', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('alignment_id', 'alignments', 'id', [ + 'constraint' => 'alignment_tags_ibfk_9', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->create(); + $this->table('meta_templates', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('scope', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'id', + ]) + ->addColumn('name', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'scope', + ]) + ->addColumn('namespace', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'name', + ]) + ->addColumn('description', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'namespace', + ]) + ->addColumn('version', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'description', + ]) + ->addColumn('uuid', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 40, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'version', + ]) + ->addColumn('source', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'uuid', + ]) + ->addColumn('enabled', 'boolean', [ + 'null' => true, + 'default' => '0', + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'source', + ]) + ->addColumn('is_default', 'boolean', [ + 'null' => false, + 'default' => '0', + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'enabled', + ]) + ->addIndex(['scope'], [ + 'name' => 'scope', + 'unique' => false, + ]) + ->addIndex(['source'], [ + 'name' => 'source', + 'unique' => false, + ]) + ->addIndex(['name'], [ + 'name' => 'name', + 'unique' => false, + ]) + ->addIndex(['namespace'], [ + 'name' => 'namespace', + 'unique' => false, + ]) + ->addIndex(['version'], [ + 'name' => 'version', + 'unique' => false, + ]) + ->addIndex(['uuid'], [ + 'name' => 'uuid', + 'unique' => false, + ]) + ->create(); + $this->table('individuals', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('uuid', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 40, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'id', + ]) + ->addColumn('email', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'uuid', + ]) + ->addColumn('first_name', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'email', + ]) + ->addColumn('last_name', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'first_name', + ]) + ->addColumn('position', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'last_name', + ]) + ->addIndex(['uuid'], [ + 'name' => 'uuid', + 'unique' => false, + ]) + ->addIndex(['email'], [ + 'name' => 'email', + 'unique' => false, + ]) + ->addIndex(['first_name'], [ + 'name' => 'first_name', + 'unique' => false, + ]) + ->addIndex(['last_name'], [ + 'name' => 'last_name', + 'unique' => false, + ]) + ->create(); + $this->table('organisations', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('uuid', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 40, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'id', + ]) + ->addColumn('name', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'uuid', + ]) + ->addColumn('url', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'name', + ]) + ->addColumn('nationality', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'url', + ]) + ->addColumn('sector', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'nationality', + ]) + ->addColumn('type', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'sector', + ]) + ->addColumn('contacts', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'type', + ]) + ->addIndex(['uuid'], [ + 'name' => 'uuid', + 'unique' => false, + ]) + ->addIndex(['name'], [ + 'name' => 'name', + 'unique' => false, + ]) + ->addIndex(['url'], [ + 'name' => 'url', + 'unique' => false, + ]) + ->addIndex(['nationality'], [ + 'name' => 'nationality', + 'unique' => false, + ]) + ->addIndex(['sector'], [ + 'name' => 'sector', + 'unique' => false, + ]) + ->addIndex(['type'], [ + 'name' => 'type', + 'unique' => false, + ]) + ->create(); + $this->table('encryption_keys', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('uuid', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 40, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'id', + ]) + ->addColumn('type', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'uuid', + ]) + ->addColumn('encryption_key', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'type', + ]) + ->addColumn('revoked', 'boolean', [ + 'null' => true, + 'default' => null, + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'encryption_key', + ]) + ->addColumn('expires', 'integer', [ + 'null' => true, + 'default' => null, + 'limit' => '10', + 'signed' => false, + 'after' => 'revoked', + ]) + ->addColumn('owner_id', 'integer', [ + 'null' => true, + 'default' => null, + 'limit' => '10', + 'signed' => false, + 'after' => 'expires', + ]) + ->addColumn('owner_type', 'string', [ + 'null' => false, + 'limit' => 20, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'owner_id', + ]) + ->addIndex(['uuid'], [ + 'name' => 'uuid', + 'unique' => false, + ]) + ->addIndex(['type'], [ + 'name' => 'type', + 'unique' => false, + ]) + ->addIndex(['expires'], [ + 'name' => 'expires', + 'unique' => false, + ]) + ->create(); + $this->table('meta_fields', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('scope', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'id', + ]) + ->addColumn('parent_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'scope', + ]) + ->addColumn('field', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'parent_id', + ]) + ->addColumn('value', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'field', + ]) + ->addColumn('uuid', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 40, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'value', + ]) + ->addColumn('meta_template_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'uuid', + ]) + ->addColumn('meta_template_field_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'meta_template_id', + ]) + ->addColumn('is_default', 'boolean', [ + 'null' => false, + 'default' => '0', + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'meta_template_field_id', + ]) + ->addIndex(['scope'], [ + 'name' => 'scope', + 'unique' => false, + ]) + ->addIndex(['uuid'], [ + 'name' => 'uuid', + 'unique' => false, + ]) + ->addIndex(['parent_id'], [ + 'name' => 'parent_id', + 'unique' => false, + ]) + ->addIndex(['field'], [ + 'name' => 'field', + 'unique' => false, + ]) + ->addIndex(['value'], [ + 'name' => 'value', + 'unique' => false, + ]) + ->addIndex(['meta_template_id'], [ + 'name' => 'meta_template_id', + 'unique' => false, + ]) + ->addIndex(['meta_template_field_id'], [ + 'name' => 'meta_template_field_id', + 'unique' => false, + ]) + ->create(); + $this->table('audit_logs', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('created', 'datetime', [ + 'null' => false, + 'after' => 'id', + ]) + ->addColumn('user_id', 'integer', [ + 'null' => true, + 'default' => null, + 'limit' => '10', + 'signed' => false, + 'after' => 'created', + ]) + ->addColumn('authkey_id', 'integer', [ + 'null' => true, + 'default' => null, + 'limit' => '10', + 'signed' => false, + 'after' => 'user_id', + ]) + ->addColumn('request_ip', 'varbinary', [ + 'null' => true, + 'default' => null, + 'limit' => 16, + 'after' => 'authkey_id', + ]) + ->addColumn('request_type', 'integer', [ + 'null' => false, + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'request_ip', + ]) + ->addColumn('request_id', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'request_type', + ]) + ->addColumn('request_action', 'string', [ + 'null' => false, + 'limit' => 20, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'request_id', + ]) + ->addColumn('model', 'string', [ + 'null' => false, + 'limit' => 80, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'request_action', + ]) + ->addColumn('model_id', 'integer', [ + 'null' => true, + 'default' => null, + 'limit' => '10', + 'signed' => false, + 'after' => 'model', + ]) + ->addColumn('model_title', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'model_id', + ]) + ->addColumn('change', 'blob', [ + 'null' => true, + 'default' => null, + 'limit' => MysqlAdapter::BLOB_REGULAR, + 'after' => 'model_title', + ]) + ->addIndex(['user_id'], [ + 'name' => 'user_id', + 'unique' => false, + ]) + ->addIndex(['request_ip'], [ + 'name' => 'request_ip', + 'unique' => false, + ]) + ->addIndex(['model'], [ + 'name' => 'model', + 'unique' => false, + ]) + ->addIndex(['request_action'], [ + 'name' => 'request_action', + 'unique' => false, + ]) + ->addIndex(['model_id'], [ + 'name' => 'model_id', + 'unique' => false, + ]) + ->addIndex(['created'], [ + 'name' => 'created', + 'unique' => false, + ]) + ->create(); + $this->table('organisation_encryption_keys', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('organisation_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'id', + ]) + ->addColumn('encryption_key_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'organisation_id', + ]) + ->addIndex(['organisation_id'], [ + 'name' => 'organisation_id', + 'unique' => false, + ]) + ->addIndex(['encryption_key_id'], [ + 'name' => 'encryption_key_id', + 'unique' => false, + ]) + ->addForeignKey('organisation_id', 'organisations', 'id', [ + 'constraint' => 'organisation_encryption_keys_ibfk_1', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('encryption_key_id', 'encryption_keys', 'id', [ + 'constraint' => 'organisation_encryption_keys_ibfk_2', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->create(); + $this->table('users', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('uuid', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 40, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'id', + ]) + ->addColumn('username', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'uuid', + ]) + ->addColumn('password', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'username', + ]) + ->addColumn('role_id', 'integer', [ + 'null' => false, + 'limit' => MysqlAdapter::INT_REGULAR, + 'signed' => false, + 'after' => 'password', + ]) + ->addColumn('individual_id', 'integer', [ + 'null' => false, + 'limit' => MysqlAdapter::INT_REGULAR, + 'signed' => false, + 'after' => 'role_id', + ]) + ->addColumn('disabled', 'boolean', [ + 'null' => true, + 'default' => '0', + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'individual_id', + ]) + ->addIndex(['uuid'], [ + 'name' => 'uuid', + 'unique' => false, + ]) + ->addIndex(['role_id'], [ + 'name' => 'role_id', + 'unique' => false, + ]) + ->addIndex(['individual_id'], [ + 'name' => 'individual_id', + 'unique' => false, + ]) + ->addForeignKey('role_id', 'roles', 'id', [ + 'constraint' => 'users_ibfk_1', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('individual_id', 'individuals', 'id', [ + 'constraint' => 'users_ibfk_2', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->create(); + $this->table('roles', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('uuid', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 40, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'id', + ]) + ->addColumn('name', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'uuid', + ]) + ->addColumn('is_default', 'boolean', [ + 'null' => true, + 'default' => null, + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'name', + ]) + ->addColumn('perm_admin', 'boolean', [ + 'null' => true, + 'default' => null, + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'is_default', + ]) + ->addIndex(['name'], [ + 'name' => 'name', + 'unique' => false, + ]) + ->addIndex(['uuid'], [ + 'name' => 'uuid', + 'unique' => false, + ]) + ->create(); + $this->table('tags', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('name', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'id', + ]) + ->addColumn('description', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'name', + ]) + ->addColumn('colour', 'string', [ + 'null' => false, + 'limit' => 6, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'description', + ]) + ->addIndex(['name'], [ + 'name' => 'name', + 'unique' => false, + ]) + ->create(); + $this->table('individual_encryption_keys', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('individual_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'id', + ]) + ->addColumn('encryption_key_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'individual_id', + ]) + ->addIndex(['individual_id'], [ + 'name' => 'individual_id', + 'unique' => false, + ]) + ->addIndex(['encryption_key_id'], [ + 'name' => 'encryption_key_id', + 'unique' => false, + ]) + ->addForeignKey('individual_id', 'individuals', 'id', [ + 'constraint' => 'individual_encryption_keys_ibfk_1', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('encryption_key_id', 'encryption_keys', 'id', [ + 'constraint' => 'individual_encryption_keys_ibfk_2', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('individual_id', 'individuals', 'id', [ + 'constraint' => 'individual_encryption_keys_ibfk_3', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('encryption_key_id', 'encryption_keys', 'id', [ + 'constraint' => 'individual_encryption_keys_ibfk_4', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('individual_id', 'individuals', 'id', [ + 'constraint' => 'individual_encryption_keys_ibfk_5', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('encryption_key_id', 'encryption_keys', 'id', [ + 'constraint' => 'individual_encryption_keys_ibfk_6', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->create(); + $this->table('meta_template_fields', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('field', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'id', + ]) + ->addColumn('type', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'field', + ]) + ->addColumn('meta_template_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'type', + ]) + ->addColumn('regex', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'meta_template_id', + ]) + ->addColumn('multiple', 'boolean', [ + 'null' => true, + 'default' => '0', + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'regex', + ]) + ->addColumn('enabled', 'boolean', [ + 'null' => true, + 'default' => '0', + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'multiple', + ]) + ->addIndex(['meta_template_id'], [ + 'name' => 'meta_template_id', + 'unique' => false, + ]) + ->addIndex(['field'], [ + 'name' => 'field', + 'unique' => false, + ]) + ->addIndex(['type'], [ + 'name' => 'type', + 'unique' => false, + ]) + ->addForeignKey('meta_template_id', 'meta_templates', 'id', [ + 'constraint' => 'meta_template_id', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->create(); + $this->table('auth_keys', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('uuid', 'string', [ + 'null' => false, + 'limit' => 40, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'id', + ]) + ->addColumn('authkey', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 72, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'uuid', + ]) + ->addColumn('authkey_start', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 4, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'authkey', + ]) + ->addColumn('authkey_end', 'string', [ + 'null' => true, + 'default' => null, + 'limit' => 4, + 'collation' => 'ascii_general_ci', + 'encoding' => 'ascii', + 'after' => 'authkey_start', + ]) + ->addColumn('created', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'authkey_end', + ]) + ->addColumn('expiration', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'created', + ]) + ->addColumn('user_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'expiration', + ]) + ->addColumn('comment', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'user_id', + ]) + ->addIndex(['authkey_start'], [ + 'name' => 'authkey_start', + 'unique' => false, + ]) + ->addIndex(['authkey_end'], [ + 'name' => 'authkey_end', + 'unique' => false, + ]) + ->addIndex(['created'], [ + 'name' => 'created', + 'unique' => false, + ]) + ->addIndex(['expiration'], [ + 'name' => 'expiration', + 'unique' => false, + ]) + ->addIndex(['user_id'], [ + 'name' => 'user_id', + 'unique' => false, + ]) + ->create(); + $this->table('local_tools', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('name', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'id', + ]) + ->addColumn('connector', 'string', [ + 'null' => false, + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'name', + ]) + ->addColumn('settings', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'connector', + ]) + ->addColumn('exposed', 'boolean', [ + 'null' => false, + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'settings', + ]) + ->addColumn('description', 'text', [ + 'null' => true, + 'default' => null, + 'limit' => 65535, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'exposed', + ]) + ->addIndex(['name'], [ + 'name' => 'name', + 'unique' => false, + ]) + ->addIndex(['connector'], [ + 'name' => 'connector', + 'unique' => false, + ]) + ->create(); + $this->table('alignments', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('individual_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'id', + ]) + ->addColumn('organisation_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'individual_id', + ]) + ->addColumn('type', 'string', [ + 'null' => true, + 'default' => 'member', + 'limit' => 191, + 'collation' => 'utf8mb4_unicode_ci', + 'encoding' => 'utf8mb4', + 'after' => 'organisation_id', + ]) + ->addIndex(['individual_id'], [ + 'name' => 'individual_id', + 'unique' => false, + ]) + ->addIndex(['organisation_id'], [ + 'name' => 'organisation_id', + 'unique' => false, + ]) + ->addForeignKey('individual_id', 'individuals', 'id', [ + 'constraint' => 'alignments_ibfk_1', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->addForeignKey('organisation_id', 'organisations', 'id', [ + 'constraint' => 'alignments_ibfk_2', + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT', + ]) + ->create(); + $this->table('sgo', [ + 'id' => false, + 'primary_key' => ['id'], + 'engine' => 'InnoDB', + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'comment' => '', + 'row_format' => 'DYNAMIC', + ]) + ->addColumn('id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'identity' => 'enable', + ]) + ->addColumn('sharing_group_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'id', + ]) + ->addColumn('organisation_id', 'integer', [ + 'null' => false, + 'limit' => '10', + 'signed' => false, + 'after' => 'sharing_group_id', + ]) + ->addColumn('deleted', 'boolean', [ + 'null' => true, + 'default' => '0', + 'limit' => MysqlAdapter::INT_TINY, + 'after' => 'organisation_id', + ]) + ->addIndex(['sharing_group_id'], [ + 'name' => 'sharing_group_id', + 'unique' => false, + ]) + ->addIndex(['organisation_id'], [ + 'name' => 'organisation_id', + 'unique' => false, + ]) + ->create(); + $this->execute('SET unique_checks=1; SET foreign_key_checks=1;'); + } +} diff --git a/debian/install b/debian/install index 2ee55e9..12d7cc8 100755 --- a/debian/install +++ b/debian/install @@ -7,4 +7,3 @@ webroot /usr/share/php-cerebrate config /usr/share/php-cerebrate debian/cerebrate.local.conf /etc/apache2/sites-available/ debian/config.php /etc/cerebrate/ -INSTALL/mysql.sql => /usr/share/dbconfig-common/data/php-cerebrate/install/mysql diff --git a/docker/README.md b/docker/README.md index 1074c0c..9bf0154 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,20 +1,3 @@ -# Database init - -For the `docker-compose` setup to work you must initialize database with -what is in `../INSTALL/mysql.sql` - -``` -mkdir -p run/dbinit/ -cp ../INSTALL/mysql.sql run/dbinit/ -``` - -The MariaDB container has a volume mounted as follow -`- ./run/dbinit:/docker-entrypoint-initdb.d/:ro` - -So that on startup the container will source files in this directory to seed -the database. Once it's done the container will run normally and Cerebrate will -be able to roll its database migration scripts - # Actual data and volumes The actual database will be located in `./run/database` exposed with the diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 6aa0b73..821ab5f 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -5,7 +5,6 @@ services: restart: always volumes: - ./run/database:/var/lib/mysql - - ./run/dbinit:/docker-entrypoint-initdb.d/:ro environment: MARIADB_RANDOM_ROOT_PASSWORD: "yes" MYSQL_DATABASE: "cerebrate" diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9283095..6df9c27 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -54,18 +54,14 @@ ConnectionManager::alias('test_debug_kit', 'debug_kit'); // has been written to. session_id('cli'); -// Load db schema from mysql.sql and run migrations -// super hacky way to skip migrations +// hacky way to skip migrations if (!in_array('skip-migrations', $_SERVER['argv'])) { - // TODO: Removing mysql.sql and relying only in migrations would be ideal - // in the meantime, `'skip' => ['*']`, prevents migrations from droping already created tables - (new SchemaLoader())->loadSqlFiles('./INSTALL/mysql.sql', 'test'); $migrator = new Migrator(); $migrator->runMany([ - ['connection' => 'test', 'skip' => ['*']], - ['plugin' => 'Tags', 'connection' => 'test', 'skip' => ['*']], - ['plugin' => 'ADmad/SocialAuth', 'connection' => 'test', 'skip' => ['*']] + ['connection' => 'test'], + ['plugin' => 'Tags', 'connection' => 'test'], + ['plugin' => 'ADmad/SocialAuth', 'connection' => 'test'] ]); -}else{ +} else { echo "[ * ] Skipping migrations ...\n"; }