From 7ca35396e0ed829220d7c32ffa00b6f0c7e8700a Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 12 Dec 2024 13:44:55 +0100 Subject: [PATCH] MigrationAnalyzer: minor adjustment (#109) --- README.md | 4 ++++ src/{MigrationsAnalyzer.php => MigrationAnalyzer.php} | 2 +- src/MigrationDefaultAnalyzer.php | 2 +- src/MigrationService.php | 4 ++-- tests/MigrationServiceTest.php | 4 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) rename src/{MigrationsAnalyzer.php => MigrationAnalyzer.php} (94%) diff --git a/README.md b/README.md index 5618bf8..7b9425d 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,10 @@ You can hook into migration execution by implementing `MigrationExecutor` interf Implement `executeQuery()` to run checks or other code before/after each query. Interface of this method mimics interface of `Doctrine\DBAL\Connection::executeQuery()`. +#### Alter generated migration SQLs: +You can implement custom `MigrationAnalyzer` and register it as a service. +This allows you to alter generated SQLs (e.g. add `ALGORITHM=INSTANT`) and assign them to proper phase. + #### Run all queries within transaction: You can change your template (or a single migration) to extend; `TransactionalMigration`. diff --git a/src/MigrationsAnalyzer.php b/src/MigrationAnalyzer.php similarity index 94% rename from src/MigrationsAnalyzer.php rename to src/MigrationAnalyzer.php index f05b082..74166f1 100644 --- a/src/MigrationsAnalyzer.php +++ b/src/MigrationAnalyzer.php @@ -12,7 +12,7 @@ * - drop statements * - reorder statements */ -interface MigrationsAnalyzer +interface MigrationAnalyzer { /** diff --git a/src/MigrationDefaultAnalyzer.php b/src/MigrationDefaultAnalyzer.php index e91bb74..4ccde93 100644 --- a/src/MigrationDefaultAnalyzer.php +++ b/src/MigrationDefaultAnalyzer.php @@ -2,7 +2,7 @@ namespace ShipMonk\Doctrine\Migration; -class MigrationDefaultAnalyzer implements MigrationsAnalyzer +class MigrationDefaultAnalyzer implements MigrationAnalyzer { /** diff --git a/src/MigrationService.php b/src/MigrationService.php index 78e916f..35ef938 100644 --- a/src/MigrationService.php +++ b/src/MigrationService.php @@ -33,14 +33,14 @@ class MigrationService private MigrationVersionProvider $versionProvider; - private MigrationsAnalyzer $migrationsAnalyzer; + private MigrationAnalyzer $migrationsAnalyzer; public function __construct( EntityManagerInterface $entityManager, MigrationConfig $config, ?MigrationExecutor $executor = null, ?MigrationVersionProvider $versionProvider = null, - ?MigrationsAnalyzer $migrationsAnalyzer = null + ?MigrationAnalyzer $migrationsAnalyzer = null ) { $this->entityManager = $entityManager; diff --git a/tests/MigrationServiceTest.php b/tests/MigrationServiceTest.php index 4297e47..c0b6ddb 100644 --- a/tests/MigrationServiceTest.php +++ b/tests/MigrationServiceTest.php @@ -179,7 +179,7 @@ public function getNextVersion(): string }; [$entityManager, $logger] = $this->createEntityManagerAndLogger(); - $statementAnalyser = new class implements MigrationsAnalyzer + $statementAnalyser = new class implements MigrationAnalyzer { /** @@ -295,7 +295,7 @@ private function createMigrationService( array $excludedTables = [], bool $transactional = false, ?MigrationVersionProvider $versionProvider = null, - ?MigrationsAnalyzer $statementAnalyzer = null + ?MigrationAnalyzer $statementAnalyzer = null ): MigrationService { $migrationsDir = $this->getMigrationsTestDir();