Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions migrations/DoctrineMigrations/Version20260602000000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/**
* Copyright 2026 SURFnet B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace OpenConext\EngineBlock\Doctrine\Migrations;

use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Name\Identifier;
use Doctrine\DBAL\Schema\Name\OptionallyQualifiedName;
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
use Doctrine\DBAL\Schema\Name\UnquotedIdentifierFolding;
use Doctrine\DBAL\Schema\Schema;

final class Version20260602000000 extends AbstractEngineBlockMigration
{
public function getDescription(): string
{
return 'Replace non-unique idx_user_uuid with unique index uq_user_uuid on user.uuid';
}

public function preUp(Schema $schema): void
{
parent::preUp($schema);

$indexes = $this->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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down