From b3949f5d8b9512a4609f0540e4c8d4d3233d1a45 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 22 Dec 2018 23:19:20 +0100 Subject: [PATCH] Move schema to json --- Admin/Install/db.json | 46 ++++++++++++++++++++++++++++++++++++++++ Admin/Installer.php | 49 ------------------------------------------- 2 files changed, 46 insertions(+), 49 deletions(-) create mode 100644 Admin/Install/db.json diff --git a/Admin/Install/db.json b/Admin/Install/db.json new file mode 100644 index 0000000..990232f --- /dev/null +++ b/Admin/Install/db.json @@ -0,0 +1,46 @@ +{ + "editor_doc": { + "name": "editor_doc", + "fields": { + "editor_doc_id": { + "name": "editor_doc_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "editor_doc_title": { + "name": "editor_doc_title", + "type": "VARCHAR(255)", + "null": false + }, + "editor_doc_plain": { + "name": "editor_doc_plain", + "type": "TEXT", + "null": false + }, + "editor_doc_content": { + "name": "editor_doc_content", + "type": "TEXT", + "null": false + }, + "editor_doc_path": { + "name": "editor_doc_path", + "type": "VARCHAR(255)", + "null": false + }, + "editor_doc_created_by": { + "name": "editor_doc_created_by", + "type": "INT", + "null": false, + "foreignTable": "account", + "foreignKey": "account_id" + }, + "editor_doc_created_at": { + "name": "editor_doc_created_at", + "type": "DATETIME", + "null": false + } + } + } +} \ No newline at end of file diff --git a/Admin/Installer.php b/Admin/Installer.php index 5ccbc16..537dac0 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -14,9 +14,6 @@ declare(strict_types=1); namespace Modules\Editor\Admin; -use phpOMS\DataStorage\Database\DatabasePool; -use phpOMS\DataStorage\Database\DatabaseType; -use phpOMS\Module\InfoManager; use phpOMS\Module\InstallerAbstract; /** @@ -29,50 +26,4 @@ use phpOMS\Module\InstallerAbstract; */ class Installer extends InstallerAbstract { - - /** - * {@inheritdoc} - */ - public static function install(DatabasePool $dbPool, InfoManager $info) : void - { - parent::install($dbPool, $info); - - switch ($dbPool->get()->getType()) { - case DatabaseType::MYSQL: - $dbPool->get()->con->prepare( - 'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'editor_doc` ( - `editor_doc_id` int(11) NOT NULL AUTO_INCREMENT, - `editor_doc_title` varchar(250) NOT NULL, - `editor_doc_plain` text NOT NULL, - `editor_doc_content` text NOT NULL, - `editor_doc_path` varchar(255) NOT NULL, - `editor_doc_created_at` datetime NOT NULL, - `editor_doc_created_by` int(11) NOT NULL, - PRIMARY KEY (`editor_doc_id`), - KEY `editor_doc_created_by` (`editor_doc_created_by`) - )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' - )->execute(); - - $dbPool->get()->con->prepare( - 'ALTER TABLE `' . $dbPool->get()->prefix . 'editor_doc` - ADD CONSTRAINT `' . $dbPool->get()->prefix . 'editor_doc_ibfk_1` FOREIGN KEY (`editor_doc_created_by`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`);' - )->execute(); - - $dbPool->get()->con->prepare( - 'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'editor_tag` ( - `editor_tag_id` int(11) NOT NULL AUTO_INCREMENT, - `editor_tag_doc` int(11) NOT NULL, - `editor_tag_tag` varchar(20) NOT NULL, - PRIMARY KEY (`editor_tag_id`), - KEY `editor_tag_doc` (`editor_tag_doc`) - )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' - )->execute(); - - $dbPool->get()->con->prepare( - 'ALTER TABLE `' . $dbPool->get()->prefix . 'editor_tag` - ADD CONSTRAINT `' . $dbPool->get()->prefix . 'editor_tag_ibfk_1` FOREIGN KEY (`editor_tag_doc`) REFERENCES `' . $dbPool->get()->prefix . 'editor_doc` (`editor_doc_id`);' - )->execute(); - break; - } - } }