Skip to content

Commit ccd2f28

Browse files
committed
Merge PR #46 branch '45-setting-dbtype-to-enum-is-not-totally-correct'
* 45-setting-dbtype-to-enum-is-not-totally-correct: Already have a task in issue Present in cebe#122 and #10 Remove redundant code Refactor Refactor Refactor Fix issue of inconsistent return value Create PR
2 parents 5b785c4 + a0b3156 commit ccd2f28

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

src/lib/ColumnToCode.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,18 @@ public function getCode(bool $quoted = false):string
220220
array_unshift($parts, '$this');
221221
return implode('->', array_filter(array_map('trim', $parts)));
222222
}
223-
if ($this->rawParts['default'] === null) {
224-
$default = '';
225-
} elseif (ApiGenerator::isPostgres() && $this->isEnum()) {
226-
$default =
227-
$this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : '';
228-
} else {
229-
$default = $this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : '';
223+
224+
if (ApiGenerator::isPostgres() && $this->alterByXDbType) {
225+
return $quoted ? VarDumper::export($this->rawParts['type']) : $this->rawParts['type'];
230226
}
231227

228+
$default = $this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : '';
232229
$code = $this->rawParts['type'] . ' ' . $this->rawParts['nullable'] . $default;
233230

234231
if ((ApiGenerator::isMysql() || ApiGenerator::isMariaDb())) {
235232
$code .= $this->rawParts['position'] ? ' ' . $this->rawParts['position'] : '';
236233
$code .= $this->rawParts['comment'] ? ' '.$this->rawParts['comment'] : '';
237234
}
238-
239-
if (ApiGenerator::isPostgres() && $this->alterByXDbType) {
240-
return $quoted ? VarDumper::export($this->rawParts['type']) : $this->rawParts['type'];
241-
}
242235
return $quoted ? VarDumper::export($code) : $code;
243236
}
244237

src/lib/migrations/MysqlMigrationBuilder.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ protected function buildColumnChanges(ColumnSchema $current, ColumnSchema $desir
3434
foreach ($changed as $attr) {
3535
$newColumn->$attr = $desired->$attr;
3636
}
37-
if (static::isEnum($newColumn)) {
38-
$newColumn->dbType = 'enum'; // TODO this is concretely not correct
39-
}
4037
$this->migration->addUpCode($this->recordBuilder->alterColumn($this->model->getTableAlias(), $newColumn, $positionDesired))
4138
->addDownCode($this->recordBuilder->alterColumn($this->model->getTableAlias(), $current, $positionCurrent));
4239
}
@@ -131,13 +128,12 @@ protected function findTableIndexes():array
131128

132129
public static function getColumnSchemaBuilderClass(): string
133130
{
134-
if (ApiGenerator::isMysql()) {
135-
return \yii\db\mysql\ColumnSchemaBuilder::class;
136-
} elseif (ApiGenerator::isMariaDb()) {
131+
if (ApiGenerator::isMariaDb()) {
137132
return \SamIT\Yii2\MariaDb\ColumnSchemaBuilder::class;
138133
} else {
139134
throw new \Exception('Unknown database');
140135
}
136+
return \yii\db\mysql\ColumnSchemaBuilder::class;
141137
}
142138

143139
public function modifyCurrent(ColumnSchema $current): void

tests/unit/EnumTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ public function testChangeToAndFromEnum() // edit enum to string and vice versa
168168
$this->deleteTables();
169169
}
170170

171-
// TODO ENH enum change is more work than just changing the eunm values. And for PgSQL it is even more
172171
// public function testEnumValuesChange()
173172
// {
174173
// $this->deleteTables();
@@ -201,7 +200,6 @@ public function testChangeToAndFromEnum() // edit enum to string and vice versa
201200

202201
// public function testChangeEnumValues()
203202
// {
204-
// // TODO
205203
// // add a value to list
206204
// // fix a typo in a enum value present in existing list
207205
// // remove a value from list

0 commit comments

Comments
 (0)