migration = $migration; } public function initialize(FormContextInterface $context) : void { $context->tableExist = []; foreach($this->migration->entities as $entity => $table) { $tableName = $table->tableName(); $databaseName = $table->databaseName(); if ( ! $tableName || ! $databaseName ) { continue; } $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; } } 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 = []; }; } }