Skip to content

Commit d4808ac

Browse files
chore: Guard the unique-index migration against existing duplicates.
1 parent b23d2aa commit d4808ac

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

database/migrations/Version20260424120000.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace Database\Migrations;
1+
<?php
2+
namespace Database\Migrations;
23
/**
34
* Copyright 2026 OpenStack Foundation
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,6 +27,21 @@ final class Version20260424120000 extends AbstractMigration
2627
{
2728
public function up(Schema $schema): void
2829
{
30+
31+
$duplicates = (int) $this->connection->fetchOne(
32+
'SELECT COUNT(*) FROM (
33+
SELECT 1
34+
FROM user_trusted_devices
35+
GROUP BY user_id, device_identifier
36+
HAVING COUNT(*) > 1
37+
) dup'
38+
);
39+
40+
$this->abortIf(
41+
$duplicates > 0,
42+
'Duplicate trusted devices exist; dedupe user_trusted_devices before applying utd_user_device_uniq.'
43+
);
44+
2945
$this->addSql(
3046
'ALTER TABLE user_trusted_devices
3147
DROP INDEX utd_user_device_idx,
@@ -41,4 +57,4 @@ public function down(Schema $schema): void
4157
ADD INDEX utd_user_device_idx (user_id, device_identifier)'
4258
);
4359
}
44-
}
60+
}

0 commit comments

Comments
 (0)