- Update on database migration
This commit is contained in:
parent
5035a65672
commit
d133ac662e
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"title" : "Debugging -- LEAN",
|
||||||
|
"page-title": "Déboguage",
|
||||||
|
"breadcrumb" : {
|
||||||
|
"index" : "Negundo"
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,6 +20,11 @@
|
||||||
"label": "Caching"
|
"label": "Caching"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"debugging": {
|
||||||
|
"label": "Déboguage",
|
||||||
|
"logs": "Logs"
|
||||||
|
},
|
||||||
|
|
||||||
"request": {
|
"request": {
|
||||||
"label": "Request",
|
"label": "Request",
|
||||||
"routes": "Routes"
|
"routes": "Routes"
|
||||||
|
|
|
@ -8,7 +8,6 @@ use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
||||||
use Lean\Console\{ Form, Lib };
|
use Lean\Console\{ Form, Lib };
|
||||||
use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
|
use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
|
||||||
|
|
||||||
#[Language("lean.caching")]
|
|
||||||
class Caching extends Console {
|
class Caching extends Console {
|
||||||
use Lib\ConsoleControllerTrait;
|
use Lib\ConsoleControllerTrait;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
|
||||||
|
|
||||||
use \Lean\Console\{ Lib, Form };
|
use \Lean\Console\{ Lib, Form };
|
||||||
|
|
||||||
#[Language("lean.console")]
|
|
||||||
class Console {
|
class Console {
|
||||||
use Lib\ConsoleControllerTrait;
|
use Lib\ConsoleControllerTrait;
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,6 @@ use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
|
||||||
|
|
||||||
use \Lean\Console\Lib;
|
use \Lean\Console\Lib;
|
||||||
|
|
||||||
#[Language("lean.dev")]
|
|
||||||
class Dev {
|
class Dev {
|
||||||
use Lib\ConsoleControllerTrait;
|
use Lib\ConsoleControllerTrait;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ use \Lean\Console\Lib;
|
||||||
|
|
||||||
use Picea\Extension\UrlExtension;
|
use Picea\Extension\UrlExtension;
|
||||||
|
|
||||||
#[Language("lean.request")]
|
|
||||||
class Request extends Console {
|
class Request extends Console {
|
||||||
use Lib\ConsoleControllerTrait;
|
use Lib\ConsoleControllerTrait;
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,6 @@ use Picea\Extension\UrlExtension;
|
||||||
use Ulmus\Annotation\Classes\Table,
|
use Ulmus\Annotation\Classes\Table,
|
||||||
Ulmus\Container\AdapterProxy;
|
Ulmus\Container\AdapterProxy;
|
||||||
|
|
||||||
|
|
||||||
#[Language("lean.storage")]
|
|
||||||
class Storage extends Console {
|
class Storage extends Console {
|
||||||
use Lib\ConsoleControllerTrait;
|
use Lib\ConsoleControllerTrait;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ use \Lean\Console\Lib;
|
||||||
|
|
||||||
use Picea\Extension\UrlExtension;
|
use Picea\Extension\UrlExtension;
|
||||||
|
|
||||||
#[Language("lean.templating")] # migrated from: "lean.templating"
|
|
||||||
class Templating extends Console {
|
class Templating extends Console {
|
||||||
use Lib\ConsoleControllerTrait;
|
use Lib\ConsoleControllerTrait;
|
||||||
|
|
||||||
|
|
|
@ -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();
|
$alter = $this->definition[$entity]['columns']->filterAlter();
|
||||||
|
|
||||||
if ( $alter->count() ) {
|
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,
|
type: Lib\Database\ModifierTypeEnum::Alter,
|
||||||
query: $entity::repository()
|
query: $query,
|
||||||
->alterSqlQuery($alter->map(fn(Lib\Database\Definition $e) => $e->toArray()))
|
|
||||||
->getSqlQuery(true),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,10 +119,19 @@ class DatabaseMigration implements FormInterface
|
||||||
$alter = $context->alterAll ? explode(',', $context->alterAll) : [ $context->alter ];
|
$alter = $context->alterAll ? explode(',', $context->alterAll) : [ $context->alter ];
|
||||||
|
|
||||||
foreach(array_filter($alter) as $entity) {
|
foreach(array_filter($alter) as $entity) {
|
||||||
|
|
||||||
|
|
||||||
if ($this->definition[$entity]['table']->modifier->type === Lib\Database\ModifierTypeEnum::Alter) {
|
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() ));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@ namespace Lean\Console\Lib\Database;
|
||||||
class Definition
|
class Definition
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $entity,
|
public string $entity,
|
||||||
public string|null $field = null,
|
public string|null $field = null,
|
||||||
public array|null $definition = null,
|
public array|null $definition = null,
|
||||||
public null|Modifier $modifier = null,
|
public null|Modifier|array $modifier = null,
|
||||||
public null|Definition $previous = null,
|
public null|Definition $previous = null,
|
||||||
public null|string $action = null,
|
public null|string $action = null,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function toArray() : array
|
public function toArray() : array
|
||||||
|
|
|
@ -26,4 +26,10 @@
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{% route 'lean.console:caching' %}">{% lang "lean.nav.templating.picea" %}</a></li>
|
<li><a href="{% route 'lean.console:caching' %}">{% lang "lean.nav.templating.picea" %}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<label>{% lang "lean.nav.debugging.label" %}</label>
|
||||||
|
<ul>
|
||||||
|
<li><a href="{% route 'lean.console:debugging-logs' %}">{% lang "lean.nav.debugging.logs" %}</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
</nav>
|
</nav>
|
|
@ -13,16 +13,24 @@
|
||||||
<section>
|
<section>
|
||||||
<header>
|
<header>
|
||||||
<h1>{{ $path }}</h1>
|
<h1>{{ $path }}</h1>
|
||||||
{% ui.form.post "caching.picea" %}
|
{% ui:form.post "caching.picea" %}
|
||||||
<button class="btn-red" type="submit">{% _ 'clear' %}</button>
|
<button class="btn-red" type="submit">{% _ 'clear' %}</button>
|
||||||
{% ui.endform %}
|
{% ui:endform %}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<article class="picea">
|
<article class="picea">
|
||||||
{% foreach $folder as $file %}
|
{% foreach $folder as $file %}
|
||||||
|
{% php $import = include($file) %}
|
||||||
|
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<strong class="col route-name">{{ substr($file, strlen($path)) }}</strong>
|
<strong class="col route-name">{{ substr($file, strlen($path)) }}</strong>
|
||||||
<div>
|
|
||||||
|
<div class="col">
|
||||||
|
{{ $import['namespace'] }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col">
|
||||||
|
{{ $import['view'] }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endforeach %}
|
{% endforeach %}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
{% extends "lean-console/base/layout" %}
|
||||||
|
|
||||||
|
{% language.set "lean.caching" %}
|
||||||
|
|
||||||
|
{% title _("title") %}
|
||||||
|
|
||||||
|
{% section "header" %}
|
||||||
|
<div class="page-title">{% _ "page-title" %}</div>
|
||||||
|
{% endsection %}
|
||||||
|
|
||||||
|
{% section "content" %}
|
||||||
|
<section>
|
||||||
|
<header>
|
||||||
|
<h1>{{ $path }}</h1>
|
||||||
|
|
||||||
|
{% ui:form.get current_url() %}
|
||||||
|
{% ui:select 'logfile', array_combine($files, $files), get('file') ?? $open %}
|
||||||
|
{% ui:endform %}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<article class="logs">
|
||||||
|
<div class="log-item">
|
||||||
|
{% foreach array_reverse($content) as $line %}
|
||||||
|
<div class="line">{{ $line }}</div>
|
||||||
|
{% endforeach %}
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
|
<style>
|
||||||
|
section > header {display:flex;justify-content: space-between}
|
||||||
|
.log-item {max-height: 60vh; overflow-y:auto}
|
||||||
|
.log-item .line {padding:0.5rem}
|
||||||
|
.log-item .line {background: #efefef}
|
||||||
|
.log-item .line:nth-child(even) {background: #ccc}
|
||||||
|
</style>
|
||||||
|
{% endsection %}
|
|
@ -40,14 +40,14 @@
|
||||||
<div class="col text-right">{% _ 'database.table.actions' %}</div>
|
<div class="col text-right">{% _ 'database.table.actions' %}</div>
|
||||||
</strong>
|
</strong>
|
||||||
|
|
||||||
{% ui.form.post "database" %}
|
{% ui:form.post "database" %}
|
||||||
{% foreach array_filter($migrations->entities, fn($e) => $e->databaseAdapter() === $connection) as $entity => $item %}
|
{% foreach array_filter($migrations->entities, fn($e) => $e->databaseAdapter() === $connection) as $entity => $item %}
|
||||||
<div class="grid table-item align-items-center">
|
<div class="grid table-item align-items-center">
|
||||||
<div class="col"><span>📄</span> <span>{{ $item->tableName() }}</span></div>
|
<div class="col"><span>📄</span> <span>{{ $item->tableName() }}</span></div>
|
||||||
<div class="col">{% _ "database.table.fields", [ 'count' => count( $item->fieldList() ) ] %}</div>
|
<div class="col">{% _ "database.table.fields", [ 'count' => count( $item->fieldList() ) ] %}</div>
|
||||||
<div class="col col-grow-2">
|
<div class="col col-grow-2">
|
||||||
{% if $context->definition[$entity]['table']->modifier->query %}
|
{% if $context->definition[$entity]['table']->modifier->query %}
|
||||||
<code>{{ $context->definition[$entity]['table']->modifier->query }}</code>
|
<code>{{= implode('<br><br>',(array) $context->definition[$entity]['table']->modifier->query) }}</code>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div>🗸 This table is up-to-date</div>
|
<div>🗸 This table is up-to-date</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -86,7 +86,7 @@
|
||||||
<button name="alterAll" value="{{ implode(',', $alterAll) }}" class="btn-red">🗸 {% _ 'database.table.alterAll' %}</button>
|
<button name="alterAll" value="{{ implode(',', $alterAll) }}" class="btn-red">🗸 {% _ 'database.table.alterAll' %}</button>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% ui.endform %}
|
{% ui:endform %}
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
{% section "content" %}
|
{% section "content" %}
|
||||||
{% if $connections %}
|
{% if $connections %}
|
||||||
{% ui.form.post "database.import" %}
|
{% ui:form.post "database.import" %}
|
||||||
<section>
|
<section>
|
||||||
<header>Import data from a connection into another</header>
|
<header>Import data from a connection into another</header>
|
||||||
|
|
||||||
|
@ -19,15 +19,15 @@
|
||||||
{% php $select = array_combine(array_column($connections, 'name'), array_column($connections, 'name')) %}
|
{% php $select = array_combine(array_column($connections, 'name'), array_column($connections, 'name')) %}
|
||||||
|
|
||||||
<div class="db-grid">
|
<div class="db-grid">
|
||||||
Source connection: {% ui.select "source", $select %}
|
Source connection: {% ui:select "source", $select %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="db-grid">
|
<div class="db-grid">
|
||||||
Destination connection: {% ui.select "destination", $select %}
|
Destination connection: {% ui:select "destination", $select %}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% ui.hidden 'source', $context->source %}
|
{% ui:hidden 'source', $context->source %}
|
||||||
{% ui.hidden 'destination', $context->destination %}
|
{% ui:hidden 'destination', $context->destination %}
|
||||||
|
|
||||||
<div class="db-grid">
|
<div class="db-grid">
|
||||||
COPY DATA FROM → TO:
|
COPY DATA FROM → TO:
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
{% foreach $dest as $key => $value %}
|
{% foreach $dest as $key => $value %}
|
||||||
<div class="db-grid">
|
<div class="db-grid">
|
||||||
<span>{% ui.select "copy[$key]", [ null => '' ] + $context->sourceTables->buildArray('entityClass', 'entityClass') %}</span>
|
<span>{% ui:select "copy[$key]", [ null => '' ] + $context->sourceTables->buildArray('entityClass', 'entityClass') %}</span>
|
||||||
<span>→</span>
|
<span>→</span>
|
||||||
<span>{{ sprintf('%s (%s)', $key, $value->tableName()) }}</span>
|
<span>{{ sprintf('%s (%s)', $key, $value->tableName()) }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
<a href="{% route 'lean.console:storage.database' %}" class="btn-red">Cancel</a>
|
<a href="{% route 'lean.console:storage.database' %}" class="btn-red">Cancel</a>
|
||||||
</footer>
|
</footer>
|
||||||
</section>
|
</section>
|
||||||
{% ui.endform %}
|
{% ui:endform %}
|
||||||
{% else %}
|
{% else %}
|
||||||
No connection found
|
No connection found
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in New Issue