- WIP on Alter table for lean-console
This commit is contained in:
1 parent
9514a46ae7
commit
2ad52aba85
11 files changed
+63
-11
No files matched your search
@@ -29,4 +29,5 @@ interface AdapterInterface {
|
||||
public function queryBuilderClass() : string;
|
||||
public function tableSyntax() : array;
|
||||
public function whitelistAttributes(array &$parameters) : void;
|
||||
public function generateAlterColumn(FieldDefinition $definition, array $field) : string|\Stringable;
|
||||
}
|
||||
@@ -100,4 +100,22 @@ trait DefaultAdapterTrait
|
||||
{
|
||||
$parameters = array_intersect_key($parameters, array_flip(static::ALLOWED_ATTRIBUTES));
|
||||
}
|
||||
|
||||
public function generateAlterColumn(FieldDefinition $definition, array $field) : string|\Stringable
|
||||
{
|
||||
if ($field['previous']) {
|
||||
$position = sprintf('AFTER %s', $adapter->escapeIdentifier($field['previous']['field'], AdapterInterface::IDENTIFIER_FIELD));
|
||||
}
|
||||
else {
|
||||
$position = "FIRST";
|
||||
}
|
||||
|
||||
return implode(" ", [
|
||||
strtoupper($field['action']),
|
||||
$this->escapeIdentifier($definition->getSqlName(), AdapterInterface::IDENTIFIER_FIELD),
|
||||
$definition->getSqlType(),
|
||||
$definition->getSqlParams(),
|
||||
$position,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -203,4 +203,14 @@ class SQLite implements AdapterInterface {
|
||||
$pdo->sqliteCreateFunction('month', fn($date) => ( new \DateTime($date) )->format('m'), 1);
|
||||
$pdo->sqliteCreateFunction('year', fn($date) => ( new \DateTime($date) )->format('Y'), 1);
|
||||
}
|
||||
|
||||
public function generateAlterColumn(FieldDefinition $definition, array $field) : string|\Stringable
|
||||
{
|
||||
return implode(" ", [
|
||||
strtoupper($field['action']),
|
||||
$this->escapeIdentifier($definition->getSqlName(), static::IDENTIFIER_FIELD),
|
||||
$definition->getSqlType(),
|
||||
$definition->getSqlParams(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user