Move schema to json

This commit is contained in:
Dennis Eichhorn 2018-12-23 15:18:00 +01:00
parent 716f7eefbc
commit 07b2e1f894
2 changed files with 319 additions and 166 deletions

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

@ -0,0 +1,319 @@
{
"profile_account": {
"name": "profile_account",
"fields": {
"profile_account_id": {
"name": "profile_account_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_account_image": {
"name": "profile_account_image",
"type": "INT",
"default": null,
"null": true,
"foreignTable": "media",
"foreignKey": "media_id"
},
"profile_account_birthday": {
"name": "profile_account_birthday",
"type": "DATETIME",
"default": null,
"null": true
},
"profile_account_account": {
"name": "profile_account_account",
"type": "INT",
"null": false,
"foreignTable": "account",
"foreignKey": "account_id"
}
}
},
"profile_account_permission": {
"name": "profile_account_permission",
"fields": {
"profile_account_permission_id": {
"name": "profile_account_permission_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_account_permission_profile": {
"name": "profile_account_permission_profile",
"type": "INT",
"null": false,
"foreignTable": "profile_account",
"foreignKey": "profile_account_id"
},
"profile_account_permission_group": {
"name": "profile_account_permission_group",
"type": "INT",
"null": false,
"foreignTable": "group",
"foreignKey": "group_id"
},
"profile_account_permission_account": {
"name": "profile_account_permission_account",
"type": "INT",
"null": false,
"foreignTable": "account",
"foreignKey": "account_id"
}
}
},
"profile_contact": {
"name": "profile_contact",
"fields": {
"profile_contact_id": {
"name": "profile_contact_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_contact_name1": {
"name": "profile_contact_name1",
"type": "VARCHAR(255)",
"null": false
},
"profile_contact_name2": {
"name": "profile_contact_name2",
"type": "VARCHAR(255)",
"null": false
},
"profile_contact_name3": {
"name": "profile_contact_name3",
"type": "VARCHAR(255)",
"null": false
},
"profile_contact_company": {
"name": "profile_contact_company",
"type": "VARCHAR(255)",
"null": false
},
"profile_contact_company_job": {
"name": "profile_contact_company_job",
"type": "VARCHAR(255)",
"null": false
},
"profile_contact_address": {
"name": "profile_contact_address",
"type": "VARCHAR(255)",
"null": false
},
"profile_contact_website": {
"name": "profile_contact_website",
"type": "VARCHAR(255)",
"null": false
},
"profile_contact_birthday": {
"name": "profile_contact_birthday",
"type": "DATETIME",
"default": null,
"null": true
},
"profile_contact_description": {
"name": "profile_contact_description",
"type": "TEXT",
"null": false
},
"profile_contact_account": {
"name": "profile_contact_account",
"type": "INT",
"null": false,
"foreignTable": "profile_account",
"foreignKey": "profile_account_id"
}
}
},
"profile_contact_element": {
"name": "profile_contact_element",
"comment": "email, phone etc",
"fields": {
"profile_contact_element_id": {
"name": "profile_contact_element_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_contact_element_type": {
"name": "profile_contact_element_type",
"type": "TINYINT",
"null": false
},
"profile_contact_element_subtype": {
"name": "profile_contact_element_subtype",
"type": "TINYINT",
"null": false
},
"profile_contact_element_content": {
"name": "profile_contact_element_content",
"type": "VARCHAR(255)",
"null": false
},
"profile_contact_element_contact": {
"name": "profile_contact_element_contact",
"type": "INT",
"null": false,
"foreignTable": "profile_contact",
"foreignKey": "profile_contact_id"
}
}
},
"profile_contactelement": {
"name": "profile_contactelement",
"comment": "not a full contact only the element like email, phone etc. for the accounts themselves (not profile_account)",
"fields": {
"profile_contactelement_id": {
"name": "profile_contactelement_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_contactelement_type": {
"name": "profile_contactelement_type",
"type": "TINYINT",
"null": false
},
"profile_contactelement_subtype": {
"name": "profile_contactelement_subtype",
"type": "TINYINT",
"null": false
},
"profile_contactelement_content": {
"name": "profile_contactelement_content",
"type": "VARCHAR(255)",
"null": false
},
"profile_contactelement_account": {
"name": "profile_contactelement_account",
"type": "INT",
"null": false,
"foreignTable": "account",
"foreignKey": "account_id"
}
}
},
"profile_address": {
"name": "profile_address",
"fields": {
"profile_address_id": {
"name": "profile_address_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_address_type": {
"name": "profile_address_type",
"type": "TINYINT",
"null": false
},
"profile_address_address": {
"name": "profile_address_address",
"type": "VARCHAR(255)",
"null": false
},
"profile_address_street": {
"name": "profile_address_street",
"type": "VARCHAR(255)",
"null": false
},
"profile_address_city": {
"name": "profile_address_city",
"type": "VARCHAR(255)",
"null": false
},
"profile_address_zip": {
"name": "profile_address_zip",
"type": "VARCHAR(255)",
"null": false
},
"profile_address_country": {
"name": "profile_address_country",
"type": "VARCHAR(255)",
"null": false
},
"profile_address_account": {
"name": "profile_address_account",
"type": "INT",
"null": false,
"foreignTable": "profile_account",
"foreignKey": "profile_account_id"
}
}
},
"profile_account_relation": {
"name": "profile_account_relation",
"fields": {
"profile_account_relation_id": {
"name": "profile_account_relation_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_account_relation_type": {
"name": "profile_account_relation_type",
"type": "TINYINT",
"null": false
},
"profile_account_relation_relation": {
"name": "profile_account_relation_relation",
"type": "INT",
"default": null,
"null": true
},
"profile_account_relation_account": {
"name": "profile_account_relation_account",
"type": "INT",
"default": null,
"null": true,
"foreignTable": "account",
"foreignKey": "account_id"
}
}
},
"profile_account_setting": {
"name": "profile_account_setting",
"fields": {
"profile_account_setting_id": {
"name": "profile_account_setting_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"profile_account_setting_module": {
"name": "profile_account_setting_module",
"type": "INT",
"null": false
},
"profile_account_setting_type": {
"name": "profile_account_setting_type",
"type": "VARCHAR(20)",
"null": false
},
"profile_account_setting_value": {
"name": "profile_account_setting_value",
"type": "VARCHAR(32)",
"default": null,
"null": true
},
"profile_account_setting_account": {
"name": "profile_account_setting_account",
"type": "INT",
"default": null,
"null": true,
"foreignTable": "account",
"foreignKey": "account_id"
}
}
}
}

View File

@ -14,9 +14,6 @@ declare(strict_types=1);
namespace Modules\Profile\Admin;
use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\Module\InfoManager;
use phpOMS\Module\InstallerAbstract;
/**
@ -29,167 +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 . 'profile_account` (
`profile_account_id` int(11) NOT NULL AUTO_INCREMENT,
`profile_account_image` int(11) DEFAULT NULL,
`profile_account_birthday` datetime DEFAULT NULL,
`profile_account_account` int(11) NOT NULL,
PRIMARY KEY (`profile_account_id`),
KEY `profile_account_image` (`profile_account_image`),
KEY `profile_account_account` (`profile_account_account`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'profile_account`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'profile_account_ibfk_1` FOREIGN KEY (`profile_account_image`) REFERENCES `' . $dbPool->get()->prefix . 'media` (`media_id`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'profile_account_ibfk_2` FOREIGN KEY (`profile_account_account`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`);'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'profile_account_permission` (
`profile_account_permission_id` int(11) NOT NULL AUTO_INCREMENT,
`profile_account_permission_profile` int(11) NOT NULL,
`profile_account_permission_account` int(11) NOT NULL,
`profile_account_permission_group` int(11) NOT NULL,
PRIMARY KEY (`profile_account_permission_id`),
KEY `profile_account_permission_profile` (`profile_account_permission_profile`),
KEY `profile_account_permission_account` (`profile_account_permission_account`),
KEY `profile_account_permission_group` (`profile_account_permission_group`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'profile_account_permission`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'profile_account_permission_ibfk_1` FOREIGN KEY (`profile_account_permission_profile`) REFERENCES `' . $dbPool->get()->prefix . 'profile_account` (`profile_account_id`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'profile_account_permission_ibfk_2` FOREIGN KEY (`profile_account_permission_account`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'profile_account_permission_ibfk_3` FOREIGN KEY (`profile_account_permission_group`) REFERENCES `' . $dbPool->get()->prefix . 'group` (`group_id`);'
)->execute();
// real contacts that you also save in your email contact list. this is to store other accounts
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'profile_contact` (
`profile_contact_id` int(11) NOT NULL AUTO_INCREMENT,
`profile_contact_name1` varchar(250) NOT NULL,
`profile_contact_name2` varchar(250) NOT NULL,
`profile_contact_name3` varchar(250) NOT NULL,
`profile_contact_company` varchar(250) NOT NULL,
`profile_contact_company_job` varchar(250) NOT NULL,
`profile_contact_address` varchar(250) NOT NULL,
`profile_contact_website` varchar(250) NOT NULL,
`profile_contact_birthday` datetime NOT NULL,
`profile_contact_description` text NOT NULL,
`profile_contact_account` int(11) NOT NULL,
PRIMARY KEY (`profile_contact_id`),
KEY `profile_contact_account` (`profile_contact_account`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'profile_contact`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'profile_contact_ibfk_1` FOREIGN KEY (`profile_contact_account`) REFERENCES `' . $dbPool->get()->prefix . 'profile_account` (`profile_account_id`);'
)->execute();
// email, phone etc for profile_contact
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'profile_contact_element` (
`profile_contact_element_id` int(11) NOT NULL AUTO_INCREMENT,
`profile_contact_element_type` tinyint(2) NOT NULL,
`profile_contact_element_subtype` tinyint(2) NOT NULL,
`profile_contact_element_content` varchar(50) NOT NULL,
`profile_contact_element_contact` int(11) NOT NULL,
PRIMARY KEY (`profile_contact_element_id`),
KEY `profile_contact_element_contact` (`profile_contact_element_contact`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'profile_contact_element`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'profile_contact_element_ibfk_1` FOREIGN KEY (`profile_contact_element_contact`) REFERENCES `' . $dbPool->get()->prefix . 'profile_contact` (`profile_contact_id`);'
)->execute();
// not a full contact only the element like email, phone etc. for the accounts themselves (not profile_account)
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'profile_contactelement` (
`profile_contactelement_id` int(11) NOT NULL AUTO_INCREMENT,
`profile_contactelement_type` tinyint(2) NOT NULL,
`profile_contactelement_subtype` tinyint(2) NOT NULL,
`profile_contactelement_content` varchar(50) NOT NULL,
`profile_contactelement_account` int(11) NOT NULL,
PRIMARY KEY (`profile_contactelement_id`),
KEY `profile_contactelement_account` (`profile_contactelement_account`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'profile_contactelement`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'profile_contactelement_ibfk_1` FOREIGN KEY (`profile_contactelement_account`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`);'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'profile_address` (
`profile_address_id` int(11) NOT NULL AUTO_INCREMENT,
`profile_address_type` tinyint(2) NOT NULL,
`profile_address_address` varchar(255) NOT NULL,
`profile_address_street` varchar(255) NOT NULL,
`profile_address_city` varchar(255) NOT NULL,
`profile_address_zip` varchar(255) NOT NULL,
`profile_address_country` varchar(255) NOT NULL,
`profile_address_account` int(11) DEFAULT NULL,
PRIMARY KEY (`profile_address_id`),
KEY `profile_address_account` (`profile_address_account`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'profile_address`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'profile_address_ibfk_1` FOREIGN KEY (`profile_address_account`) REFERENCES `' . $dbPool->get()->prefix . 'profile_account` (`profile_account_id`);'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'profile_account_relation` (
`profile_account_relation_id` int(11) NOT NULL AUTO_INCREMENT,
`profile_account_relation_type` tinyint(2) NOT NULL,
`profile_account_relation_relation` int(11) DEFAULT NULL,
`profile_account_relation_account` int(11) DEFAULT NULL,
PRIMARY KEY (`profile_account_relation_id`),
KEY `profile_account_relation_account` (`profile_account_relation_account`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'profile_account_relation`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'profile_account_relation_ibfk_1` FOREIGN KEY (`profile_account_relation_account`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`);'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'profile_account_setting` (
`profile_account_setting_id` int(11) NOT NULL AUTO_INCREMENT,
`profile_account_setting_module` int(11) NOT NULL,
`profile_account_setting_type` varchar(20) NOT NULL,
`profile_account_setting_value` varchar(32) DEFAULT NULL,
`profile_account_setting_account` int(11) DEFAULT NULL,
PRIMARY KEY (`profile_account_setting_id`),
KEY `profile_account_setting_account` (`profile_account_setting_account`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'profile_account_setting`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'profile_account_setting_ibfk_1` FOREIGN KEY (`profile_account_setting_account`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`);'
)->execute();
break;
}
}
}