Prepare for json schema installation

This commit is contained in:
Dennis Eichhorn 2018-12-22 19:50:10 +01:00
parent 4fc518dd4b
commit 835f9a5f64
4 changed files with 26 additions and 11 deletions

View File

@ -94,7 +94,7 @@ class MysqlGrammar extends Grammar
foreach ($fields as $name => $field) {
$fieldQuery .= ' ' . $this->expressionizeTableColumn([$name], '') . ' ' . $field['type'];
if (isset($field['default'])) {
if (isset($field['default']) || ($field['default'] === null && isset($field['null']) && $field['null'])) {
$fieldQuery .= ' DEFAULT ' . $this->compileValue($query, $field['default']);
}

View File

@ -0,0 +1,16 @@
{
"name": "[a-z]+",
"fields": {
".*": {
"name": "[a-z]+",
"type": ".+",
".*?default": "1|0",
".*?null": "1|0",
".*?primary": "1|0",
".*?unique": "1|0",
".*?autoincrement": "1|0",
".*?foreignTable": "[a-z]+",
".*?foreignKey": "[a-z]+"
}
}
}

View File

@ -104,7 +104,7 @@ class InstallerAbstract
*
* @since 1.0.0
*/
public static function createTables(DatabasePool $dbPool, InfoManager $info) : void
private static function createTables(DatabasePool $dbPool, InfoManager $info) : void
{
$path = \dirname($info->getPath()) . '/Admin/Install/db.json';
@ -118,7 +118,6 @@ class InstallerAbstract
}
$definitions = \json_decode($content, true);
foreach ($definitions as $definition) {
self::createTable($definition, $dbPool);
}
@ -134,22 +133,21 @@ class InstallerAbstract
*
* @since 1.0.0
*/
public static function createTable(array $definition, DatabasePool $dbPool) : void
private static function createTable(array $definition, DatabasePool $dbPool) : void
{
$builder = new SchemaBuilder($dbPool->get('schema'));
$builder->prefix($dbPool->get('schema')->prefix);
$builder->createTable($definition['table'] ?? '');
$builder->createTable($definition['name'] ?? '');
foreach ($definition['fields'] as $name => $def) {
$builder->field(
$name, $def['type'], $def['default'],
$def['null'], $def['primary'], $def['autoincrement'],
$def['foreign']['table'], $def['foreign']['field']
$name, $def['type'], $def['default'] ?? null,
$def['null'] ?? true, $def['primary'] ?? false, $def['autoincrement'] ?? false,
$def['foreignTable'] ?? null, $def['foreignKey'] ?? null
);
}
}
$builder->execute();
}
/**

View File

@ -323,5 +323,6 @@ $GLOBALS['dbpool']->create('admin', $CONFIG['db']['core']['masters']['admin']);
$GLOBALS['dbpool']->create('select', $CONFIG['db']['core']['masters']['select']);
$GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']);
$GLOBALS['dbpool']->create('update', $CONFIG['db']['core']['masters']['update']);
$GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']);
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());