diff --git a/CHANGELOG.md b/CHANGELOG.md index 741141d..e057607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,14 +11,16 @@ - Chg #272: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov) - Enh #275: Refactor PHP type of `ColumnSchemaInterface` instances (@Tigrov) - Enh #277: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov) -- New #276: Implement `ColumnFactory` class (@Tigrov) +- New #276, #288: Implement `ColumnFactory` class (@Tigrov) - Enh #279: Separate column type constants (@Tigrov) -- New #280: Realize `ColumnBuilder` class (@Tigrov) +- New #280, #291: Realize `ColumnBuilder` class (@Tigrov) - Enh #281: Update according changes in `ColumnSchemaInterface` (@Tigrov) -- New #282: Add `ColumnDefinitionBuilder` class (@Tigrov) +- New #282, #291: Add `ColumnDefinitionBuilder` class (@Tigrov) - Bug #285: Fix `DMLQueryBuilder::insertBatch()` method (@Tigrov) - Enh #283: Refactor `Dsn` class (@Tigrov) - Enh #286: Use constructor to create columns and initialize properties (@Tigrov) +- Enh #288: Refactor `Schema::findColumns()` method (@Tigrov) +- Enh #289: Refactor `Schema::normalizeDefaultValue()` method and move it to `ColumnFactory` class (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/src/Column/ColumnBuilder.php b/src/Column/ColumnBuilder.php index 41e9457..0e5f26b 100644 --- a/src/Column/ColumnBuilder.php +++ b/src/Column/ColumnBuilder.php @@ -9,26 +9,6 @@ final class ColumnBuilder extends \Yiisoft\Db\Schema\Column\ColumnBuilder { - public static function tinyint(int|null $size = 3): ColumnSchemaInterface - { - return parent::tinyint($size); - } - - public static function smallint(int|null $size = 5): ColumnSchemaInterface - { - return parent::smallint($size); - } - - public static function integer(int|null $size = 10): ColumnSchemaInterface - { - return parent::integer($size); - } - - public static function bigint(int|null $size = 20): ColumnSchemaInterface - { - return parent::bigint($size); - } - public static function binary(int|null $size = null): ColumnSchemaInterface { return new BinaryColumnSchema(ColumnType::BINARY, size: $size); diff --git a/src/Column/ColumnDefinitionBuilder.php b/src/Column/ColumnDefinitionBuilder.php index baad503..10c5eb1 100644 --- a/src/Column/ColumnDefinitionBuilder.php +++ b/src/Column/ColumnDefinitionBuilder.php @@ -19,6 +19,10 @@ final class ColumnDefinitionBuilder extends AbstractColumnDefinitionBuilder protected const GENERATE_UUID_EXPRESSION = 'sys_guid()'; protected const TYPES_WITH_SIZE = [ + 'char', + 'nchar', + 'character', + 'varchar', 'varchar2', 'nvarchar2', 'number', @@ -27,8 +31,6 @@ final class ColumnDefinitionBuilder extends AbstractColumnDefinitionBuilder 'interval day(0) to second', 'raw', 'urowid', - 'char', - 'nchar', ]; protected const TYPES_WITH_SCALE = [ @@ -67,7 +69,7 @@ protected function getDbType(ColumnSchemaInterface $column): string $size = $column->getSize(); /** @psalm-suppress DocblockTypeContradiction */ - return match ($column->getType()) { + return $column->getDbType() ?? match ($column->getType()) { ColumnType::BOOLEAN => 'number(1)', ColumnType::BIT => match (true) { $size === null => 'number(38)', @@ -83,7 +85,7 @@ protected function getDbType(ColumnSchemaInterface $column): string ColumnType::DECIMAL => 'number(' . ($size ?? 10) . ',' . ($column->getScale() ?? 0) . ')', ColumnType::MONEY => 'number(' . ($size ?? 19) . ',' . ($column->getScale() ?? 4) . ')', ColumnType::CHAR => 'char', - ColumnType::STRING => 'varchar2', + ColumnType::STRING => 'varchar2(' . ($size ?? 255) . ')', ColumnType::TEXT => 'clob', ColumnType::BINARY => 'blob', ColumnType::UUID => 'raw(16)', @@ -91,9 +93,9 @@ protected function getDbType(ColumnSchemaInterface $column): string ColumnType::TIMESTAMP => 'timestamp', ColumnType::DATE => 'date', ColumnType::TIME => 'interval day(0) to second', - ColumnType::ARRAY => 'json', - ColumnType::STRUCTURED => 'json', - ColumnType::JSON => 'json', + ColumnType::ARRAY => 'clob', + ColumnType::STRUCTURED => 'clob', + ColumnType::JSON => 'clob', default => 'varchar2', }; } diff --git a/src/Column/ColumnFactory.php b/src/Column/ColumnFactory.php index 8916825..1411493 100644 --- a/src/Column/ColumnFactory.php +++ b/src/Column/ColumnFactory.php @@ -9,6 +9,7 @@ use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use function preg_replace; +use function rtrim; use function strtolower; final class ColumnFactory extends AbstractColumnFactory @@ -19,12 +20,13 @@ final class ColumnFactory extends AbstractColumnFactory * @link https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/Data-Types.html * * @var string[] - * - * @psalm-suppress MissingClassConstType + * @psalm-var array */ - private const TYPE_MAP = [ + protected const TYPE_MAP = [ 'char' => ColumnType::CHAR, 'nchar' => ColumnType::CHAR, + 'character' => ColumnType::CHAR, + 'varchar' => ColumnType::STRING, 'varchar2' => ColumnType::STRING, 'nvarchar2' => ColumnType::STRING, 'clob' => ColumnType::TEXT, @@ -65,21 +67,20 @@ protected function getType(string $dbType, array $info = []): string return ColumnType::STRING; } - return self::TYPE_MAP[$dbType] ?? ColumnType::STRING; + return parent::getType($dbType, $info); } - public function fromType(string $type, array $info = []): ColumnSchemaInterface + protected function getColumnClass(string $type, array $info = []): string { if ($type === ColumnType::BINARY) { - unset($info['type']); - return new BinaryColumnSchema($type, ...$info); + return BinaryColumnSchema::class; } - return parent::fromType($type, $info); + return parent::getColumnClass($type, $info); } - protected function isDbType(string $dbType): bool + protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnSchemaInterface $column): mixed { - return isset(self::TYPE_MAP[$dbType]); + return parent::normalizeNotNullDefaultValue(rtrim($defaultValue), $column); } } diff --git a/src/Schema.php b/src/Schema.php index 9060c54..b2364ea 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -7,7 +7,6 @@ use Throwable; use Yiisoft\Db\Cache\SchemaCache; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Constraint\CheckConstraint; use Yiisoft\Db\Constraint\Constraint; use Yiisoft\Db\Constraint\ForeignKeyConstraint; @@ -16,7 +15,6 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Helper\DbArrayHelper; use Yiisoft\Db\Oracle\Column\ColumnFactory; use Yiisoft\Db\Schema\Builder\ColumnInterface; @@ -30,24 +28,23 @@ use function implode; use function is_array; use function md5; -use function preg_match; use function serialize; -use function str_replace; -use function trim; /** * Implements the Oracle Server specific schema, supporting Oracle Server 11C and above. * - * @psalm-type ColumnInfoArray = array{ + * @psalm-type ColumnArray = array{ * column_name: string, * data_type: string, * data_scale: string|null, + * identity_column: string, * size: string|null, * nullable: string, * data_default: string|null, - * is_pk: string|null, - * identity_column: string, - * column_comment: string|null + * constraint_type: string|null, + * column_comment: string|null, + * schema: string, + * table: string * } * * @psalm-type ConstraintArray = array< @@ -334,6 +331,9 @@ protected function loadTableDefaultValues(string $tableName): array */ protected function findColumns(TableSchemaInterface $table): bool { + $schemaName = $table->getSchemaName(); + $tableName = $table->getName(); + $sql = << 0 THEN A.CHAR_LENGTH ELSE A.DATA_PRECISION END) AS "size", A.NULLABLE, A.DATA_DEFAULT, - ( - SELECT COUNT(*) - FROM ALL_CONSTRAINTS AC - INNER JOIN ALL_CONS_COLUMNS ACC ON ACC.CONSTRAINT_NAME=AC.CONSTRAINT_NAME - WHERE - AC.OWNER = A.OWNER - AND AC.TABLE_NAME = B.OBJECT_NAME - AND ACC.COLUMN_NAME = A.COLUMN_NAME - AND AC.CONSTRAINT_TYPE = 'P' - ) AS IS_PK, + AC.CONSTRAINT_TYPE, COM.COMMENTS AS COLUMN_COMMENT FROM ALL_TAB_COLUMNS A - INNER JOIN ALL_OBJECTS B ON B.OWNER = A.OWNER AND LTRIM(B.OBJECT_NAME) = LTRIM(A.TABLE_NAME) - LEFT JOIN ALL_COL_COMMENTS COM ON (A.OWNER = COM.OWNER AND A.TABLE_NAME = COM.TABLE_NAME AND A.COLUMN_NAME = COM.COLUMN_NAME) - WHERE - A.OWNER = :schemaName + INNER JOIN ALL_OBJECTS B + ON B.OWNER = A.OWNER + AND B.OBJECT_NAME = A.TABLE_NAME + LEFT JOIN ALL_COL_COMMENTS COM + ON COM.OWNER = A.OWNER + AND COM.TABLE_NAME = A.TABLE_NAME + AND COM.COLUMN_NAME = A.COLUMN_NAME + LEFT JOIN ALL_CONSTRAINTS AC + ON AC.OWNER = A.OWNER + AND AC.TABLE_NAME = A.TABLE_NAME + AND (AC.CONSTRAINT_TYPE = 'P' + OR AC.CONSTRAINT_TYPE = 'U' + AND ( + SELECT COUNT(*) + FROM ALL_CONS_COLUMNS UCC + WHERE UCC.CONSTRAINT_NAME = AC.CONSTRAINT_NAME + AND UCC.TABLE_NAME = AC.TABLE_NAME + AND UCC.OWNER = AC.OWNER + ) = 1 + ) + AND AC.CONSTRAINT_NAME IN ( + SELECT ACC.CONSTRAINT_NAME + FROM ALL_CONS_COLUMNS ACC + WHERE ACC.OWNER = A.OWNER + AND ACC.TABLE_NAME = A.TABLE_NAME + AND ACC.COLUMN_NAME = A.COLUMN_NAME + ) + WHERE A.OWNER = :schemaName + AND A.TABLE_NAME = :tableName AND B.OBJECT_TYPE IN ('TABLE', 'VIEW', 'MATERIALIZED VIEW') - AND B.OBJECT_NAME = :tableName ORDER BY A.COLUMN_ID SQL; $columns = $this->db->createCommand($sql, [ - ':tableName' => $table->getName(), - ':schemaName' => $table->getSchemaName(), + ':schemaName' => $schemaName, + ':tableName' => $tableName, ])->queryAll(); if ($columns === []) { @@ -375,9 +390,12 @@ protected function findColumns(TableSchemaInterface $table): bool /** @psalm-var string[][] $info */ foreach ($columns as $info) { - /** @psalm-var ColumnInfoArray $info */ $info = array_change_key_case($info); + $info['schema'] = $schemaName; + $info['table'] = $tableName; + + /** @psalm-var ColumnArray $info */ $column = $this->loadColumnSchema($info); $table->column($info['column_name'], $column); @@ -422,57 +440,23 @@ protected function getTableSequenceName(string $tableName): string|null * * @return ColumnSchemaInterface The column schema object. * - * @psalm-param ColumnInfoArray $info The column information. + * @psalm-param ColumnArray $info The column information. */ private function loadColumnSchema(array $info): ColumnSchemaInterface { - $columnFactory = $this->db->getSchema()->getColumnFactory(); - - $dbType = $info['data_type']; - $column = $columnFactory->fromDbType($dbType, [ + return $this->getColumnFactory()->fromDbType($info['data_type'], [ + 'autoIncrement' => $info['identity_column'] === 'YES', + 'comment' => $info['column_comment'], + 'defaultValueRaw' => $info['data_default'], + 'name' => $info['column_name'], + 'notNull' => $info['nullable'] !== 'Y', + 'primaryKey' => $info['constraint_type'] === 'P', 'scale' => $info['data_scale'] !== null ? (int) $info['data_scale'] : null, + 'schema' => $info['schema'], 'size' => $info['size'] !== null ? (int) $info['size'] : null, + 'table' => $info['table'], + 'unique' => $info['constraint_type'] === 'U', ]); - /** @psalm-suppress DeprecatedMethod */ - $column->name($info['column_name']); - $column->notNull($info['nullable'] !== 'Y'); - $column->comment($info['column_comment']); - $column->primaryKey((bool) $info['is_pk']); - $column->autoIncrement($info['identity_column'] === 'YES'); - $column->defaultValue($this->normalizeDefaultValue($info['data_default'], $column)); - - return $column; - } - - /** - * Converts column's default value according to {@see ColumnSchema::phpType} after retrieval from the database. - * - * @param string|null $defaultValue The default value retrieved from the database. - * @param ColumnSchemaInterface $column The column schema object. - * - * @return mixed The normalized default value. - */ - private function normalizeDefaultValue(string|null $defaultValue, ColumnSchemaInterface $column): mixed - { - if ($defaultValue === null || $column->isPrimaryKey()) { - return null; - } - - $defaultValue = trim($defaultValue); - - if ($defaultValue === 'NULL') { - return null; - } - - if ($column->getType() === ColumnType::TIMESTAMP && $defaultValue === 'CURRENT_TIMESTAMP') { - return new Expression($defaultValue); - } - - if (preg_match("/^'(.*)'$/s", $defaultValue, $matches) === 1) { - $defaultValue = str_replace("''", "'", $matches[1]); - } - - return $column->phpTypecast($defaultValue); } /** diff --git a/tests/ColumnFactoryTest.php b/tests/ColumnFactoryTest.php index 3cbaaf3..78d8e6b 100644 --- a/tests/ColumnFactoryTest.php +++ b/tests/ColumnFactoryTest.php @@ -4,6 +4,8 @@ namespace Yiisoft\Db\Oracle\Tests; +use PHPUnit\Framework\Attributes\DataProviderExternal; +use Yiisoft\Db\Oracle\Tests\Provider\ColumnFactoryProvider; use Yiisoft\Db\Oracle\Tests\Support\TestTrait; use Yiisoft\Db\Tests\AbstractColumnFactoryTest; @@ -14,13 +16,13 @@ final class ColumnFactoryTest extends AbstractColumnFactoryTest { use TestTrait; - /** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnFactoryProvider::dbTypes */ + #[DataProviderExternal(ColumnFactoryProvider::class, 'dbTypes')] public function testFromDbType(string $dbType, string $expectedType, string $expectedInstanceOf): void { parent::testFromDbType($dbType, $expectedType, $expectedInstanceOf); } - /** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnFactoryProvider::definitions */ + #[DataProviderExternal(ColumnFactoryProvider::class, 'definitions')] public function testFromDefinition( string $definition, string $expectedType, @@ -30,7 +32,7 @@ public function testFromDefinition( parent::testFromDefinition($definition, $expectedType, $expectedInstanceOf, $expectedMethodResults); } - /** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnFactoryProvider::pseudoTypes */ + #[DataProviderExternal(ColumnFactoryProvider::class, 'pseudoTypes')] public function testFromPseudoType( string $pseudoType, string $expectedType, @@ -40,9 +42,15 @@ public function testFromPseudoType( parent::testFromPseudoType($pseudoType, $expectedType, $expectedInstanceOf, $expectedMethodResults); } - /** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnFactoryProvider::types */ + #[DataProviderExternal(ColumnFactoryProvider::class, 'types')] public function testFromType(string $type, string $expectedType, string $expectedInstanceOf): void { parent::testFromType($type, $expectedType, $expectedInstanceOf); } + + #[DataProviderExternal(ColumnFactoryProvider::class, 'defaultValueRaw')] + public function testFromTypeDefaultValueRaw(string $type, string|null $defaultValueRaw, mixed $expected): void + { + parent::testFromTypeDefaultValueRaw($type, $defaultValueRaw, $expected); + } } diff --git a/tests/ColumnSchemaTest.php b/tests/ColumnSchemaTest.php index 6977bd6..ebfb9ca 100644 --- a/tests/ColumnSchemaTest.php +++ b/tests/ColumnSchemaTest.php @@ -69,7 +69,7 @@ public function testPhpTypeCast(): void $db->close(); } - public function testColumnSchemaInstance() + public function testColumnSchemaInstance(): void { $db = $this->getConnection(true); $schema = $db->getSchema(); @@ -82,18 +82,18 @@ public function testColumnSchemaInstance() } /** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnSchemaProvider::predefinedTypes */ - public function testPredefinedType(string $className, string $type, string $phpType) + public function testPredefinedType(string $className, string $type, string $phpType): void { parent::testPredefinedType($className, $type, $phpType); } /** @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnSchemaProvider::dbTypecastColumns */ - public function testDbTypecastColumns(string $className, array $values) + public function testDbTypecastColumns(string $className, array $values): void { parent::testDbTypecastColumns($className, $values); } - public function testBinaryColumnSchema() + public function testBinaryColumnSchema(): void { $binaryCol = new BinaryColumnSchema(); $binaryCol->dbType('BLOB'); @@ -104,4 +104,16 @@ public function testBinaryColumnSchema() $binaryCol->dbTypecast(new Param("\x10\x11\x12", PDO::PARAM_LOB)), ); } + + public function testUniqueColumn(): void + { + $db = $this->getConnection(true); + $schema = $db->getSchema(); + + $this->assertTrue($schema->getTableSchema('T_constraints_1')?->getColumn('C_unique')->isUnique()); + $this->assertFalse($schema->getTableSchema('T_constraints_2')?->getColumn('C_index_2_1')->isUnique()); + $this->assertFalse($schema->getTableSchema('T_constraints_2')?->getColumn('C_index_2_2')->isUnique()); + $this->assertTrue($schema->getTableSchema('T_upsert')?->getColumn('email')->isUnique()); + $this->assertFalse($schema->getTableSchema('T_upsert')?->getColumn('recovery_email')->isUnique()); + } } diff --git a/tests/Provider/ColumnBuilderProvider.php b/tests/Provider/ColumnBuilderProvider.php index 41bbb5e..a846cde 100644 --- a/tests/Provider/ColumnBuilderProvider.php +++ b/tests/Provider/ColumnBuilderProvider.php @@ -12,16 +12,6 @@ public static function buildingMethods(): array { $values = parent::buildingMethods(); - $values['primaryKey()'][4]['getSize'] = 10; - $values['primaryKey(false)'][4]['getSize'] = 10; - $values['smallPrimaryKey()'][4]['getSize'] = 5; - $values['smallPrimaryKey(false)'][4]['getSize'] = 5; - $values['bigPrimaryKey()'][4]['getSize'] = 20; - $values['bigPrimaryKey(false)'][4]['getSize'] = 20; - $values['tinyint()'][4]['getSize'] = 3; - $values['smallint()'][4]['getSize'] = 5; - $values['integer()'][4]['getSize'] = 10; - $values['bigint()'][4]['getSize'] = 20; $values['binary()'][2] = BinaryColumnSchema::class; $values['binary(8)'][2] = BinaryColumnSchema::class; diff --git a/tests/Provider/ColumnFactoryProvider.php b/tests/Provider/ColumnFactoryProvider.php index 88731d4..f087085 100644 --- a/tests/Provider/ColumnFactoryProvider.php +++ b/tests/Provider/ColumnFactoryProvider.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Oracle\Tests\Provider; use Yiisoft\Db\Constant\ColumnType; +use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Oracle\Column\BinaryColumnSchema; use Yiisoft\Db\Schema\Column\DoubleColumnSchema; use Yiisoft\Db\Schema\Column\StringColumnSchema; @@ -53,4 +54,16 @@ public static function definitions(): array return $definitions; } + + public static function defaultValueRaw(): array + { + $defaultValueRaw = parent::defaultValueRaw(); + + $defaultValueRaw[] = [ColumnType::STRING, 'NULL ', null]; + $defaultValueRaw[] = [ColumnType::STRING, "'str''ing' ", "str'ing"]; + $defaultValueRaw[] = [ColumnType::INTEGER, '-1 ', -1]; + $defaultValueRaw[] = [ColumnType::TIMESTAMP, 'now() ', new Expression('now()')]; + + return $defaultValueRaw; + } } diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 2201d39..95da6dc 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -248,7 +248,7 @@ public static function buildColumnDefinition(): array $values[PseudoType::UBIGPK][0] = 'number(20) GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY'; $values[PseudoType::UUID_PK][0] = 'raw(16) DEFAULT sys_guid() PRIMARY KEY'; $values[PseudoType::UUID_PK_SEQ][0] = 'raw(16) DEFAULT sys_guid() PRIMARY KEY'; - $values['STRING'][0] = 'varchar2'; + $values['STRING'][0] = 'varchar2(255)'; $values['STRING(100)'][0] = 'varchar2(100)'; $values['primaryKey()'][0] = 'number(10) GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY'; $values['primaryKey(false)'][0] = 'number(10) PRIMARY KEY'; @@ -263,7 +263,7 @@ public static function buildColumnDefinition(): array $values['bit()'][0] = 'number(38)'; $values['bit(1)'][0] = 'number(1)'; $values['bit(8)'][0] = 'number(3)'; - $values['bit(1000)'][0] = 'raw(125)'; + $values['bit(64)'][0] = 'number(20)'; $values['tinyint()'][0] = 'number(3)'; $values['tinyint(2)'][0] = 'number(2)'; $values['smallint()'][0] = 'number(5)'; @@ -288,7 +288,7 @@ public static function buildColumnDefinition(): array $values['money(null)'][0] = 'number(19,4)'; $values['string()'][0] = 'varchar2(255)'; $values['string(100)'][0] = 'varchar2(100)'; - $values['string(null)'][0] = 'varchar2'; + $values['string(null)'][0] = 'varchar2(255)'; $values['text()'][0] = 'clob'; $values['text(1000)'][0] = 'clob'; $values['binary()'][0] = 'blob'; @@ -300,21 +300,28 @@ public static function buildColumnDefinition(): array $values['time()'][0] = 'interval day(0) to second(0)'; $values['time(6)'][0] = 'interval day(0) to second(6)'; $values['time(null)'][0] = 'interval day(0) to second'; + $values['array()'][0] = 'clob'; + $values['structured()'][0] = 'clob'; + $values["structured('json')"] = ['blob', ColumnBuilder::structured('blob')]; + $values['json()'][0] = 'clob'; + $values['json(100)'][0] = 'clob'; + $values["extra('NOT NULL')"][0] = 'varchar2(255) NOT NULL'; + $values["extra('')"][0] = 'varchar2(255)'; + $values["check('value > 5')"][0] = 'number(10) CHECK ("col_59" > 5)'; + $values["check('')"][0] = 'number(10)'; + $values['check(null)'][0] = 'number(10)'; $values["comment('comment')"][0] = 'varchar2(255)'; $values["comment('')"][0] = 'varchar2(255)'; $values['comment(null)'][0] = 'varchar2(255)'; - $values["extra('bar')"][0] = 'varchar2(255) bar'; - $values["extra('')"][0] = 'varchar2(255)'; - $values["check('value > 5')"][0] = 'varchar2(255) CHECK (value > 5)'; - $values["check('')"][0] = 'varchar2(255)'; - $values['check(null)'][0] = 'varchar2(255)'; $values["defaultValue('value')"][0] = "varchar2(255) DEFAULT 'value'"; $values["defaultValue('')"][0] = "varchar2(255) DEFAULT ''"; - $values['defaultValue(null)'][0] = 'varchar2(255)'; - $values['defaultValue($expression)'][0] = 'varchar2(255) DEFAULT expression'; + $values['defaultValue(null)'][0] = 'varchar2(255) DEFAULT NULL'; + $values['defaultValue($expression)'][0] = 'number(10) DEFAULT (1 + 2)'; + $values['notNull()->defaultValue(null)'][0] = 'varchar2(255) NOT NULL'; $values['notNull()'][0] = 'varchar2(255) NOT NULL'; + $values['null()'][0] = 'varchar2(255) NULL'; $values['integer()->primaryKey()'][0] = 'number(10) PRIMARY KEY'; - $values["integer()->defaultValue('')"][0] = 'number(10)'; + $values["integer()->defaultValue('')"][0] = 'number(10) DEFAULT NULL'; $values['size(10)'][0] = 'varchar2(10)'; $values['unique()'][0] = 'varchar2(255) UNIQUE'; $values['unsigned()'][0] = 'number(10)'; diff --git a/tests/Provider/SchemaProvider.php b/tests/Provider/SchemaProvider.php index ab426a0..8a406d8 100644 --- a/tests/Provider/SchemaProvider.php +++ b/tests/Provider/SchemaProvider.php @@ -169,7 +169,7 @@ public static function columns(): array 'enumValues' => null, 'size' => null, 'scale' => 6, - 'defaultValue' => "to_timestamp('2002-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')", + 'defaultValue' => new Expression("to_timestamp('2002-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')"), ], 'time_col' => [ 'type' => 'time', @@ -181,7 +181,7 @@ public static function columns(): array 'enumValues' => null, 'size' => 0, 'scale' => 0, - 'defaultValue' => "INTERVAL '0 10:33:21' DAY(0) TO SECOND(0)", + 'defaultValue' => new Expression("INTERVAL '0 10:33:21' DAY(0) TO SECOND(0)"), ], 'interval_day_col' => [ 'type' => 'string', @@ -193,7 +193,7 @@ public static function columns(): array 'enumValues' => null, 'size' => 1, 'scale' => 0, - 'defaultValue' => "INTERVAL '2 04:56:12' DAY(1) TO SECOND(0)", + 'defaultValue' => new Expression("INTERVAL '2 04:56:12' DAY(1) TO SECOND(0)"), ], 'bool_col' => [ 'type' => 'char', @@ -278,15 +278,6 @@ public static function columns(): array ]; } - public static function columnsTypeChar(): array - { - return [ - ['char_col', 'char', 100, 'CHAR'], - ['char_col2', 'string', 100, 'VARCHAR2'], - ['char_col3', 'string', 4000, 'VARCHAR2'], - ]; - } - public static function constraints(): array { $constraints = parent::constraints(); diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 40e909d..a95e978 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -81,18 +81,6 @@ public function testGetSchemaDefaultValues(): void parent::testGetSchemaDefaultValues(); } - /** - * @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\SchemaProvider::columnsTypeChar - */ - public function testGetStringFieldsSize( - string $columnName, - string $columnType, - int|null $columnSize, - string $columnDbType - ): void { - parent::testGetStringFieldsSize($columnName, $columnType, $columnSize, $columnDbType); - } - /** * @throws Exception * @throws InvalidConfigException