diff --git a/src/Controller/Dev.php b/src/Controller/Dev.php new file mode 100644 index 0000000..1680371 --- /dev/null +++ b/src/Controller/Dev.php @@ -0,0 +1,28 @@ + "lean.dev:phpinfo") + */ + public function home(ServerRequestInterface $request, array $arguments) : ResponseInterface + { + phpinfo(); + die(); + } +} \ No newline at end of file diff --git a/src/Form/Database.php b/src/Form/Database.php index 0156d5f..e026e54 100644 --- a/src/Form/Database.php +++ b/src/Form/Database.php @@ -8,6 +8,7 @@ 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 @@ -31,22 +32,35 @@ class Database implements FormInterface continue; } - $table = Table::repository()->where(Table::field('name'), $table->tableName()) + $table = Table::repository() + ->where(Table::field('name'), $table->tableName()) ->where(Table::field('schema'), $table->databaseName()) ->loadOne(); if ( $table ) { - #$fields = $entiy::resolveEntity()->fieldList(); + $fields = $entity::resolveEntity()->fieldList(EntityResolver::KEY_COLUMN_NAME, true); - foreach($table->columns as $col) { - //dump( $entity::field($col->name) ); + $alter = []; + + foreach($fields as $field => $definition) { + if ( $table->columns->filtersCollection(fn($e) => $e->name === $field)->count() === 0 ) { + $alter[$field] = $definition; + } } - # if columns are different - $context->status[$entity] = [ - 'msg' => "up-to-date", - 'query' => "", - ]; + 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] = [ @@ -76,6 +90,9 @@ class Database implements FormInterface $entity::repository()->createTable(); } } + elseif ( $context->alter ?? false ) { + + } $this->initialize($context); } diff --git a/src/Lib/ConsoleControllerTrait.php b/src/Lib/ConsoleControllerTrait.php index 6af4701..f94510a 100644 --- a/src/Lib/ConsoleControllerTrait.php +++ b/src/Lib/ConsoleControllerTrait.php @@ -11,7 +11,8 @@ use Picea; /** * @Language("lean.route") * @RouteParam("methods" => [ 'GET', 'POST', 'DELETE' ], "base" => "/~") - * @Security('locked' => false) + * @Security('locked' => true) + * @Taxus("admin") */ trait ConsoleControllerTrait { @@ -23,6 +24,5 @@ trait ConsoleControllerTrait $this->picea = $picea; $this->session = $session; $this->container = $container; - // $this->mailer = $mailer; } } \ No newline at end of file diff --git a/src/Lib/DatabaseMigrations.php b/src/Lib/DatabaseMigrations.php index e169793..7650fb1 100644 --- a/src/Lib/DatabaseMigrations.php +++ b/src/Lib/DatabaseMigrations.php @@ -30,6 +30,8 @@ class DatabaseMigrations $this->entities[$entity] = $entity::resolveEntity(); } } + + ksort($this->entities); } protected static function files(string $path, string $fileExtension = "") : \Generator diff --git a/view/lean-console/base/asset/lean.css b/view/lean-console/base/asset/lean.css index 7bc26ad..06b1eb5 100644 --- a/view/lean-console/base/asset/lean.css +++ b/view/lean-console/base/asset/lean.css @@ -20,15 +20,15 @@ summary {cursor:pointer;} #body-main {background:#ccc;min-height:calc(100vh - 90px);display:flex} /* Header */ -#body-header {background: #385075; color:#fff; min-height:60px;line-height:60px;padding:0 1rem} +#body-header {background: #6b7fa8; color:#fff; min-height:60px;line-height:60px;padding:0 1rem} #body-header .page-title {font-size:1.5rem} #body-header .page-title:before {content:"🔳"; margin-right:10px} /* Footer */ -#body-footer {background: #2e2e30;color: #fff;height: 30px;line-height: 30px;font-size: 0.8rem;padding: 0 0.5rem;text-align: right;border-top:2px solid #434446;} +#body-footer {background: #475262;color: #fff;height: 30px;line-height: 30px;font-size: 0.8rem;padding: 0 0.5rem;text-align: right;border-top:2px solid #434446;} /* Sidebar */ -#main-nav {background:#393a3c;border-top:2px solid #172842;min-width:210px;color:#fff;font-family:consolas, courier new, monospace;font-size:0.9rem} +#main-nav {background:#6b7fa8;border-top:2px solid #44526f;min-width:210px;color:#fff;font-family:consolas, courier new, monospace;font-size:0.9rem} #main-nav label {background:rgba(0,0,0,0.2);text-transform:uppercase ; display:block;padding:0.8rem 1rem;font-size:1.15em;} #main-nav label:before {content:"⊙"; margin-right:10px} #main-nav a {color: #efecec;text-decoration:none;display:block;padding:0rem 1rem;background:rgba(255,255,255,0.05);transition:all 0.3s ease;line-height:3em;font-size:0.9em} @@ -37,7 +37,7 @@ summary {cursor:pointer;} #main-nav li + li {border-top:1px solid #555} /* Main content */ -#main-content {padding:4vh 2vw;border-top:2px solid #172842;width:100%;} +#main-content {padding:4vh 2vw;border-top:2px solid #7d7d7d;width:100%;} #main-content section {border-radius:4px;box-shadow: 1px 1px 3px rgba(0,0,0,0.5)} #main-content section article {background:#fff;padding:2vh 1vw;} #main-content section header {background:#e8e8e8;padding:2vh 1vw;} \ No newline at end of file diff --git a/view/lean-console/page/storage/database.phtml b/view/lean-console/page/storage/database.phtml index 1af4189..bf33e43 100644 --- a/view/lean-console/page/storage/database.phtml +++ b/view/lean-console/page/storage/database.phtml @@ -55,6 +55,7 @@