diff --git a/UPGRADE.md b/UPGRADE.md index da8e9c863..0c7f7fc43 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -93,9 +93,10 @@ and the following changes were made: ### New classes with constants - `Yiisoft\Db\Constant\PhpType` with PHP types constants; -- `Yiisoft\Db\Constant\GettypeResult` with `gettype()` function results constants. -- `Yiisoft\Db\Constant\ColumnType` with abstract column types constants. -- `Yiisoft\Db\Constant\PseudoType` with column pseudo-types constants. +- `Yiisoft\Db\Constant\GettypeResult` with `gettype()` function results constants; +- `Yiisoft\Db\Constant\ColumnType` with abstract column types constants; +- `Yiisoft\Db\Constant\PseudoType` with column pseudo-types constants; +- `Yiisoft\Db\Constant\IndexType` with table index types. ### New classes for table columns diff --git a/src/Command/CommandInterface.php b/src/Command/CommandInterface.php index 975cb9abf..a660f206f 100644 --- a/src/Command/CommandInterface.php +++ b/src/Command/CommandInterface.php @@ -9,6 +9,7 @@ use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Constant\ColumnType; +use Yiisoft\Db\Constant\IndexType; use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; @@ -296,13 +297,15 @@ public function checkIntegrity(string $schema, string $table, bool $check = true * @param string $name The name of the index. * @param array|string $columns The column(s) to include in the index. If there are many columns, * separate them with commas. - * @param string|null $indexType The type of index-supported DBMS - for example: `UNIQUE`, `FULLTEXT`, `SPATIAL`, - * `BITMAP` or null as default. - * @param string|null $indexMethod The setting index organization method (with `USING`, not all DBMS). + * @param string|null $indexType The type of the index supported by DBMS {@see IndexType} - for example: `UNIQUE`, + * `FULLTEXT`, `SPATIAL`, `BITMAP` or null as default. + * @param string|null $indexMethod The index organization method (with `USING`, not all DBMS). * * @throws Exception * @throws InvalidArgumentException * + * @psalm-param IndexType::*|null $indexType + * * Note: The method will quote the `name`, `table`, and `column` parameters before using them in the generated SQL. */ public function createIndex( diff --git a/src/Constant/IndexType.php b/src/Constant/IndexType.php new file mode 100644 index 000000000..a87844d1e --- /dev/null +++ b/src/Constant/IndexType.php @@ -0,0 +1,78 @@ +execute(); $tableSchema = $schema->getTableSchema('uniqueIndex', true); @@ -166,7 +167,7 @@ public function testFindUniquesIndexes(): void 'uniqueIndex', 'someCol2Unique', 'someCol2', - SchemaInterface::INDEX_UNIQUE, + IndexType::UNIQUE, )->execute(); $tableSchema = $schema->getTableSchema('uniqueIndex', true); @@ -181,7 +182,7 @@ public function testFindUniquesIndexes(): void 'uniqueIndex', 'another unique index', 'someCol3', - SchemaInterface::INDEX_UNIQUE, + IndexType::UNIQUE, )->execute(); $tableSchema = $schema->getTableSchema('uniqueIndex', true); diff --git a/tests/Provider/CommandProvider.php b/tests/Provider/CommandProvider.php index ef542e013..d6d4f3173 100644 --- a/tests/Provider/CommandProvider.php +++ b/tests/Provider/CommandProvider.php @@ -10,6 +10,7 @@ use Yiisoft\Db\Command\DataType; use Yiisoft\Db\Command\Param; use Yiisoft\Db\Constant\ColumnType; +use Yiisoft\Db\Constant\IndexType; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Schema\Column\ColumnBuilder; @@ -512,7 +513,7 @@ public static function createIndex(): array { return [ ['{{test_idx_constraint_1}}', '{{test_idx}}', 'int1', null, null], - ['{{test_idx_constraint_2}}', '{{test_idx}}', ['int1'], SchemaInterface::INDEX_UNIQUE, null], + ['{{test_idx_constraint_2}}', '{{test_idx}}', ['int1'], IndexType::UNIQUE, null], ['{{test_idx_constraint_3}}', '{{test_idx}}', ['int1', 'int2'], null, null], ]; } @@ -550,7 +551,7 @@ public static function createIndexSql(): array '{{name}}', '{{table}}', ['column1', 'column2'], - SchemaInterface::INDEX_UNIQUE, + IndexType::UNIQUE, '', DbHelper::replaceQuotes( << [ @@ -947,7 +948,7 @@ public static function createIndex(): array $tableName, $name2, 'C_index_2_1, C_index_2_2', - SchemaInterface::INDEX_UNIQUE, + IndexType::UNIQUE, ), ], ]; diff --git a/tests/Provider/SchemaProvider.php b/tests/Provider/SchemaProvider.php index bd451a4d1..fe840547d 100644 --- a/tests/Provider/SchemaProvider.php +++ b/tests/Provider/SchemaProvider.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Tests\Provider; use PDO; +use Yiisoft\Db\Constant\IndexType; use Yiisoft\Db\Constraint\CheckConstraint; use Yiisoft\Db\Constraint\Constraint; use Yiisoft\Db\Constraint\ForeignKeyConstraint; @@ -190,7 +191,7 @@ public static function withIndexDataProvider(): array { return [ [ - 'indexType' => SchemaInterface::INDEX_UNIQUE, + 'indexType' => IndexType::UNIQUE, 'indexMethod' => null, 'columnType' => null, 'isPrimary' => false,