From 2e9d39fe72dd4316eca3286ca36b3f30019ccb0d Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Fri, 6 Sep 2024 09:20:59 +0530 Subject: [PATCH 1/8] Create PR --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1cd2090b..3bb79307 100644 --- a/README.md +++ b/README.md @@ -568,3 +568,4 @@ Professional support, consulting as well as software development services are av https://www.cebe.cc/en/contact Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud). + From 433984836b40779e61cbb9f840e12a428eef5773 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Fri, 6 Sep 2024 09:41:29 +0530 Subject: [PATCH 2/8] Fix issue of inconsistent return value --- README.md | 1 - src/lib/migrations/MysqlMigrationBuilder.php | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3bb79307..1cd2090b 100644 --- a/README.md +++ b/README.md @@ -568,4 +568,3 @@ Professional support, consulting as well as software development services are av https://www.cebe.cc/en/contact Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud). - diff --git a/src/lib/migrations/MysqlMigrationBuilder.php b/src/lib/migrations/MysqlMigrationBuilder.php index 42354df3..359c1af1 100644 --- a/src/lib/migrations/MysqlMigrationBuilder.php +++ b/src/lib/migrations/MysqlMigrationBuilder.php @@ -117,11 +117,10 @@ protected function findTableIndexes():array public static function getColumnSchemaBuilderClass(): string { - if (ApiGenerator::isMysql()) { - return \yii\db\mysql\ColumnSchemaBuilder::class; - } elseif (ApiGenerator::isMariaDb()) { + if (ApiGenerator::isMariaDb()) { return \SamIT\Yii2\MariaDb\ColumnSchemaBuilder::class; } + return \yii\db\mysql\ColumnSchemaBuilder::class; } public function modifyCurrent(ColumnSchema $current): void From f7ed24bc094c9d9f7a216e309189c564f5172628 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Fri, 6 Sep 2024 16:24:58 +0530 Subject: [PATCH 3/8] Refactor --- src/lib/ColumnToCode.php | 3 --- src/lib/migrations/MigrationRecordBuilder.php | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/ColumnToCode.php b/src/lib/ColumnToCode.php index e9a570bc..cdaef236 100644 --- a/src/lib/ColumnToCode.php +++ b/src/lib/ColumnToCode.php @@ -167,9 +167,6 @@ public function getCode(bool $quoted = false):string } if ($this->rawParts['default'] === null) { $default = ''; - } elseif (ApiGenerator::isPostgres() && $this->isEnum()) { - $default = - $this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : ''; } else { $default = $this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : ''; } diff --git a/src/lib/migrations/MigrationRecordBuilder.php b/src/lib/migrations/MigrationRecordBuilder.php index 98ee03b8..0512bbbe 100644 --- a/src/lib/migrations/MigrationRecordBuilder.php +++ b/src/lib/migrations/MigrationRecordBuilder.php @@ -227,6 +227,7 @@ public function addFk(string $fkName, string $tableAlias, string $fkCol, string $onUpdate ); } + return ''; } public function addUniqueIndex(string $tableAlias, string $indexName, array $columns):string From 9e8905ced5ada34fb3eff5e15854956a4166dcae Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Fri, 6 Sep 2024 16:26:34 +0530 Subject: [PATCH 4/8] Refactor --- src/lib/ColumnToCode.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lib/ColumnToCode.php b/src/lib/ColumnToCode.php index cdaef236..52460e49 100644 --- a/src/lib/ColumnToCode.php +++ b/src/lib/ColumnToCode.php @@ -165,12 +165,8 @@ public function getCode(bool $quoted = false):string array_unshift($parts, '$this'); return implode('->', array_filter(array_map('trim', $parts))); } - if ($this->rawParts['default'] === null) { - $default = ''; - } else { - $default = $this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : ''; - } + $default = $this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : ''; $code = $this->rawParts['type'] . ' ' . $this->rawParts['nullable'] . $default; if ((ApiGenerator::isMysql() || ApiGenerator::isMariaDb()) && $this->rawParts['position']) { $code .= ' ' . $this->rawParts['position']; From f3b3ad93183d893148cbfb1e411abd3fa8166ba0 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Fri, 6 Sep 2024 16:28:29 +0530 Subject: [PATCH 5/8] Refactor --- src/lib/ColumnToCode.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/ColumnToCode.php b/src/lib/ColumnToCode.php index 52460e49..81062b0d 100644 --- a/src/lib/ColumnToCode.php +++ b/src/lib/ColumnToCode.php @@ -166,14 +166,15 @@ public function getCode(bool $quoted = false):string return implode('->', array_filter(array_map('trim', $parts))); } + if (ApiGenerator::isPostgres() && $this->alterByXDbType) { + return $quoted ? VarDumper::export($this->rawParts['type']) : $this->rawParts['type']; + } + $default = $this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : ''; $code = $this->rawParts['type'] . ' ' . $this->rawParts['nullable'] . $default; if ((ApiGenerator::isMysql() || ApiGenerator::isMariaDb()) && $this->rawParts['position']) { $code .= ' ' . $this->rawParts['position']; } - if (ApiGenerator::isPostgres() && $this->alterByXDbType) { - return $quoted ? VarDumper::export($this->rawParts['type']) : $this->rawParts['type']; - } return $quoted ? VarDumper::export($code) : $code; } From e24d6c1efa5fe17b21c6fdaec6a4f23cb05f7422 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Fri, 6 Sep 2024 17:04:41 +0530 Subject: [PATCH 6/8] Remove redundant code --- src/lib/migrations/MysqlMigrationBuilder.php | 3 --- tests/unit/EnumTest.php | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/lib/migrations/MysqlMigrationBuilder.php b/src/lib/migrations/MysqlMigrationBuilder.php index 359c1af1..81061a98 100644 --- a/src/lib/migrations/MysqlMigrationBuilder.php +++ b/src/lib/migrations/MysqlMigrationBuilder.php @@ -29,9 +29,6 @@ protected function buildColumnChanges(ColumnSchema $current, ColumnSchema $desir foreach ($changed as $attr) { $newColumn->$attr = $desired->$attr; } - if (static::isEnum($newColumn)) { - $newColumn->dbType = 'enum'; // TODO this is concretely not correct - } $this->migration->addUpCode($this->recordBuilder->alterColumn($this->model->getTableAlias(), $newColumn)) ->addDownCode($this->recordBuilder->alterColumn($this->model->getTableAlias(), $current)); } diff --git a/tests/unit/EnumTest.php b/tests/unit/EnumTest.php index 8b48e249..46b08d45 100644 --- a/tests/unit/EnumTest.php +++ b/tests/unit/EnumTest.php @@ -168,7 +168,7 @@ public function testChangeToAndFromEnum() // edit enum to string and vice versa $this->deleteTables(); } - // TODO ENH enum change is more work than just changing the eunm values. And for PgSQL it is even more + // TODO ENH enum change is more work than just changing the enum values. And for PgSQL it is even more // public function testEnumValuesChange() // { // $this->deleteTables(); From d43368398168ec9e121ae9af76db6c6008d03b6a Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Fri, 6 Sep 2024 17:05:07 +0530 Subject: [PATCH 7/8] Present in https://github.com/cebe/yii2-openapi/issues/122 and https://github.com/php-openapi/yii2-openapi/issues/10 --- tests/unit/EnumTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/EnumTest.php b/tests/unit/EnumTest.php index 46b08d45..febc1047 100644 --- a/tests/unit/EnumTest.php +++ b/tests/unit/EnumTest.php @@ -168,7 +168,6 @@ public function testChangeToAndFromEnum() // edit enum to string and vice versa $this->deleteTables(); } - // TODO ENH enum change is more work than just changing the enum values. And for PgSQL it is even more // public function testEnumValuesChange() // { // $this->deleteTables(); From c4b4cf64c6ca22e09e5350a22c05ca4629dd1b68 Mon Sep 17 00:00:00 2001 From: Sohel Ahmed Mesaniya Date: Fri, 6 Sep 2024 17:15:19 +0530 Subject: [PATCH 8/8] Already have a task in issue --- tests/unit/EnumTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/EnumTest.php b/tests/unit/EnumTest.php index febc1047..79797d38 100644 --- a/tests/unit/EnumTest.php +++ b/tests/unit/EnumTest.php @@ -200,7 +200,6 @@ public function testChangeToAndFromEnum() // edit enum to string and vice versa // public function testChangeEnumValues() // { - // // TODO // // add a value to list // // fix a typo in a enum value present in existing list // // remove a value from list