- Added a new Field Mapper to SQLs Adapters.

- Defined missing MySQL fields attributes
- WIP on lean-console's migration methods
This commit is contained in:
Dave Mc Nicoll committed 2024-10-21 18:12:24 +00:00
1 parent 5f4f23a8e4
commit 411992c7a8
17 files changed
+214 -8

No files matched your search

+11
View File
@@ -2,12 +2,15 @@
namespace Ulmus\Adapter;
use Ulmus\ConnectionAdapter;
use Ulmus\Entity\Mysql\Table;
use Ulmus\Migration\FieldDefinition;
use Ulmus\Migration\MigrateInterface;
use Ulmus\QueryBuilder\Sql;
use Ulmus\Common\PdoObject;
use Ulmus\Exception\AdapterConfigurationException;
use Ulmus\Repository;
class MySQL implements AdapterInterface, MigrateInterface, SqlAdapterInterface {
use SqlAdapterTrait;
@@ -166,4 +169,12 @@ class MySQL implements AdapterInterface, MigrateInterface, SqlAdapterInterface {
{
return Sql\MysqlQueryBuilder::class;
}
public function schemaTable(ConnectionAdapter $adapter, $databaseName, string $tableName) : null|object
{
return Table::repository(Repository::DEFAULT_ALIAS, $adapter)
->select(\Ulmus\Common\Sql::raw('this.*'))
->where($this->escapeIdentifier('table_schema', AdapterInterface::IDENTIFIER_FIELD), $databaseName)
->loadOneFromField($this->escapeIdentifier('table_name', AdapterInterface::IDENTIFIER_FIELD), $tableName);
}
}
+10
View File
@@ -28,4 +28,14 @@ class MySQLFieldMapper extends SqlFieldMapper
parent::map();
}
}
public function postProcess() : void
{
if (
in_array($this->type, [ 'BLOB', 'TINYBLOB', 'MEDIUMBLOB', 'LONGBLOB', 'JSON', 'TEXT', 'TINYTEXT', 'MEDIUMTEXT', 'LONGTEXT', 'GEOMETRY' ]) &&
! is_object($this->field->default ?? false) # Could be a functional default, which would now be valid
) {
unset($this->field->default);
}
}
}
+8 -1
View File
@@ -97,7 +97,6 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
public function mapFieldType(FieldDefinition $field, bool $typeOnly = false) : string
{
$type = $field->type;
$length = $field->length;
if ( is_a($type, Entity\Field\Date::class, true) || is_a($type, Entity\Field\Time::class, true) || is_a($type, \DateTime::class, true) ) {
@@ -115,6 +114,10 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
break;
case "array":
$type = "JSON";
$length = null;
break;
case "string":
$type = "TEXT";
$length = null;
@@ -130,6 +133,10 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
}
}
if (in_array($type, [ 'JSON', 'TEXT', 'BLOB', 'GEOMETRY' ])) {
$field->default = "";
}
return $typeOnly ? $type : $type . ( $length ? "($length" . ")" : "" );
}
+9 -1
View File
@@ -46,6 +46,9 @@ class SqlFieldMapper
break;
case "array":
$this->type = "JSON";
break;
case "string":
if ($length && $length <= 255) {
$this->type = "VARCHAR";
@@ -75,13 +78,18 @@ class SqlFieldMapper
default:
$this->type = strtoupper($type);
break;
}
$this->postProcess();
}
public function render() : string
{
return $this->type . ( isset($this->length) ? "($this->length)" : "" );
}
public function postProcess() : void
{
}
}