Skip to content

Commit a7288c5

Browse files
authored
Update according changes in ColumnSchemaInterface (#321)
1 parent eb4e5ef commit a7288c5

7 files changed

Lines changed: 45 additions & 60 deletions

File tree

.github/workflows/build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
COMPOSER_ROOT_VERSION: 1.0.0
2727
EXTENSIONS: pdo, pdo_sqlsrv-5.10.1
2828

29-
runs-on: ubuntu-latest
29+
runs-on: ${{ matrix.mssql.os || 'ubuntu-latest' }}
3030

3131
strategy:
3232
matrix:
@@ -42,7 +42,9 @@ jobs:
4242

4343
include:
4444
- php: 8.3
45-
mssql: { server: 2017-latest }
45+
mssql:
46+
server: 2017-latest
47+
os: ubuntu-20.04
4648
- php: 8.3
4749
mssql:
4850
server: 2019-latest

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Enh #316: Implement `ColumnFactory` class (@Tigrov)
1414
- Enh #319: Separate column type constants (@Tigrov)
1515
- Enh #320: Realize `ColumnBuilder` class (@Tigrov)
16+
- Enh #321: Update according changes in `ColumnSchemaInterface` (@Tigrov)
1617

1718
## 1.2.0 March 21, 2024
1819

src/DMLQueryBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public function insertWithReturningPks(string $table, QueryInterface|array $colu
4949
if (in_array($dbType, ['char', 'varchar', 'nchar', 'nvarchar', 'binary', 'varbinary'], true)) {
5050
$dbType .= '(MAX)';
5151
} elseif ($dbType === 'timestamp') {
52-
$dbType = $returnColumn->isAllowNull() ? 'varbinary(8)' : 'binary(8)';
52+
$dbType = $returnColumn->isNotNull() ? 'binary(8)' : 'varbinary(8)';
5353
}
5454

5555
$quotedName = $this->quoter->quoteColumnName($columnName);
56-
$createdCols[] = $quotedName . ' ' . (string) $dbType . ' ' . ($returnColumn->isAllowNull() ? 'NULL' : '');
56+
$createdCols[] = $quotedName . ' ' . (string) $dbType . ' ' . ($returnColumn->isNotNull() ? '' : 'NULL');
5757
$insertedCols[] = 'INSERTED.' . $quotedName;
5858
}
5959

src/Schema.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
* is_computed: string,
4040
* comment: null|string,
4141
* size?: int,
42-
* precision?: int,
4342
* scale?: int,
4443
* }
4544
* @psalm-type ConstraintArray = array<
@@ -364,11 +363,10 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface
364363
$dbType = $info['data_type'];
365364
/** @psalm-var ColumnArray $info */
366365
$column = $columnFactory->fromDefinition($dbType);
366+
/** @psalm-suppress DeprecatedMethod */
367367
$column->name($info['column_name']);
368-
$column->allowNull($info['is_nullable'] === 'YES');
368+
$column->notNull($info['is_nullable'] !== 'YES');
369369
$column->dbType($dbType);
370-
$column->enumValues([]); // MSSQL has only vague equivalents to enum.
371-
$column->primaryKey(false); // The primary key will be determined in the `findColumns()` method.
372370
$column->autoIncrement($info['is_identity'] === '1');
373371
$column->computed($info['is_computed'] === '1');
374372
$column->comment($info['comment'] ?? '');

tests/CommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public function testAlterColumnWithDefaultNull()
341341

342342
$fieldCol = $db->getTableSchema('column_with_constraint', true)->getColumn('field');
343343

344-
$this->assertFalse($fieldCol->isAllowNull());
344+
$this->assertTrue($fieldCol->isNotNull());
345345
$this->assertNull($fieldCol->getDefaultValue());
346346
$this->assertSame('nvarchar(40)', $fieldCol->getDbType());
347347

