-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatic database migration when enum definition changes #9951
Previously, we had to manually craft a DB migration when we modified the enum definition in PHP. This is now entirely automated. This will migrate all pre-existing enums.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ecodev\Felix\Service; | ||
|
||
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs; | ||
use Ecodev\Felix\DBAL\Types\EnumType; | ||
|
||
/** | ||
* When we update our enum values in PHP (native or non-native), a DB migration will be created automatically. | ||
*/ | ||
class EnumAutoMigrator | ||
{ | ||
public function postGenerateSchema(GenerateSchemaEventArgs $eventArgs): void | ||
{ | ||
foreach ($eventArgs->getSchema()->getTables() as $table) { | ||
foreach ($table->getColumns() as $column) { | ||
$type = $column->getType(); | ||
if ($type instanceof EnumType) { | ||
$hash = md5($type->getQuotedPossibleValues()); | ||
$column->setComment("(FelixEnum:$hash)"); | ||
} | ||
} | ||
} | ||
} | ||
} |