- Update on database migration

This commit is contained in:
mcndave committed 2023-08-29 20:28:45 +00:00
1 parent 5035a65672
commit d133ac662e
17 files changed
+174 -33

No files matched your search

-1
View File
@@ -8,7 +8,6 @@ use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
use Lean\Console\{ Form, Lib };
use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
#[Language("lean.caching")]
class Caching extends Console {
use Lib\ConsoleControllerTrait;
-1
View File
@@ -9,7 +9,6 @@ use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
use \Lean\Console\{ Lib, Form };
#[Language("lean.console")]
class Console {
use Lib\ConsoleControllerTrait;
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace Lean\Console\Controller;
use League\Route\Router;
use Picea\{FileFetcher, Picea, Caching\Opcache, Extension\UrlExtension, Ui\Method\FormHandler};
use Lean\File;
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
use Lean\Console\{ Form, Lib };
use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
class Debugging extends Console {
use Lib\ConsoleControllerTrait;
#[Route(route: "/debugging/logs", name: "lean.console:debugging-logs")]
public function logs(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
$list = [];
new FormHandler($request, new Form\Debugging\Logs(), $this->pushContext(new Lib\FormContext($request, "debugging.logs")));
$path = getenv('LOGS_PATH');
$files = array_map(fn($e) => basename($e), glob("$path/*"));
$default = basename(ini_get('error_log'));
$open = end($files);
$content = File::tail($path . DIRECTORY_SEPARATOR . $open, 100);
return $this->renderView("lean-console/page/debugging/logs", get_defined_vars());
}
}
-1
View File
@@ -8,7 +8,6 @@ use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
use \Lean\Console\Lib;
#[Language("lean.dev")]
class Dev {
use Lib\ConsoleControllerTrait;
-1
View File
@@ -11,7 +11,6 @@ use \Lean\Console\Lib;
use Picea\Extension\UrlExtension;
#[Language("lean.request")]
class Request extends Console {
use Lib\ConsoleControllerTrait;
-2
View File
@@ -17,8 +17,6 @@ use Picea\Extension\UrlExtension;
use Ulmus\Annotation\Classes\Table,
Ulmus\Container\AdapterProxy;
#[Language("lean.storage")]
class Storage extends Console {
use Lib\ConsoleControllerTrait;
-1
View File
@@ -13,7 +13,6 @@ use \Lean\Console\Lib;
use Picea\Extension\UrlExtension;
#[Language("lean.templating")] # migrated from: "lean.templating"
class Templating extends Console {
use Lib\ConsoleControllerTrait;
+34
View File
@@ -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
{
}
}
+25 -7
View File
@@ -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() ));
}
}
}
+6 -6
View File
@@ -5,12 +5,12 @@ namespace Lean\Console\Lib\Database;
class Definition
{
public function __construct(
public string $entity,
public string|null $field = null,
public array|null $definition = null,
public null|Modifier $modifier = null,
public null|Definition $previous = null,
public null|string $action = null,
public string $entity,
public string|null $field = null,
public array|null $definition = null,
public null|Modifier|array $modifier = null,
public null|Definition $previous = null,
public null|string $action = null,
) {}
public function toArray() : array