- Moved Database into migration folder (form)
This commit is contained in:
parent
39b02507a3
commit
3a8e56a617
|
@ -1,122 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Lean\Console\Form;
|
||||
|
||||
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
|
||||
|
||||
use \Lean\Console\Lib;
|
||||
|
||||
use Picea\Compiler\Context;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Ulmus\Common\EntityResolver;
|
||||
use \Ulmus\Entity\InformationSchema\Table;
|
||||
|
||||
class Database implements FormInterface
|
||||
{
|
||||
protected ? Lib\DatabaseMigrations $migration;
|
||||
|
||||
public function __construct(Lib\DatabaseMigrations $migration)
|
||||
{
|
||||
$this->migration = $migration;
|
||||
}
|
||||
|
||||
public function initialize(FormContextInterface $context) : void
|
||||
{
|
||||
$context->tableExist = [];
|
||||
|
||||
foreach($this->migration->entities as $entity => $table) {
|
||||
$adapter = $entity::resolveEntity()->sqlAdapter()->adapter();
|
||||
|
||||
$tableName = $table->tableName();
|
||||
$databaseName = $table->databaseName();
|
||||
|
||||
if ( ! $tableName || ! $databaseName ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#<<<<<<< HEAD
|
||||
$tableEntity = $adapter->schemaTable($databaseName, $tableName);
|
||||
|
||||
if ( $tableEntity ) {
|
||||
#$fields = $entiy::resolveEntity()->fieldList();
|
||||
|
||||
foreach($tableEntity->columns as $col) {
|
||||
//dump( $entity::field($col->name) );
|
||||
#=======
|
||||
# $table = Table::repository()
|
||||
# ->where(Table::field('name'), $table->tableName())
|
||||
# ->where(Table::field('schema'), $table->databaseName())
|
||||
# ->loadOne();
|
||||
|
||||
# if ( $table ) {
|
||||
# $fields = $entity::resolveEntity()->fieldList(EntityResolver::KEY_COLUMN_NAME, true);
|
||||
|
||||
# $alter = [];
|
||||
|
||||
# foreach($fields as $field => $definition) {
|
||||
# if ( $table->columns->filtersCollection(fn($e) => $e->name === $field)->count() === 0 ) {
|
||||
# $alter[$field] = $definition;
|
||||
# }
|
||||
#>>>>>>> 7194a33bec884d745e838c8ac2693b353e95a3ce
|
||||
}
|
||||
|
||||
if ( $alter ) {
|
||||
$context->status[$entity] = [
|
||||
'msg' => "alter",
|
||||
"query" => $entity::repository()->alterSqlQuery($alter)->getSqlQuery(true),
|
||||
];
|
||||
}
|
||||
else {
|
||||
# if columns are different
|
||||
$context->status[$entity] = [
|
||||
'msg' => "up-to-date",
|
||||
'query' => "",
|
||||
];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$context->status[$entity] = [
|
||||
'msg' => "unexisting",
|
||||
'query' => $entity::repository()->createSqlQuery()->getSqlQuery(true),
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( $context->formSent() ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(FormContextInterface $context) : bool
|
||||
{
|
||||
return $context->valid();
|
||||
}
|
||||
|
||||
public function execute(FormContextInterface $context) : void
|
||||
{
|
||||
if ( $context->create ?? false ) {
|
||||
$context->create::repository()->createTable();
|
||||
}
|
||||
elseif ( $context->createAll ?? false ) {
|
||||
foreach(explode(',', $context->createAll) as $entity) {
|
||||
$entity::repository()->createTable();
|
||||
}
|
||||
}
|
||||
elseif ( $context->alter ?? false ) {
|
||||
|
||||
}
|
||||
|
||||
$this->initialize($context);
|
||||
}
|
||||
|
||||
public function getContext(ServerRequestInterface $request) : FormContextInterface
|
||||
{
|
||||
return new class($request) extends FormContext {
|
||||
|
||||
public array $status = [];
|
||||
|
||||
public array $actions = [];
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue