From ac568b1750484380e3af9917f0feefea475cdaa2 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 30 Aug 2024 19:01:21 +0000 Subject: [PATCH] - WIP on Lean console definition change --- src/Form/Storage/DatabaseMigration.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Form/Storage/DatabaseMigration.php b/src/Form/Storage/DatabaseMigration.php index 7b18ffa..6bb394c 100644 --- a/src/Form/Storage/DatabaseMigration.php +++ b/src/Form/Storage/DatabaseMigration.php @@ -55,10 +55,22 @@ class DatabaseMigration implements FormInterface previous: $def ?? null, ); + $column = $tableEntity->columns->filtersOne(fn($e) => strtolower($e->name) === $field); + # Column do not exists - if ( $tableEntity->columns->filtersCollection(fn($e) => strtolower($e->name) === $field)->count() === 0 ) { + if ( $column === null ) { $def->action = "add"; + $def->modifier = new Lib\Database\Modifier( + type: Lib\Database\ModifierTypeEnum::Alter, + query: $entity::repository() + ->alterSqlQuery([ $def->toArray() ]) + ->getSqlQuery(true) + ); + } + elseif ( ! $column->matchFieldDefinition($definition) ) { + $def->action = "change"; + $def->modifier = new Lib\Database\Modifier( type: Lib\Database\ModifierTypeEnum::Alter, query: $entity::repository() @@ -68,6 +80,7 @@ class DatabaseMigration implements FormInterface } } + # ALTER TABLE `ajustements` CHANGE `annee` `annee` INT(11) NULL; $alter = $this->definition[$entity]['columns']->filterAlter(); if ( $alter->count() ) {