tests/Provider/SchemaProvider.php

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ public static function columns(): array
1919
'dbType' => 'int',
2020
'phpType' => 'int',
2121
'primaryKey' => false,
22-
'allowNull' => false,
22+
'notNull' => true,
2323
'autoIncrement' => false,
24-
'enumValues' => [],
24+
'enumValues' => null,
2525
'size' => null,
26-
'precision' => null,
2726
'scale' => null,
2827
'defaultValue' => null,
2928
],
@@ -32,11 +31,10 @@ public static function columns(): array
3231
'dbType' => 'int',
3332
'phpType' => 'int',
3433
'primaryKey' => false,
35-
'allowNull' => true,
34+
'notNull' => false,
3635
'autoIncrement' => false,
37-
'enumValues' => [],
36+
'enumValues' => null,
3837
'size' => null,
39-
'precision' => null,
4038
'scale' => null,
4139
'defaultValue' => 1,
4240
],
@@ -45,11 +43,10 @@ public static function columns(): array
4543
'dbType' => 'tinyint',
4644
'phpType' => 'int',
4745
'primaryKey' => false,
48-
'allowNull' => true,
46+
'notNull' => false,
4947
'autoIncrement' => false,
50-
'enumValues' => [],
48+
'enumValues' => null,
5149
'size' => null,
52-
'precision' => null,
5350
'scale' => null,
5451
'defaultValue' => 1,
5552
],
@@ -58,11 +55,10 @@ public static function columns(): array
5855
'dbType' => 'smallint',
5956
'phpType' => 'int',
6057
'primaryKey' => false,
61-
'allowNull' => true,
58+
'notNull' => false,
6259
'autoIncrement' => false,
63-
'enumValues' => [],
60+
'enumValues' => null,
6461
'size' => null,
65-
'precision' => null,
6662
'scale' => null,
6763
'defaultValue' => 1,
6864
],
@@ -71,11 +67,10 @@ public static function columns(): array
7167
'dbType' => 'char(100)',
7268
'phpType' => 'string',
7369
'primaryKey' => false,
74-
'allowNull' => false,
70+
'notNull' => true,
7571
'autoIncrement' => false,
76-
'enumValues' => [],
72+
'enumValues' => null,
7773
'size' => 100,
78-
'precision' => 100,
7974
'scale' => null,
8075
'defaultValue' => null,
8176
],
@@ -84,11 +79,10 @@ public static function columns(): array
8479
'dbType' => 'varchar(100)',
8580
'phpType' => 'string',
8681
'primaryKey' => false,
87-
'allowNull' => true,
82+
'notNull' => false,
8883
'autoIncrement' => false,
89-
'enumValues' => [],
84+
'enumValues' => null,
9085
'size' => 100,
91-
'precision' => 100,
9286
'scale' => null,
9387
'defaultValue' => 'something',
9488
],
@@ -97,11 +91,10 @@ public static function columns(): array
9791
'dbType' => 'text',
9892
'phpType' => 'string',
9993
'primaryKey' => false,
100-
'allowNull' => true,
94+
'notNull' => false,
10195
'autoIncrement' => false,
102-
'enumValues' => [],
96+
'enumValues' => null,
10397
'size' => null,
104-
'precision' => null,
10598
'scale' => null,
10699
'defaultValue' => null,
107100
],
@@ -110,11 +103,10 @@ public static function columns(): array
110103
'dbType' => 'decimal(4,3)',
111104
'phpType' => 'float',
112105
'primaryKey' => false,
113-
'allowNull' => false,
106+
'notNull' => true,
114107
'autoIncrement' => false,
115-
'enumValues' => [],
108+
'enumValues' => null,
116109
'size' => 4,
117-
'precision' => 4,
118110
'scale' => 3,
119111
'defaultValue' => null,
120112
],
@@ -123,11 +115,10 @@ public static function columns(): array
123115
'dbType' => 'float',
124116
'phpType' => 'float',
125117
'primaryKey' => false,
126-
'allowNull' => true,
118+
'notNull' => false,
127119
'autoIncrement' => false,
128-
'enumValues' => [],
120+
'enumValues' => null,
129121
'size' => null,
130-
'precision' => null,
131122
'scale' => null,
132123
'defaultValue' => 1.23,
133124
],
@@ -136,11 +127,10 @@ public static function columns(): array
136127
'dbType' => 'varbinary',
137128
'phpType' => 'mixed',
138129
'primaryKey' => false,
139-
'allowNull' => true,
130+
'notNull' => false,
140131
'autoIncrement' => false,
141-
'enumValues' => [],
132+
'enumValues' => null,
142133
'size' => null,
143-
'precision' => null,
144134
'scale' => null,
145135
'defaultValue' => null,
146136
],
@@ -149,11 +139,10 @@ public static function columns(): array
149139
'dbType' => 'decimal(5,2)',
150140
'phpType' => 'float',
151141
'primaryKey' => false,
152-
'allowNull' => true,
142+
'notNull' => false,
153143
'autoIncrement' => false,
154-
'enumValues' => [],
144+
'enumValues' => null,
155145
'size' => 5,
156-
'precision' => 5,
157146
'scale' => 2,
158147
'defaultValue' => 33.22,
159148
],
@@ -162,11 +151,10 @@ public static function columns(): array
162151
'dbType' => 'datetime',
163152
'phpType' => 'string',
164153
'primaryKey' => false,
165-
'allowNull' => false,
154+
'notNull' => true,
166155
'autoIncrement' => false,
167-
'enumValues' => [],
156+
'enumValues' => null,
168157
'size' => null,
169-
'precision' => null,
170158
'scale' => null,
171159
'defaultValue' => '2002-01-01 00:00:00',
172160
],
@@ -175,11 +163,10 @@ public static function columns(): array
175163
'dbType' => 'bit',
176164
'phpType' => 'bool',
177165
'primaryKey' => false,
178-
'allowNull' => false,
166+
'notNull' => true,
179167
'autoIncrement' => false,
180-
'enumValues' => [],
168+
'enumValues' => null,
181169
'size' => null,
182-
'precision' => null,
183170
'scale' => null,
184171
'defaultValue' => null,
185172
],
@@ -188,11 +175,10 @@ public static function columns(): array
188175
'dbType' => 'bit',
189176
'phpType' => 'bool',
190177
'primaryKey' => false,
191-
'allowNull' => true,
178+
'notNull' => false,
192179
'autoIncrement' => false,
193-
'enumValues' => [],
180+
'enumValues' => null,
194181
'size' => null,
195-
'precision' => null,
196182
'scale' => null,
197183
'defaultValue' => true,
198184
],
@@ -206,11 +192,10 @@ public static function columns(): array
206192
'dbType' => 'int',
207193
'phpType' => 'int',
208194
'primaryKey' => true,
209-
'allowNull' => false,
195+
'notNull' => true,
210196
'autoIncrement' => true,
211-
'enumValues' => [],
197+
'enumValues' => null,
212198
'size' => null,
213-
'precision' => null,
214199
'scale' => null,
215200
'defaultValue' => null,
216201
],
@@ -219,11 +204,10 @@ public static function columns(): array
219204
'dbType' => 'varchar(255)',
220205
'phpType' => 'string',
221206
'primaryKey' => false,
222-
'allowNull' => false,
207+
'notNull' => true,
223208
'autoIncrement' => false,
224-
'enumValues' => [],
209+
'enumValues' => null,
225210
'size' => 255,
226-
'precision' => 255,
227211
'scale' => null,
228212
'defaultValue' => null,
229213
],

