-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EntityMigrator] remove not needed Migration method, automatically cr…
…eate index
- Loading branch information
Showing
6 changed files
with
63 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20241025145126 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE INDEX draw_migration_sate ON user_migration (migration_id, state)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
packages/entity-migrator/EventListener/DoctrineSchemaListener.php
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,34 @@ | ||
<?php | ||
|
||
namespace Draw\Component\EntityMigrator\EventListener; | ||
|
||
use Doctrine\ORM\Mapping\ClassMetadataInfo; | ||
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs; | ||
use Draw\Component\EntityMigrator\Entity\EntityMigrationInterface; | ||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; | ||
|
||
#[AutoconfigureTag( | ||
'doctrine.event_listener', | ||
[ | ||
'event' => 'loadClassMetadata', | ||
] | ||
)] | ||
class DoctrineSchemaListener | ||
{ | ||
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void | ||
{ | ||
$metadata = $eventArgs->getClassMetadata(); | ||
|
||
if (!$metadata instanceof ClassMetadataInfo) { | ||
return; | ||
} | ||
|
||
if (!\in_array(EntityMigrationInterface::class, class_implements($metadata->getName()), true)) { | ||
return; | ||
} | ||
|
||
$metadata->table['indexes']['draw_migration_sate'] = [ | ||
'columns' => ['migration_id', 'state'], | ||
]; | ||
} | ||
} |
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
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