- Update on database migration
This commit is contained in:
1 parent
5035a65672
commit
d133ac662e
17 files changed
+174
-33
No files matched your search
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Console\Form\Debugging;
|
||||
|
||||
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
|
||||
|
||||
use \Lean\Console\Lib;
|
||||
|
||||
use Picea\{Caching\Opcache, Compiler\Context };
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Ulmus\Common\EntityResolver;
|
||||
use \Ulmus\Entity\InformationSchema\Table;
|
||||
|
||||
use RecursiveIteratorIterator, RecursiveDirectoryIterator;
|
||||
|
||||
class Logs implements FormInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function initialize(FormContextInterface $context) : void
|
||||
{
|
||||
}
|
||||
|
||||
public function validate(FormContextInterface $context) : bool
|
||||
{
|
||||
return $context->valid();
|
||||
}
|
||||
|
||||
public function execute(FormContextInterface $context) : void
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -71,11 +71,20 @@ class DatabaseMigration implements FormInterface
|
||||
$alter = $this->definition[$entity]['columns']->filterAlter();
|
||||
|
||||
if ( $alter->count() ) {
|
||||
$tableDefinition->modifier = new Lib\Database\Modifier(
|
||||
if ( $adapter->splitAlterQuery() ) {
|
||||
$query = $alter->map(fn(Lib\Database\Definition $map) => $entity::repository()
|
||||
->alterSqlQuery([$map->toArray()])
|
||||
->getSqlQuery(true));
|
||||
}
|
||||
else {
|
||||
$query = $entity::repository()
|
||||
->alterSqlQuery($alter->map(fn(Lib\Database\Definition $map) => $map->toArray()))
|
||||
->getSqlQuery(true);
|
||||
}
|
||||
|
||||
$tableDefinition->modifier = new Lib\Database\Modifier(
|
||||
type: Lib\Database\ModifierTypeEnum::Alter,
|
||||
query: $entity::repository()
|
||||
->alterSqlQuery($alter->map(fn(Lib\Database\Definition $e) => $e->toArray()))
|
||||
->getSqlQuery(true),
|
||||
query: $query,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -110,10 +119,19 @@ class DatabaseMigration implements FormInterface
|
||||
$alter = $context->alterAll ? explode(',', $context->alterAll) : [ $context->alter ];
|
||||
|
||||
foreach(array_filter($alter) as $entity) {
|
||||
|
||||
|
||||
if ($this->definition[$entity]['table']->modifier->type === Lib\Database\ModifierTypeEnum::Alter) {
|
||||
$entity::repository()->alterTable($this->definition[$entity]['columns']->filterAlter ()->map( fn($e) => $e->toArray() ));
|
||||
$adapter = $entity::resolveEntity()->sqlAdapter()->adapter();
|
||||
|
||||
$def = $this->definition[$entity]['columns']->filterAlter();
|
||||
|
||||
if ( $adapter->splitAlterQuery() ) {
|
||||
$def->walk(fn(Lib\Database\Definition $definition) =>
|
||||
$entity::repository()->alterTable([ $definition->toArray() ])
|
||||
);
|
||||
}
|
||||
else {
|
||||
$entity::repository()->alterTable($def->map( fn(Lib\Database\Definition $e) => $e->toArray() ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user