tests/QueryBuilderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ public function testAlterColumnOnDb(): void
847847
$schema = $db->getTableSchema('[foo1]', true);
848848

849849
$this->assertSame('varchar(255)', $schema?->getColumn('bar')->getDbType());
850-
$this->assertSame(true, $schema?->getColumn('bar')->isAllowNull());
850+
$this->assertFalse($schema?->getColumn('bar')->isNotNull());
851851

852852
$sql = $db->getQueryBuilder()->alterColumn(
853853
'foo1',
@@ -858,7 +858,7 @@ public function testAlterColumnOnDb(): void
858858
$schema = $db->getTableSchema('[foo1]', true);
859859

860860
$this->assertSame('nvarchar(128)', $schema?->getColumn('bar')->getDbType());
861-
$this->assertSame(false, $schema?->getColumn('bar')->isAllowNull());
861+
$this->assertTrue($schema?->getColumn('bar')->isNotNull());
862862

863863
$sql = $db->getQueryBuilder()->alterColumn(
864864
'foo1',
@@ -888,7 +888,7 @@ public function testAlterColumnWithCheckConstraintOnDb(): void
888888
$db->createCommand($sql)->execute();
889889
$schema = $db->getTableSchema('[foo1]', true);
890890
$this->assertEquals('nvarchar(128)', $schema?->getColumn('bar')->getDbType());
891-
$this->assertEquals(true, $schema?->getColumn('bar')->isAllowNull());
891+
$this->assertFalse($schema?->getColumn('bar')->isNotNull());
892892

893893
$sql = "INSERT INTO [foo1]([bar]) values('abcdef')";
894894
$this->assertEquals(1, $db->createCommand($sql)->execute());

0 commit comments

Comments
 (0)