diff --git a/migrations/DoctrineMigrations/Version20260602000000.php b/migrations/DoctrineMigrations/Version20260602000000.php new file mode 100644 index 000000000..b619d8139 --- /dev/null +++ b/migrations/DoctrineMigrations/Version20260602000000.php @@ -0,0 +1,77 @@ +connection->createSchemaManager()->introspectTableIndexes( + new OptionallyQualifiedName(Identifier::unquoted('user'), null) + ); + $existingIndex = array_filter( + $indexes, + static fn(Index $index) => $index->getObjectName()->equals( + UnqualifiedName::unquoted('idx_user_uuid'), + UnquotedIdentifierFolding::NONE + ) + ); + + $this->skipIf( + count($existingIndex) === 0, + 'Index idx_user_uuid on user table does not exist. Skipping (already migrated).' + ); + } + + public function up(Schema $schema): void + { + $this->addSql('SET SESSION innodb_sort_buffer_size = 268435456'); + $this->addSql( + 'ALTER TABLE `user` ADD UNIQUE INDEX `uq_user_uuid` (`uuid`), DROP INDEX `idx_user_uuid`, ALGORITHM=INPLACE, LOCK=NONE' + ); + } + + public function down(Schema $schema): void + { + $this->addSql( + 'ALTER TABLE `user` ADD INDEX `idx_user_uuid` (`uuid`), DROP INDEX `uq_user_uuid`' + ); + } + + public function isTransactional(): bool + { + return false; + } +} diff --git a/src/OpenConext/EngineBlockBundle/Authentication/Entity/User.php b/src/OpenConext/EngineBlockBundle/Authentication/Entity/User.php index 747a5d97d..d5b6ff76a 100644 --- a/src/OpenConext/EngineBlockBundle/Authentication/Entity/User.php +++ b/src/OpenConext/EngineBlockBundle/Authentication/Entity/User.php @@ -23,7 +23,7 @@ use OpenConext\EngineBlockBundle\Authentication\Repository\UserRepository; #[ORM\Entity(repositoryClass: UserRepository::class)] -#[ORM\Index(name: 'idx_user_uuid', columns: ['uuid'])] +#[ORM\UniqueConstraint(name: 'uq_user_uuid', columns: ['uuid'])] class User { /**