From 586dfcb3be5724ddae69d81e18cd3413a87949e8 Mon Sep 17 00:00:00 2001 From: Aleksei Prokhorov <a.prokhorov@revizto.com> Date: Thu, 6 Jun 2024 12:11:27 +0300 Subject: [PATCH] Added support of functional indexes for MySQL and Postgres --- src/Driver/AbstractMySQLDriver.php | 5 +---- src/Platforms/AbstractPlatform.php | 6 +++--- src/Platforms/MySQL8013Platform.php | 1 + src/Platforms/MySQL84Platform.php | 5 +++++ src/Platforms/SQLitePlatform.php | 2 +- src/Schema/PostgreSQLSchemaManager.php | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Driver/AbstractMySQLDriver.php b/src/Driver/AbstractMySQLDriver.php index 07a01726d9b..4610bde3bd8 100644 --- a/src/Driver/AbstractMySQLDriver.php +++ b/src/Driver/AbstractMySQLDriver.php @@ -63,10 +63,7 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): Abs return new MySQL8013Platform(); } - if ( - version_compare($version, '8.0.0', '>=') - && version_compare($version, '8.0.13', '<') - ) { + if (version_compare($version, '8.0.0', '>=')) { return new MySQL80Platform(); } diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 1fa69c347b6..d2128186c56 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -802,7 +802,7 @@ private function buildCreateTableSQL(Table $table, bool $createForeignKeys): arr 'but platform "%s" does not support functional indexes.', $index->getName(), $table->getName(), - substr(static::class, (int) strrpos(static::class, '\\') + 1), + get_debug_type($this), )); } @@ -1099,7 +1099,7 @@ public function getCreateIndexSQL(Index $index, string $table): string 'but platform "%s" does not support functional indexes.', $name, $table, - substr(static::class, (int) strrpos(static::class, '\\') + 1), + get_debug_type($this), )); } @@ -1560,7 +1560,7 @@ public function getIndexDeclarationSQL(Index $index): string 'Index "%s" contains a functional part, ' . 'but platform "%s" does not support functional indexes.', $index->getName(), - substr(static::class, (int) strrpos(static::class, '\\') + 1), + get_debug_type($this), )); } diff --git a/src/Platforms/MySQL8013Platform.php b/src/Platforms/MySQL8013Platform.php index 5e87ffe53c5..2b2feaf0428 100644 --- a/src/Platforms/MySQL8013Platform.php +++ b/src/Platforms/MySQL8013Platform.php @@ -8,6 +8,7 @@ * Provides features of the MySQL since 8.0.13 database platform. * * Note: Should not be used with versions prior to 8.0.13. + * @deprecated This class will be removed once support for MySQL 8.0.13 is dropped. */ class MySQL8013Platform extends MySQL80Platform { diff --git a/src/Platforms/MySQL84Platform.php b/src/Platforms/MySQL84Platform.php index 0c304318c62..15d0083840f 100644 --- a/src/Platforms/MySQL84Platform.php +++ b/src/Platforms/MySQL84Platform.php @@ -16,4 +16,9 @@ protected function createReservedKeywordsList(): KeywordList { return new MySQL84Keywords(); } + + public function supportsFunctionalIndex(): bool + { + return true; + } } diff --git a/src/Platforms/SQLitePlatform.php b/src/Platforms/SQLitePlatform.php index 41f4e92f11b..3144747a1f5 100644 --- a/src/Platforms/SQLitePlatform.php +++ b/src/Platforms/SQLitePlatform.php @@ -568,7 +568,7 @@ public function getCreateIndexSQL(Index $index, string $table): string 'but platform "%s" does not support functional indexes.', $name, $table, - substr(static::class, (int) strrpos(static::class, '\\') + 1), + get_debug_type($this), )); } diff --git a/src/Schema/PostgreSQLSchemaManager.php b/src/Schema/PostgreSQLSchemaManager.php index f7c39fd7bb6..f4ebfd82ab4 100644 --- a/src/Schema/PostgreSQLSchemaManager.php +++ b/src/Schema/PostgreSQLSchemaManager.php @@ -161,7 +161,7 @@ protected function _getPortableTableIndexesList(array $tableIndexes, string $tab { $buffer = []; foreach ($tableIndexes as $row) { - $indexColumns = json_decode($row['index_columns'], true); + $indexColumns = json_decode($row['index_columns'], true, flags: JSON_THROW_ON_ERROR); foreach ($indexColumns as $colRow) { $buffer[] = [