- WIP on migration and some bug fixes linked to withJoin() select problems

This commit is contained in:
Dave Mc Nicoll committed 2025-05-15 18:05:23 +00:00
1 parent 761e0401b0
commit cc6048d4ee
20 files changed
+196 -93

No files matched your search

+1 -1
View File
@@ -5,4 +5,4 @@ namespace Ulmus\Migration\Sql;
class SqliteMigration
{
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
namespace Ulmus\Migration;
use Ulmus\Adapter\AdapterInterface;
use Ulmus\Adapter\SqlFieldMapper;
use Ulmus\ConnectionAdapter;
use Ulmus\Entity\Mysql\Table;
use Ulmus\Repository;
trait SqlMigrationTrait
{
protected array $QUERY_REPLACE = [
'change' => "alter",
];
public function schemaTable(ConnectionAdapter $adapter, $databaseName, string $tableName) : null|object
{
return \Ulmus\Entity\InformationSchema\Table::repository(Repository::DEFAULT_ALIAS, $adapter)
->select(\Ulmus\Common\Sql::raw('this.*'))
->where($this->escapeIdentifier('table_schema', AdapterInterface::IDENTIFIER_FIELD), $databaseName)
->or($this->escapeIdentifier('table_catalog', AdapterInterface::IDENTIFIER_FIELD), $databaseName)
->loadOneFromField($this->escapeIdentifier('table_name', AdapterInterface::IDENTIFIER_FIELD), $tableName);
}
public function mapFieldType(FieldDefinition $field, bool $typeOnly = false) : string
{
$mapper = new SqlFieldMapper($field);
return $typeOnly ? $mapper->type : $mapper->render();
}
public function generateAlterColumn(FieldDefinition $definition, array $field) : string|\Stringable
{
if ($field['action'] === 'add') {
if (! empty($field['previous'])) {
$position = sprintf('AFTER %s', $this->escapeIdentifier($field['previous']->field, AdapterInterface::IDENTIFIER_FIELD));
}
else {
$position = "FIRST";
}
}
return implode(" ", array_filter([
strtoupper($field['action']),
$this->escapeIdentifier($definition->getSqlName(), AdapterInterface::IDENTIFIER_FIELD),
$definition->getSqlType(),
$definition->getSqlParams(),
$position ?? null,
]));
}
public function splitAlterQuery() : bool
{
return false;
}
}