diff --git a/src/Expression/JsonExpression.php b/src/Expression/JsonExpression.php index fa2014f2f..b5898f5f4 100644 --- a/src/Expression/JsonExpression.php +++ b/src/Expression/JsonExpression.php @@ -19,9 +19,6 @@ */ class JsonExpression implements ExpressionInterface, JsonSerializable { - public const TYPE_JSON = 'json'; - public const TYPE_JSONB = 'jsonb'; - public function __construct(protected mixed $value, private string|null $type = null) { if ($value instanceof self) { diff --git a/src/QueryBuilder/QueryBuilderInterface.php b/src/QueryBuilder/QueryBuilderInterface.php index d9352f9c7..468c161af 100644 --- a/src/QueryBuilder/QueryBuilderInterface.php +++ b/src/QueryBuilder/QueryBuilderInterface.php @@ -12,11 +12,6 @@ interface QueryBuilderInterface extends DDLQueryBuilderInterface, DMLQueryBuilderInterface, DQLQueryBuilderInterface { - /** - * Defines a UNIQUE index type for {@see createIndex()}. - */ - public const INDEX_UNIQUE = 'UNIQUE'; - /** * Helper method to add $value to $params array using {@see PARAM_PREFIX}. * diff --git a/src/Schema/AbstractColumnSchemaBuilder.php b/src/Schema/AbstractColumnSchemaBuilder.php index 289c3af21..bdc08e82e 100644 --- a/src/Schema/AbstractColumnSchemaBuilder.php +++ b/src/Schema/AbstractColumnSchemaBuilder.php @@ -20,7 +20,7 @@ * For example, the following code creates a column schema for an integer column: * * ```php - * $column = (new ColumnSchemaBuilder(Schema::TYPE_INTEGER))->notNull()->defaultValue(0); + * $column = (new ColumnSchemaBuilder(SchemaInterface::TYPE_INTEGER))->notNull()->defaultValue(0); * ``` * * The AbstractColumnSchemaBuilder class provides a fluent interface, which means that the methods can be chained diff --git a/src/Schema/SchemaInterface.php b/src/Schema/SchemaInterface.php index e4544db2e..23cbd72fc 100644 --- a/src/Schema/SchemaInterface.php +++ b/src/Schema/SchemaInterface.php @@ -24,6 +24,33 @@ interface SchemaInterface extends ConstraintSchemaInterface public const FOREIGN_KEYS = 'foreignKeys'; public const DEFAULT_VALUES = 'defaultValues'; public const UNIQUES = 'uniques'; + public const DEFAULTS = 'defaults'; + + /** + * Types of supported indexes {@see QueryBuilderInterface::createIndex()}. + * MySQL, MSSQL, Oracle, PostgreSQL, SQLite + */ + public const INDEX_UNIQUE = 'UNIQUE'; + + /* MySQL, PostgreSQL */ + public const INDEX_BTREE = 'BTREE'; + public const INDEX_HASH = 'HASH'; + + /* MySQL */ + public const INDEX_FULLTEXT = 'FULLTEXT'; + public const INDEX_SPATIAL = 'SPATIAL'; + + /* PostgreSQL */ + public const INDEX_GIST = 'GIST'; + public const INDEX_GIN = 'GIN'; + public const INDEX_BRIN = 'BRIN'; + + /* MS SQL */ + public const INDEX_CLUSTERED = 'CLUSTERED'; + public const INDEX_NONCLUSTERED = 'NONCLUSTERED'; + + /* Oracle */ + public const INDEX_BITMAP = 'BITMAP'; public const TYPE_PK = 'pk'; public const TYPE_UPK = 'upk'; @@ -47,6 +74,7 @@ interface SchemaInterface extends ConstraintSchemaInterface public const TYPE_BOOLEAN = 'boolean'; public const TYPE_MONEY = 'money'; public const TYPE_JSON = 'json'; + public const TYPE_JSONB = 'jsonb'; public const PHP_TYPE_INTEGER = 'integer'; public const PHP_TYPE_STRING = 'string'; diff --git a/tests/AbstractQueryBuilderTest.php b/tests/AbstractQueryBuilderTest.php index ab05fe4c7..f09ad5502 100644 --- a/tests/AbstractQueryBuilderTest.php +++ b/tests/AbstractQueryBuilderTest.php @@ -51,13 +51,13 @@ public function testAddColumn(): void $qb = $db->getQueryBuilder(); $schema = $db->getSchema(); - $sql = $qb->addColumn('table', 'column', $schema::TYPE_STRING); + $sql = $qb->addColumn('table', 'column', SchemaInterface::TYPE_STRING); $this->assertSame( DbHelper::replaceQuotes( <<getColumnType($schema::TYPE_STRING), + SQL . ' ' . $qb->getColumnType(SchemaInterface::TYPE_STRING), $db->getName(), ), $sql, @@ -171,13 +171,13 @@ public function testAlterColumn(): void $qb = $db->getQueryBuilder(); $schema = $db->getSchema(); - $sql = $qb->alterColumn('customer', 'email', $schema::TYPE_STRING); + $sql = $qb->alterColumn('customer', 'email', SchemaInterface::TYPE_STRING); $this->assertSame( DbHelper::replaceQuotes( <<getColumnType($schema::TYPE_STRING), + SQL . ' ' . $qb->getColumnType(SchemaInterface::TYPE_STRING), $db->getName(), ), $sql, diff --git a/tests/AbstractQueryTest.php b/tests/AbstractQueryTest.php index 0ce1b8ebf..cbbe7d49a 100644 --- a/tests/AbstractQueryTest.php +++ b/tests/AbstractQueryTest.php @@ -820,8 +820,15 @@ public function testPopulateWithIncorrectIndexByWithObject(Closure|string|null $ $rows = json_decode(json_encode($rows)); - $this->expectWarning(); + set_error_handler(static function (int $errno, string $errstr) { + throw new \Exception('E_WARNING: ' . $errstr, $errno); + }, E_WARNING); + + $this->expectExceptionMessageMatches('/^E_WARNING: /'); + $query->populate($rows); + + restore_error_handler(); } public function populateProviderWithIndexBy(): array diff --git a/tests/Common/CommonSchemaTest.php b/tests/Common/CommonSchemaTest.php index 31da7772c..4825affe8 100644 --- a/tests/Common/CommonSchemaTest.php +++ b/tests/Common/CommonSchemaTest.php @@ -17,7 +17,6 @@ use Yiisoft\Db\Exception\InvalidCallException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Schema\TableSchemaInterface; use Yiisoft\Db\Tests\AbstractSchemaTest; @@ -140,7 +139,7 @@ public function testFindUniquesIndexes(): void 'somecolUnique', 'uniqueIndex', 'somecol', - QueryBuilderInterface::INDEX_UNIQUE, + SchemaInterface::INDEX_UNIQUE, )->execute(); $tableSchema = $schema->getTableSchema('uniqueIndex', true); @@ -159,7 +158,7 @@ public function testFindUniquesIndexes(): void 'someCol2Unique', 'uniqueIndex', 'someCol2', - QueryBuilderInterface::INDEX_UNIQUE, + SchemaInterface::INDEX_UNIQUE, )->execute(); $tableSchema = $schema->getTableSchema('uniqueIndex', true); @@ -174,7 +173,7 @@ public function testFindUniquesIndexes(): void 'another unique index', 'uniqueIndex', 'someCol3', - QueryBuilderInterface::INDEX_UNIQUE, + SchemaInterface::INDEX_UNIQUE, )->execute(); $tableSchema = $schema->getTableSchema('uniqueIndex', true); diff --git a/tests/Provider/AbstractCommandProvider.php b/tests/Provider/AbstractCommandProvider.php index 5095e0bcc..fcb4b4e74 100644 --- a/tests/Provider/AbstractCommandProvider.php +++ b/tests/Provider/AbstractCommandProvider.php @@ -6,7 +6,7 @@ use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Query\Query; -use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; +use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Tests\Support\DbHelper; use Yiisoft\Db\Tests\Support\TestTrait; @@ -350,7 +350,7 @@ public function createIndex(): array { return [ ['{{test_idx_constraint_1}}', '{{test_idx}}', 'int1', null, null], - ['{{test_idx_constraint_2}}', '{{test_idx}}', ['int1'], QueryBuilderInterface::INDEX_UNIQUE, null], + ['{{test_idx_constraint_2}}', '{{test_idx}}', ['int1'], SchemaInterface::INDEX_UNIQUE, null], ['{{test_idx_constraint_3}}', '{{test_idx}}', ['int1', 'int2'], null, null], ]; } @@ -388,7 +388,7 @@ public function createIndexSql(): array '{{name}}', '{{table}}', ['column1', 'column2'], - QueryBuilderInterface::INDEX_UNIQUE, + SchemaInterface::INDEX_UNIQUE, '', DbHelper::replaceQuotes( << [ @@ -878,7 +879,7 @@ public function createIndex(): array $name2, $tableName, 'C_index_2_1, C_index_2_2', - QueryBuilderInterface::INDEX_UNIQUE, + SchemaInterface::INDEX_UNIQUE, ), ], ]; diff --git a/tests/Provider/AbstractSchemaProvider.php b/tests/Provider/AbstractSchemaProvider.php index 8e7a957fc..e29043b84 100644 --- a/tests/Provider/AbstractSchemaProvider.php +++ b/tests/Provider/AbstractSchemaProvider.php @@ -9,7 +9,6 @@ use Yiisoft\Db\Constraint\Constraint; use Yiisoft\Db\Constraint\ForeignKeyConstraint; use Yiisoft\Db\Constraint\IndexConstraint; -use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Tests\Support\AnyValue; @@ -200,7 +199,7 @@ public function withIndexDataProvider(): array { return [ [ - 'indexType' => QueryBuilderInterface::INDEX_UNIQUE, + 'indexType' => SchemaInterface::INDEX_UNIQUE, 'indexMethod' => null, 'columnType' => null, 'isPrimary' => false,