- Bugfixes made while working on lean/console database migrations
This commit is contained in:
parent
8489cb4841
commit
cc741566fb
|
@ -2,7 +2,12 @@
|
||||||
|
|
||||||
namespace Ulmus\Adapter;
|
namespace Ulmus\Adapter;
|
||||||
|
|
||||||
use Ulmus\{ConnectionAdapter, Entity\InformationSchema\Table, Migration\FieldDefinition, Repository, QueryBuilder};
|
use Ulmus\{ConnectionAdapter,
|
||||||
|
Entity\InformationSchema\Table,
|
||||||
|
Migration\FieldDefinition,
|
||||||
|
Repository,
|
||||||
|
QueryBuilder,
|
||||||
|
Ulmus};
|
||||||
|
|
||||||
trait DefaultAdapterTrait
|
trait DefaultAdapterTrait
|
||||||
{
|
{
|
||||||
|
@ -103,8 +108,8 @@ trait DefaultAdapterTrait
|
||||||
|
|
||||||
public function generateAlterColumn(FieldDefinition $definition, array $field) : string|\Stringable
|
public function generateAlterColumn(FieldDefinition $definition, array $field) : string|\Stringable
|
||||||
{
|
{
|
||||||
if ($field['previous']) {
|
if (! empty($field['previous']) ) {
|
||||||
$position = sprintf('AFTER %s', $this->escapeIdentifier($field['previous']['field'], AdapterInterface::IDENTIFIER_FIELD));
|
$position = sprintf('AFTER %s', $this->escapeIdentifier($field['previous']->field, AdapterInterface::IDENTIFIER_FIELD));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$position = "FIRST";
|
$position = "FIRST";
|
||||||
|
@ -118,4 +123,28 @@ trait DefaultAdapterTrait
|
||||||
$position,
|
$position,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function writableValue(mixed $value) : mixed
|
||||||
|
{
|
||||||
|
switch (true) {
|
||||||
|
case $value instanceof \UnitEnum:
|
||||||
|
return Ulmus::convertEnum($value);
|
||||||
|
|
||||||
|
case is_object($value):
|
||||||
|
return Ulmus::convertObject($value);
|
||||||
|
|
||||||
|
case is_array($value):
|
||||||
|
return json_encode($value);
|
||||||
|
|
||||||
|
case is_bool($value):
|
||||||
|
return (int) $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function splitAlterQuery() : bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,26 +218,6 @@ class MsSQL implements AdapterInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function writableValue(mixed $value) /*: mixed*/
|
|
||||||
{
|
|
||||||
switch (true) {
|
|
||||||
case $value instanceof \UnitEnum:
|
|
||||||
return Ulmus::convertEnum($value);
|
|
||||||
|
|
||||||
case is_object($value):
|
|
||||||
return Ulmus::convertObject($value);
|
|
||||||
|
|
||||||
case is_array($value):
|
|
||||||
return json_encode($value);
|
|
||||||
|
|
||||||
case is_bool($value):
|
|
||||||
return (int) $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function defaultEngine(): ? string
|
public function defaultEngine(): ? string
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -252,9 +232,4 @@ class MsSQL implements AdapterInterface {
|
||||||
{
|
{
|
||||||
return QueryBuilder\MssqlQueryBuilder::class;
|
return QueryBuilder\MssqlQueryBuilder::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function splitAlterQuery() : bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,32 +152,8 @@ class MySQL implements AdapterInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function writableValue(mixed $value) : mixed
|
|
||||||
{
|
|
||||||
switch (true) {
|
|
||||||
case $value instanceof \UnitEnum:
|
|
||||||
return Ulmus::convertEnum($value);
|
|
||||||
|
|
||||||
case is_object($value):
|
|
||||||
return Ulmus::convertObject($value);
|
|
||||||
|
|
||||||
case is_array($value):
|
|
||||||
return json_encode($value);
|
|
||||||
|
|
||||||
case is_bool($value):
|
|
||||||
return (int) $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function defaultEngine(): ? string
|
public function defaultEngine(): ? string
|
||||||
{
|
{
|
||||||
return "InnoDB";
|
return "InnoDB";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function splitAlterQuery() : bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,25 +137,6 @@ class SQLite implements AdapterInterface {
|
||||||
return $typeOnly ? $type : $type . ( $length ? "($length" . ( isset($precision) ? ",$precision" : "" ) . ")" : "" );
|
return $typeOnly ? $type : $type . ( $length ? "($length" . ( isset($precision) ? ",$precision" : "" ) . ")" : "" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function writableValue(mixed $value) /*: mixed*/
|
|
||||||
{
|
|
||||||
switch (true) {
|
|
||||||
case $value instanceof \UnitEnum:
|
|
||||||
return Ulmus::convertEnum($value);
|
|
||||||
|
|
||||||
case is_object($value):
|
|
||||||
return Ulmus::convertObject($value);
|
|
||||||
|
|
||||||
case is_array($value):
|
|
||||||
return json_encode($value);
|
|
||||||
|
|
||||||
case is_bool($value):
|
|
||||||
return (int) $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tableSyntax() : array
|
public function tableSyntax() : array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -83,6 +83,6 @@ class Table
|
||||||
public ? string $temporary;
|
public ? string $temporary;
|
||||||
|
|
||||||
#[Relation(type: "oneToMany", key: "name", foreignKey: [ Column::class, 'tableName' ], entity: Column::class)]
|
#[Relation(type: "oneToMany", key: "name", foreignKey: [ Column::class, 'tableName' ], entity: Column::class)]
|
||||||
#[Where('TABLE_SCHEMA', [ Column::class, 'tableSchema' ])]
|
#[Where('TABLE_SCHEMA', fieldValue: [ Column::class, 'tableSchema' ])]
|
||||||
public EntityCollection $columns;
|
public EntityCollection $columns;
|
||||||
}
|
}
|
|
@ -90,14 +90,14 @@ class FieldDefinition {
|
||||||
|
|
||||||
public function getDefault() : mixed
|
public function getDefault() : mixed
|
||||||
{
|
{
|
||||||
if ( isset($this->default) ) {
|
if (isset($this->default)) {
|
||||||
if (is_bool($this->default)) {
|
$value = $this->adapter->writableValue($this->default);
|
||||||
return (int) $this->default;
|
|
||||||
|
if (is_string($value) ) {
|
||||||
|
$value = $this->adapter->escapeIdentifier($value, AdapterInterface::IDENTIFIER_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Specific default cases here ..
|
return $value;
|
||||||
|
|
||||||
return $this->default;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fallback on attribute's default value
|
# Fallback on attribute's default value
|
||||||
|
|
Loading…
Reference in New Issue