Skip to content

Commit dbcf4a9

Browse files
committed
WIP
1 parent 3d2f995 commit dbcf4a9

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ User:
390390
`NOT NULL` in DB migrations is determined by `nullable` and `required` properties of the OpenAPI schema.
391391
e.g. attribute = 'my_property'.
392392

393-
- If you define attribute neither "required" nor via "nullable", then it is by default `NULL`:
393+
- If you define attribute neither "required" nor via "nullable", then it is by default `NULL` ([opposite of OpenAPI spec](https://swagger.io/specification/v3/?sbsearch=nullable)):
394394

395395
```yaml
396396
ExampleSchema:
@@ -568,4 +568,3 @@ Professional support, consulting as well as software development services are av
568568
https://www.cebe.cc/en/contact
569569

570570
Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud).
571-

src/lib/ColumnToCode.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ private function resolve():void
345345
$fluentSize = $this->column->size ? '(' . $this->column->size . ')' : '()';
346346
$rawSize = $this->column->size ? '(' . $this->column->size . ')' : '';
347347
$this->rawParts['nullable'] = $this->column->allowNull ? 'NULL' : 'NOT NULL';
348-
$this->fluentParts['nullable'] = $this->column->allowNull === true ? 'null()' : 'notNull()';
348+
// if (!ApiGenerator::isPostgres()) {
349+
$this->fluentParts['nullable'] = $this->column->allowNull === true ? 'null()' : 'notNull()';
350+
// }
349351
if (array_key_exists($dbType, self::INT_TYPE_MAP)) {
350352
$this->fluentParts['type'] = self::INT_TYPE_MAP[$dbType] . $fluentSize;
351353
$this->rawParts['type'] =
@@ -384,6 +386,7 @@ private function getIsBuiltinType($type, $dbType)
384386
if ($this->isEnum()) {
385387
return false;
386388
}
389+
387390
if ($this->fromDb === true) {
388391
return isset(
389392
(new ColumnSchemaBuilder(''))->categoryMap[$type]

src/lib/migrations/PostgresMigrationBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ protected function buildColumnChanges(ColumnSchema $current, ColumnSchema $desir
7272
$this->migration->addDownCode($this->recordBuilder->alterColumnTypeFromDb($tableName, $current, $addUsing));
7373
}
7474
if (in_array('allowNull', $changed, true)) {
75+
// TODO if last up code contains `null()` string then do execute below statement, same for notNull() and same in down code
7576
if ($desired->allowNull === true) {
7677
$this->migration->addUpCode($this->recordBuilder->dropColumnNotNull($tableName, $desired));
7778
$this->migration->addDownCode($this->recordBuilder->setColumnNotNull($tableName, $current), true);

0 commit comments

Comments
 (0)