Move schema to json

This commit is contained in:
Dennis Eichhorn 2018-12-22 23:19:20 +01:00
parent 5813c9e528
commit 46899b9118
2 changed files with 74 additions and 45 deletions

73
Admin/Install/db.json Normal file
View File

@ -0,0 +1,73 @@
{
"comments_list": {
"name": "comments_list",
"fields": {
"comments_list_id": {
"name": "comments_list_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
}
}
},
"comments_comment": {
"name": "comments_comment",
"fields": {
"comments_comment_id": {
"name": "comments_comment_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"comments_comment_status": {
"name": "comments_comment_status",
"type": "TINYINT",
"null": false
},
"comments_comment_title": {
"name": "comments_comment_title",
"type": "VARCHAR(255)",
"null": false
},
"comments_comment_content": {
"name": "comments_comment_content",
"type": "TEXT",
"null": false
},
"comments_comment_content_raw": {
"name": "comments_comment_content_raw",
"type": "TEXT",
"null": false
},
"comments_comment_list": {
"name": "comments_comment_list",
"type": "INT",
"null": false,
"foreignTable": "comments_list",
"foreignKey": "comments_list_id"
},
"comments_comment_ref": {
"name": "comments_comment_ref",
"type": "INT",
"default": null,
"null": true,
"foreignTable": "comments_comment",
"foreignKey": "comments_comment_id"
},
"comments_comment_created_by": {
"name": "comments_comment_created_by",
"type": "INT",
"null": false,
"foreignTable": "account",
"foreignKey": "account_id"
},
"comments_comment_created_at": {
"name": "comments_comment_created_at",
"type": "DATETIME",
"null": false
}
}
}
}

View File

@ -14,13 +14,10 @@ declare(strict_types=1);
namespace Modules\Comments\Admin;
use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\Module\InfoManager;
use phpOMS\Module\InstallerAbstract;
/**
* Calendar install class.
* Install class.
*
* @package Modules\Comments\Admin
* @license OMS License 1.0
@ -29,45 +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 . 'comments_list` (
`comments_list_id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`comments_list_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'comments_comment` (
`comments_comment_id` int(11) NOT NULL AUTO_INCREMENT,
`comments_comment_title` varchar(250) NOT NULL,
`comments_comment_content` text NOT NULL,
`comments_comment_list` int(11) DEFAULT NULL,
`comments_comment_ref` int(11) DEFAULT NULL,
`comments_comment_created_at` datetime NOT NULL,
`comments_comment_created_by` int(11) NOT NULL,
PRIMARY KEY (`comments_comment_id`),
KEY `comments_comment_ref` (`comments_comment_ref`),
KEY `comments_comment_created_by` (`comments_comment_created_by`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'comments_comment`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'comments_comment_ibfk_1` FOREIGN KEY (`comments_comment_list`) REFERENCES `' . $dbPool->get()->prefix . 'comments_list` (`comments_list_id`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'comments_comment_ibfk_2` FOREIGN KEY (`comments_comment_ref`) REFERENCES `' . $dbPool->get()->prefix . 'comments_comment` (`comments_comment_id`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'comments_comment_ibfk_3` FOREIGN KEY (`comments_comment_created_by`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`);'
)->execute();
break;
}
}
}