From 06cf03738738164143dd117cfa2f55223603210c Mon Sep 17 00:00:00 2001 From: Stefan Giehl Date: Mon, 25 Jul 2022 02:37:45 +0200 Subject: Adds unique index for user email (#19560) --- core/Db/Schema/Mysql.php | 3 ++- core/Updates/4.12.0-b2.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++ core/Version.php | 2 +- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 core/Updates/4.12.0-b2.php diff --git a/core/Db/Schema/Mysql.php b/core/Db/Schema/Mysql.php index 1f8bc7d5f9..9ac76c951d 100644 --- a/core/Db/Schema/Mysql.php +++ b/core/Db/Schema/Mysql.php @@ -57,7 +57,8 @@ class Mysql implements SchemaInterface invite_token VARCHAR(191) NULL, invite_expired_at TIMESTAMP NULL, invite_accept_at TIMESTAMP NULL, - PRIMARY KEY(login) + PRIMARY KEY(login), + UNIQUE INDEX `uniq_email` (`email`) ) ENGINE=$engine DEFAULT CHARSET=$charset ", 'user_token_auth' => "CREATE TABLE {$prefixTables}user_token_auth ( diff --git a/core/Updates/4.12.0-b2.php b/core/Updates/4.12.0-b2.php new file mode 100644 index 0000000000..829b22ef10 --- /dev/null +++ b/core/Updates/4.12.0-b2.php @@ -0,0 +1,52 @@ +migration = $factory; + } + + /** + * @param Updater $updater + * + * @return Migration[] + */ + public function getMigrations(Updater $updater) + { + $uniqueIndex = $this->migration->db->addUniqueKey('user', 'email', 'uniq_email'); + + // if for some reason a duplicate email exists we simply ignore the error and don't add the index. + $uniqueIndex->addErrorCodeToIgnore(Migration\Db::ERROR_CODE_DUPLICATE_ENTRY); + + return [$uniqueIndex]; + } + + public function doUpdate(Updater $updater) + { + $updater->executeMigrations(__FILE__, $this->getMigrations($updater)); + } +} diff --git a/core/Version.php b/core/Version.php index 9a5e30e677..1c774e811c 100644 --- a/core/Version.php +++ b/core/Version.php @@ -21,7 +21,7 @@ final class Version * The current Matomo version. * @var string */ - const VERSION = '4.12.0-b1'; + const VERSION = '4.12.0-b2'; const MAJOR_VERSION = 4; -- cgit v1.2.3