diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b1de761f..66adb433 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: COMPOSER_ROOT_VERSION: 1.0.0 EXTENSIONS: pdo, pdo_sqlsrv-5.10.1 - runs-on: ubuntu-latest + runs-on: ${{ matrix.mssql.os || 'ubuntu-latest' }} strategy: matrix: @@ -42,7 +42,9 @@ jobs: include: - php: 8.3 - mssql: { server: 2017-latest } + mssql: + server: 2017-latest + os: ubuntu-20.04 - php: 8.3 mssql: server: 2019-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 49c8f4ab..3ab08350 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Enh #316: Implement `ColumnFactory` class (@Tigrov) - Enh #319: Separate column type constants (@Tigrov) - Enh #320: Realize `ColumnBuilder` class (@Tigrov) +- Enh #321: Update according changes in `ColumnSchemaInterface` (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/DMLQueryBuilder.php b/src/DMLQueryBuilder.php index 732a3506..c8ee2e37 100644 --- a/src/DMLQueryBuilder.php +++ b/src/DMLQueryBuilder.php @@ -49,11 +49,11 @@ public function insertWithReturningPks(string $table, QueryInterface|array $colu if (in_array($dbType, ['char', 'varchar', 'nchar', 'nvarchar', 'binary', 'varbinary'], true)) { $dbType .= '(MAX)'; } elseif ($dbType === 'timestamp') { - $dbType = $returnColumn->isAllowNull() ? 'varbinary(8)' : 'binary(8)'; + $dbType = $returnColumn->isNotNull() ? 'binary(8)' : 'varbinary(8)'; } $quotedName = $this->quoter->quoteColumnName($columnName); - $createdCols[] = $quotedName . ' ' . (string) $dbType . ' ' . ($returnColumn->isAllowNull() ? 'NULL' : ''); + $createdCols[] = $quotedName . ' ' . (string) $dbType . ' ' . ($returnColumn->isNotNull() ? '' : 'NULL'); $insertedCols[] = 'INSERTED.' . $quotedName; } diff --git a/src/Schema.php b/src/Schema.php index fadea8bc..46ca44b2 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -39,7 +39,6 @@ * is_computed: string, * comment: null|string, * size?: int, - * precision?: int, * scale?: int, * } * @psalm-type ConstraintArray = array< @@ -364,11 +363,10 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface $dbType = $info['data_type']; /** @psalm-var ColumnArray $info */ $column = $columnFactory->fromDefinition($dbType); + /** @psalm-suppress DeprecatedMethod */ $column->name($info['column_name']); - $column->allowNull($info['is_nullable'] === 'YES'); + $column->notNull($info['is_nullable'] !== 'YES'); $column->dbType($dbType); - $column->enumValues([]); // MSSQL has only vague equivalents to enum. - $column->primaryKey(false); // The primary key will be determined in the `findColumns()` method. $column->autoIncrement($info['is_identity'] === '1'); $column->computed($info['is_computed'] === '1'); $column->comment($info['comment'] ?? ''); diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 13a2d037..607c632d 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -341,7 +341,7 @@ public function testAlterColumnWithDefaultNull() $fieldCol = $db->getTableSchema('column_with_constraint', true)->getColumn('field'); - $this->assertFalse($fieldCol->isAllowNull()); + $this->assertTrue($fieldCol->isNotNull()); $this->assertNull($fieldCol->getDefaultValue()); $this->assertSame('nvarchar(40)', $fieldCol->getDbType()); diff --git a/tests/Provider/SchemaProvider.php b/tests/Provider/SchemaProvider.php index cf38b620..d53db017 100644 --- a/tests/Provider/SchemaProvider.php +++ b/tests/Provider/SchemaProvider.php @@ -19,11 +19,10 @@ public static function columns(): array 'dbType' => 'int', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -32,11 +31,10 @@ public static function columns(): array 'dbType' => 'int', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => 1, ], @@ -45,11 +43,10 @@ public static function columns(): array 'dbType' => 'tinyint', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => 1, ], @@ -58,11 +55,10 @@ public static function columns(): array 'dbType' => 'smallint', 'phpType' => 'int', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => 1, ], @@ -71,11 +67,10 @@ public static function columns(): array 'dbType' => 'char(100)', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => 100, - 'precision' => 100, 'scale' => null, 'defaultValue' => null, ], @@ -84,11 +79,10 @@ public static function columns(): array 'dbType' => 'varchar(100)', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => 100, - 'precision' => 100, 'scale' => null, 'defaultValue' => 'something', ], @@ -97,11 +91,10 @@ public static function columns(): array 'dbType' => 'text', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -110,11 +103,10 @@ public static function columns(): array 'dbType' => 'decimal(4,3)', 'phpType' => 'float', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => 4, - 'precision' => 4, 'scale' => 3, 'defaultValue' => null, ], @@ -123,11 +115,10 @@ public static function columns(): array 'dbType' => 'float', 'phpType' => 'float', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => 1.23, ], @@ -136,11 +127,10 @@ public static function columns(): array 'dbType' => 'varbinary', 'phpType' => 'mixed', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -149,11 +139,10 @@ public static function columns(): array 'dbType' => 'decimal(5,2)', 'phpType' => 'float', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => 5, - 'precision' => 5, 'scale' => 2, 'defaultValue' => 33.22, ], @@ -162,11 +151,10 @@ public static function columns(): array 'dbType' => 'datetime', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => '2002-01-01 00:00:00', ], @@ -175,11 +163,10 @@ public static function columns(): array 'dbType' => 'bit', 'phpType' => 'bool', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -188,11 +175,10 @@ public static function columns(): array 'dbType' => 'bit', 'phpType' => 'bool', 'primaryKey' => false, - 'allowNull' => true, + 'notNull' => false, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => true, ], @@ -206,11 +192,10 @@ public static function columns(): array 'dbType' => 'int', 'phpType' => 'int', 'primaryKey' => true, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => true, - 'enumValues' => [], + 'enumValues' => null, 'size' => null, - 'precision' => null, 'scale' => null, 'defaultValue' => null, ], @@ -219,11 +204,10 @@ public static function columns(): array 'dbType' => 'varchar(255)', 'phpType' => 'string', 'primaryKey' => false, - 'allowNull' => false, + 'notNull' => true, 'autoIncrement' => false, - 'enumValues' => [], + 'enumValues' => null, 'size' => 255, - 'precision' => 255, 'scale' => null, 'defaultValue' => null, ], diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index ea8e9f97..3015dc32 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -847,7 +847,7 @@ public function testAlterColumnOnDb(): void $schema = $db->getTableSchema('[foo1]', true); $this->assertSame('varchar(255)', $schema?->getColumn('bar')->getDbType()); - $this->assertSame(true, $schema?->getColumn('bar')->isAllowNull()); + $this->assertFalse($schema?->getColumn('bar')->isNotNull()); $sql = $db->getQueryBuilder()->alterColumn( 'foo1', @@ -858,7 +858,7 @@ public function testAlterColumnOnDb(): void $schema = $db->getTableSchema('[foo1]', true); $this->assertSame('nvarchar(128)', $schema?->getColumn('bar')->getDbType()); - $this->assertSame(false, $schema?->getColumn('bar')->isAllowNull()); + $this->assertTrue($schema?->getColumn('bar')->isNotNull()); $sql = $db->getQueryBuilder()->alterColumn( 'foo1', @@ -888,7 +888,7 @@ public function testAlterColumnWithCheckConstraintOnDb(): void $db->createCommand($sql)->execute(); $schema = $db->getTableSchema('[foo1]', true); $this->assertEquals('nvarchar(128)', $schema?->getColumn('bar')->getDbType()); - $this->assertEquals(true, $schema?->getColumn('bar')->isAllowNull()); + $this->assertFalse($schema?->getColumn('bar')->isNotNull()); $sql = "INSERT INTO [foo1]([bar]) values('abcdef')"; $this->assertEquals(1, $db->createCommand($sql)->execute());