From eca4a9e923e07be9127718fd2dd4a543373c99b5 Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Tue, 13 Dec 2022 15:01:40 +0100 Subject: [PATCH] Add integration test to ensure correct unique varchar indexes [MAILPOET-4832] --- .../integration/Migrations/DbIndexesTest.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 mailpoet/tests/integration/Migrations/DbIndexesTest.php diff --git a/mailpoet/tests/integration/Migrations/DbIndexesTest.php b/mailpoet/tests/integration/Migrations/DbIndexesTest.php new file mode 100644 index 0000000000..0d9c2a8d58 --- /dev/null +++ b/mailpoet/tests/integration/Migrations/DbIndexesTest.php @@ -0,0 +1,36 @@ +diContainer->get(Connection::class); + $incorrectIndexes = $connection->executeQuery("SELECT DISTINCT + ISS.TABLE_NAME, + ISS.INDEX_NAME, + ISS.COLUMN_NAME, + ISS.NON_UNIQUE, + ISC.CHARACTER_MAXIMUM_LENGTH, + ISC.DATA_TYPE + FROM INFORMATION_SCHEMA.STATISTICS ISS + JOIN INFORMATION_SCHEMA.COLUMNS ISC ON ISC.COLUMN_NAME = ISS.COLUMN_NAME AND ISC.TABLE_NAME = ISS.TABLE_NAME + WHERE ISS.TABLE_NAME LIKE :prefix + AND ISS.NON_UNIQUE = 0 + AND ISC.DATA_TYPE = 'varchar' + AND ISC.CHARACTER_MAXIMUM_LENGTH > 191;", + ['prefix' => Env::$dbPrefix . '%'] + )->fetchAllAssociative(); + if (!empty($incorrectIndexes)) { + $this->fail("The following unique indexes use varchar column, but have incorrect length over 191 chars:\n " . json_encode($incorrectIndexes, JSON_PRETTY_PRINT)); + } + } +}