Skip to content

Commit a6d8786

Browse files
authored
Do not generate ENUM types on postgres if x-db-type is specified for the enum column (cebe#174)
fixes cebe#173
2 parents 70a449f + 705714e commit a6d8786

File tree

45 files changed

+122
-88
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+122
-88
lines changed

Diff for: src/lib/ColumnToCode.php

+12-19
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function getCode(bool $quoted = false):string
169169
$default = '';
170170
} elseif (ApiGenerator::isPostgres() && $this->isEnum()) {
171171
$default =
172-
$this->rawParts['default'] !== null ? ' DEFAULT ' . self::escapeQuotes(trim($this->rawParts['default'])) : '';
172+
$this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : '';
173173
} else {
174174
$default = $this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : '';
175175
}
@@ -178,13 +178,10 @@ public function getCode(bool $quoted = false):string
178178
if ((ApiGenerator::isMysql() || ApiGenerator::isMariaDb()) && $this->rawParts['position']) {
179179
$code .= ' ' . $this->rawParts['position'];
180180
}
181-
if ((ApiGenerator::isMysql() || ApiGenerator::isMariaDb()) && $this->isEnum()) {
182-
return $quoted ? "'" . $code . "'" : $code;
183-
}
184181
if (ApiGenerator::isPostgres() && $this->alterByXDbType) {
185-
return $quoted ? "'" . $this->rawParts['type'] . "'" : $this->rawParts['type'];
182+
return $quoted ? VarDumper::export($this->rawParts['type']) : $this->rawParts['type'];
186183
}
187-
return $quoted ? "'" . $code . "'" : $code;
184+
return $quoted ? VarDumper::export($code) : $code;
188185
}
189186

190187
public function getAlterExpression(bool $addUsingExpression = false):string
@@ -226,7 +223,7 @@ public function isJson():bool
226223

227224
public function isEnum():bool
228225
{
229-
return !empty($this->column->enumValues);
226+
return BaseMigrationBuilder::isEnum($this->column);
230227
}
231228

232229
public function isDecimal()
@@ -313,14 +310,14 @@ public static function mysqlEnumToString(array $enum):string
313310
private function defaultValueJson(array $value):string
314311
{
315312
if ($this->alter === true) {
316-
return "'" . str_replace('"', '\"', Json::encode($value)). "'";
313+
return "'" . str_replace('"', '\"', Json::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT)) . "'";
317314
}
318-
return "\\'" . new Expression(Json::encode($value)) . "\\'";
315+
return "'" . Json::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT) . "'";
319316
}
320317

321318
private function defaultValueArray(array $value):string
322319
{
323-
return "'{" . str_replace('"', "\"", trim(Json::encode($value), '[]')) . "}'";
320+
return "'{" . trim(Json::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT), '[]') . "}'";
324321
}
325322

326323
private function resolve():void
@@ -442,10 +439,10 @@ private function resolveDefaultValue():void
442439
break;
443440
case 'object':
444441
if ($value instanceof JsonExpression) {
445-
$this->fluentParts['default'] = "defaultValue('" . Json::encode($value->getValue()) . "')";
442+
$this->fluentParts['default'] = "defaultValue('" . Json::encode($value->getValue(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT) . "')";
446443
$this->rawParts['default'] = $this->defaultValueJson($value->getValue());
447444
} elseif ($value instanceof ArrayExpression) {
448-
$this->fluentParts['default'] = "defaultValue('" . Json::encode($value->getValue()) . "')";
445+
$this->fluentParts['default'] = "defaultValue('" . Json::encode($value->getValue(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT) . "')";
449446
$this->rawParts['default'] = $this->defaultValueArray($value->getValue());
450447
} else {
451448
// $value instanceof \yii\db\Expression
@@ -454,19 +451,15 @@ private function resolveDefaultValue():void
454451
}
455452
break;
456453
case 'array':
457-
$this->fluentParts['default'] = "defaultValue('" . Json::encode($value) . "')";
454+
$this->fluentParts['default'] = "defaultValue('" . Json::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT) . "')";
458455
$this->rawParts['default'] = $this->isJson()
459456
? $this->defaultValueJson($value)
460457
: $this->defaultValueArray($value);
461458
break;
462459
default:
463460
$this->fluentParts['default'] = $expectInteger
464-
? 'defaultValue(' . $value . ')' : 'defaultValue("' . self::escapeQuotes((string)$value) . '")';
465-
$this->rawParts['default'] = $expectInteger ? $value : self::wrapQuotes($value);
466-
467-
if ((ApiGenerator::isMysql() || ApiGenerator::isMariaDb()) && $this->isEnum()) {
468-
$this->rawParts['default'] = self::escapeQuotes($this->rawParts['default']);
469-
}
461+
? 'defaultValue(' . $value . ')' : 'defaultValue(' . VarDumper::export((string)$value) . ')';
462+
$this->rawParts['default'] = $expectInteger ? $value : VarDumper::export((string)$value);
470463
}
471464
}
472465

Diff for: src/lib/migrations/BaseMigrationBuilder.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,7 @@ public function newColStr(string $tableAlias, \cebe\yii2openapi\db\ColumnSchema
479479

480480
public static function isEnum(\yii\db\ColumnSchema $columnSchema): bool
481481
{
482-
if (!empty($columnSchema->enumValues) && is_array($columnSchema->enumValues)) {
483-
return true;
484-
}
485-
return false;
482+
return !empty($columnSchema->enumValues) && is_array($columnSchema->enumValues) && empty($columnSchema->xDbType);
486483
}
487484

488485
public static function isEnumValuesChanged(

Diff for: src/lib/migrations/MigrationRecordBuilder.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function addColumn(string $tableAlias, ColumnSchema $column, ?string $pos
8888
if (is_string($column->xDbType) && !empty($column->xDbType)) {
8989
$converter = $this->columnToCode($tableAlias, $column, false, false, false, false, $position);
9090
$name = static::quote($column->name);
91-
return sprintf(self::ADD_COLUMN_RAW, $tableAlias, $name, $converter->getCode());
91+
return sprintf(self::ADD_COLUMN_RAW, $tableAlias, $name, ColumnToCode::escapeQuotes($converter->getCode()));
9292
}
9393

9494
$converter = $this->columnToCode($tableAlias, $column, false, false, false, false, $position);
@@ -103,7 +103,7 @@ public function addDbColumn(string $tableAlias, ColumnSchema $column, ?string $p
103103
if (property_exists($column, 'xDbType') && is_string($column->xDbType) && !empty($column->xDbType)) {
104104
$converter = $this->columnToCode($tableAlias, $column, true, false, false, false, $position);
105105
$name = static::quote($column->name);
106-
return sprintf(self::ADD_COLUMN_RAW, $tableAlias, $column->name, $converter->getCode());
106+
return sprintf(self::ADD_COLUMN_RAW, $tableAlias, $column->name, ColumnToCode::escapeQuotes($converter->getCode()));
107107
}
108108
$converter = $this->columnToCode($tableAlias, $column, true, false, false, false, $position);
109109
return sprintf(self::ADD_COLUMN, $tableAlias, $column->name, $converter->getCode(true));
@@ -120,7 +120,7 @@ public function alterColumn(string $tableAlias, ColumnSchema $column):string
120120
ApiGenerator::isPostgres() ? self::ALTER_COLUMN_RAW_PGSQL : self::ALTER_COLUMN_RAW,
121121
$tableAlias,
122122
$column->name,
123-
$converter->getCode()
123+
ColumnToCode::escapeQuotes($converter->getCode())
124124
);
125125
}
126126
$converter = $this->columnToCode($tableAlias, $column, true);
@@ -340,7 +340,7 @@ public static function makeString(array $codeColumns): string
340340
}
341341
}
342342

343-
$codeColumns = str_replace([PHP_EOL, "\\\'"], [PHP_EOL . self::INDENT.' ', "'"], $finalStr);
343+
$codeColumns = str_replace([PHP_EOL], [PHP_EOL . self::INDENT.' '], $finalStr);
344344
$codeColumns = trim($codeColumns);
345345
$codeColumns = '['.PHP_EOL.self::INDENT.' '.$codeColumns.PHP_EOL . self::INDENT.']';
346346
return $codeColumns;

Diff for: src/lib/migrations/PostgresMigrationBuilder.php

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ protected function createEnumMigrations():void
147147
$tableAlias = $this->model->getTableAlias();
148148
$enums = $this->model->getEnumAttributes();
149149
foreach ($enums as $attr) {
150+
if (!empty($attr->xDbType)) {
151+
// do not generate enum types when custom x-db-type is used
152+
continue;
153+
}
150154
$this->migration
151155
->addUpCode($this->recordBuilder->createEnum($tableAlias, $attr->columnName, $attr->enumValues), true)
152156
->addDownCode($this->recordBuilder->dropEnum($tableAlias, $attr->columnName), true);

Diff for: tests/migrations/m100000_000000_pgsql.php

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public function safeUp()
103103
'json3' => $this->json()->defaultValue(Json::encode(['foo' => 'bar', 'bar' => 'baz'])),
104104
'json4' => "json DEFAULT '" . new Expression(Json::encode(['ffo' => 'bar'])) . "'",
105105
'status' => '"'.$enumTypeName.'"',
106+
'status_x' => 'varchar(10)',
106107
'search' => 'tsvector'
107108
]);
108109
$columns = [

Diff for: tests/specs/blog/migrations/m200000_000001_create_table_users.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function up()
1212
'username' => $this->string(200)->notNull(),
1313
'email' => $this->string(200)->notNull(),
1414
'password' => $this->string()->notNull(),
15-
'role' => $this->string(20)->null()->defaultValue("reader"),
15+
'role' => $this->string(20)->null()->defaultValue('reader'),
1616
'flags' => $this->integer()->null()->defaultValue(0),
1717
'created_at' => $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)"),
1818
]);

Diff for: tests/specs/blog/migrations_maria_db/m200000_000001_create_table_users.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function up()
1212
'username' => $this->string(200)->notNull(),
1313
'email' => $this->string(200)->notNull(),
1414
'password' => $this->string()->notNull(),
15-
'role' => $this->string(20)->null()->defaultValue("reader"),
15+
'role' => $this->string(20)->null()->defaultValue('reader'),
1616
'flags' => $this->integer()->null()->defaultValue(0),
1717
'created_at' => $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)"),
1818
]);

Diff for: tests/specs/blog/migrations_mysql_db/m200000_000001_create_table_users.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function up()
1212
'username' => $this->string(200)->notNull(),
1313
'email' => $this->string(200)->notNull(),
1414
'password' => $this->string()->notNull(),
15-
'role' => $this->string(20)->null()->defaultValue("reader"),
15+
'role' => $this->string(20)->null()->defaultValue('reader'),
1616
'flags' => $this->integer()->null()->defaultValue(0),
1717
'created_at' => $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)"),
1818
]);

Diff for: tests/specs/blog/migrations_pgsql_db/m200000_000001_create_table_users.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function safeUp()
1212
'username' => $this->string(200)->notNull(),
1313
'email' => $this->string(200)->notNull(),
1414
'password' => $this->string()->notNull(),
15-
'role' => $this->string(20)->null()->defaultValue("reader"),
15+
'role' => $this->string(20)->null()->defaultValue('reader'),
1616
'flags' => $this->integer()->null()->defaultValue(0),
1717
'created_at' => $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)"),
1818
]);

Diff for: tests/specs/blog_v2/migrations/m200000_000005_create_table_v2_comments.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function up()
1212
'post_id' => $this->bigInteger()->notNull(),
1313
'user_id' => $this->bigInteger()->null()->defaultValue(null),
1414
'message' => $this->text()->notNull(),
15-
'meta_data' => $this->string(300)->null()->defaultValue(""),
15+
'meta_data' => $this->string(300)->null()->defaultValue(''),
1616
'created_at' => $this->timestamp()->notNull(),
1717
]);
1818
$this->addForeignKey('fk_v2_comments_post_id_v2_posts_id', '{{%v2_comments}}', 'post_id', '{{%v2_posts}}', 'id');

Diff for: tests/specs/blog_v2/migrations_maria_db/m200000_000004_change_table_v2_users.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function down()
2323
$this->dropIndex('v2_users_login_key', '{{%v2_users}}');
2424
$this->createIndex('v2_users_username_key', '{{%v2_users}}', 'username', true);
2525
$this->alterColumn('{{%v2_users}}', 'created_at', $this->timestamp()->null()->defaultExpression("current_timestamp()"));
26-
$this->alterColumn('{{%v2_users}}', 'role', $this->string(20)->null()->defaultValue("reader"));
26+
$this->alterColumn('{{%v2_users}}', 'role', $this->string(20)->null()->defaultValue('reader'));
2727
$this->alterColumn('{{%v2_users}}', 'email', $this->string(200)->notNull());
2828
$this->addColumn('{{%v2_users}}', 'username', $this->string(200)->notNull());
2929
$this->dropColumn('{{%v2_users}}', 'login');

Diff for: tests/specs/blog_v2/migrations_maria_db/m200000_000005_change_table_v2_comments.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function up()
1212
$this->addColumn('{{%v2_comments}}', 'user_id', $this->bigInteger()->null()->defaultValue(null)->after('post_id'));
1313
$this->dropColumn('{{%v2_comments}}', 'author_id');
1414
$this->alterColumn('{{%v2_comments}}', 'message', $this->text()->notNull());
15-
$this->alterColumn('{{%v2_comments}}', 'meta_data', $this->string(300)->null()->defaultValue(""));
15+
$this->alterColumn('{{%v2_comments}}', 'meta_data', $this->string(300)->null()->defaultValue(''));
1616
$this->alterColumn('{{%v2_comments}}', 'created_at', $this->timestamp()->notNull());
1717
$this->addForeignKey('fk_v2_comments_post_id_v2_posts_id', '{{%v2_comments}}', 'post_id', '{{%v2_posts}}', 'id');
1818
$this->addForeignKey('fk_v2_comments_user_id_v2_users_id', '{{%v2_comments}}', 'user_id', '{{%v2_users}}', 'id');

Diff for: tests/specs/blog_v2/migrations_mysql_db/m200000_000004_change_table_v2_users.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function down()
2323
$this->dropIndex('v2_users_login_key', '{{%v2_users}}');
2424
$this->createIndex('v2_users_username_key', '{{%v2_users}}', 'username', true);
2525
$this->alterColumn('{{%v2_users}}', 'created_at', $this->timestamp()->null()->defaultExpression("CURRENT_TIMESTAMP"));
26-
$this->alterColumn('{{%v2_users}}', 'role', $this->string(20)->null()->defaultValue("reader"));
26+
$this->alterColumn('{{%v2_users}}', 'role', $this->string(20)->null()->defaultValue('reader'));
2727
$this->alterColumn('{{%v2_users}}', 'email', $this->string(200)->notNull());
2828
$this->addColumn('{{%v2_users}}', 'username', $this->string(200)->notNull());
2929
$this->dropColumn('{{%v2_users}}', 'login');

Diff for: tests/specs/blog_v2/migrations_mysql_db/m200000_000005_change_table_v2_comments.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function up()
1212
$this->addColumn('{{%v2_comments}}', 'user_id', $this->bigInteger()->null()->defaultValue(null)->after('post_id'));
1313
$this->dropColumn('{{%v2_comments}}', 'author_id');
1414
$this->alterColumn('{{%v2_comments}}', 'message', $this->text()->notNull());
15-
$this->alterColumn('{{%v2_comments}}', 'meta_data', $this->string(300)->null()->defaultValue(""));
15+
$this->alterColumn('{{%v2_comments}}', 'meta_data', $this->string(300)->null()->defaultValue(''));
1616
$this->alterColumn('{{%v2_comments}}', 'created_at', $this->timestamp()->notNull());
1717
$this->addForeignKey('fk_v2_comments_post_id_v2_posts_id', '{{%v2_comments}}', 'post_id', '{{%v2_posts}}', 'id');
1818
$this->addForeignKey('fk_v2_comments_user_id_v2_users_id', '{{%v2_comments}}', 'user_id', '{{%v2_users}}', 'id');

Diff for: tests/specs/enum/change/maria/app/migrations_maria_db/m200000_000001_create_table_newcolumns.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public function up()
1010
$this->createTable('{{%newcolumns}}', [
1111
'id' => $this->primaryKey(),
1212
'new_column' => 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\'',
13+
0 => 'new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'',
1314
]);
1415
}
1516

Diff for: tests/specs/enum/change/mysql/app/migrations_mysql_db/m200000_000001_create_table_newcolumns.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public function up()
1010
$this->createTable('{{%newcolumns}}', [
1111
'id' => $this->primaryKey(),
1212
'new_column' => 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\'',
13+
0 => 'new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'',
1314
]);
1415
}
1516

Diff for: tests/specs/enum/change/pgsql/app/migrations_pgsql_db/m200000_000001_create_table_newcolumns.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public function safeUp()
1111
$this->createTable('{{%newcolumns}}', [
1212
'id' => $this->primaryKey(),
1313
'new_column' => '"enum_itt_newcolumns_new_column" NOT NULL DEFAULT \'ONE\'',
14+
0 => '"new_column_x" varchar(10) NOT NULL DEFAULT \'ONE\'',
1415
]);
1516
}
1617

Diff for: tests/specs/enum/fresh/maria/app/migrations_maria_db/m200000_000001_create_table_newcolumns.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public function up()
1010
$this->createTable('{{%newcolumns}}', [
1111
'id' => $this->primaryKey(),
1212
'new_column' => 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\'',
13+
0 => 'new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'',
1314
]);
1415
}
1516

Diff for: tests/specs/enum/fresh/mysql/app/migrations_mysql_db/m200000_000001_create_table_newcolumns.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public function up()
1010
$this->createTable('{{%newcolumns}}', [
1111
'id' => $this->primaryKey(),
1212
'new_column' => 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\'',
13+
0 => 'new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'',
1314
]);
1415
}
1516

Diff for: tests/specs/enum/fresh/mysql/enum.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ components:
5959
default:
6060
ONE
6161
nullable: false
62+
new_column_x:
63+
type: string
64+
enum:
65+
- ONE
66+
- TWO
67+
- THREE
68+
default:
69+
ONE
70+
x-db-type: varchar(10)
71+
nullable: false
6272

6373
Editcolumn:
6474
type: object

Diff for: tests/specs/enum/fresh/pgsql/app/migrations_pgsql_db/m200000_000001_create_table_newcolumns.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public function safeUp()
1111
$this->createTable('{{%newcolumns}}', [
1212
'id' => $this->primaryKey(),
1313
'new_column' => '"enum_itt_newcolumns_new_column" NOT NULL DEFAULT \'ONE\'',
14+
0 => '"new_column_x" varchar(10) NOT NULL DEFAULT \'ONE\'',
1415
]);
1516
}
1617

Diff for: tests/specs/enum/new_column/maria/app/migrations_maria_db/m200000_000001_change_table_newcolumns.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ class m200000_000001_change_table_newcolumns extends \yii\db\Migration
77
{
88
public function up()
99
{
10-
$this->addColumn('{{%newcolumns}}', 'new_column', 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\'');
10+
$this->addColumn('{{%newcolumns}}', 'new_column', 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\' AFTER id');
11+
$this->db->createCommand('ALTER TABLE {{%newcolumns}} ADD COLUMN new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'')->execute();
1112
$this->dropColumn('{{%newcolumns}}', 'delete_col');
1213
}
1314

1415
public function down()
1516
{
1617
$this->addColumn('{{%newcolumns}}', 'delete_col', 'enum("FOUR", "FIVE", "SIX") NULL DEFAULT NULL');
18+
$this->dropColumn('{{%newcolumns}}', 'new_column_x');
1719
$this->dropColumn('{{%newcolumns}}', 'new_column');
1820
}
1921
}

Diff for: tests/specs/enum/new_column/mysql/app/migrations_mysql_db/m200000_000001_change_table_newcolumns.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ class m200000_000001_change_table_newcolumns extends \yii\db\Migration
77
{
88
public function up()
99
{
10-
$this->addColumn('{{%newcolumns}}', 'new_column', 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\'');
10+
$this->addColumn('{{%newcolumns}}', 'new_column', 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\' AFTER id');
11+
$this->db->createCommand('ALTER TABLE {{%newcolumns}} ADD COLUMN new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'')->execute();
1112
$this->dropColumn('{{%newcolumns}}', 'delete_col');
1213
}
1314

1415
public function down()
1516
{
1617
$this->addColumn('{{%newcolumns}}', 'delete_col', 'enum("FOUR", "FIVE", "SIX") NULL DEFAULT NULL');
18+
$this->dropColumn('{{%newcolumns}}', 'new_column_x');
1719
$this->dropColumn('{{%newcolumns}}', 'new_column');
1820
}
1921
}

Diff for: tests/specs/enum/new_column/pgsql/app/migrations_pgsql_db/m200000_000001_change_table_newcolumns.php

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public function safeUp()
99
{
1010
$this->execute('CREATE TYPE "enum_itt_newcolumns_new_column" AS ENUM(\'ONE\', \'TWO\', \'THREE\')');
1111
$this->addColumn('{{%newcolumns}}', 'new_column', '"enum_itt_newcolumns_new_column" NOT NULL DEFAULT \'ONE\'');
12+
$this->db->createCommand('ALTER TABLE {{%newcolumns}} ADD COLUMN "new_column_x" varchar(10) NOT NULL DEFAULT \'ONE\'')->execute();
1213
$this->dropColumn('{{%newcolumns}}', 'delete_col');
1314
$this->execute('DROP TYPE "enum_itt_newcolumns_delete_col"');
1415
}
@@ -17,6 +18,7 @@ public function safeDown()
1718
{
1819
$this->execute('CREATE TYPE "enum_itt_newcolumns_delete_col" AS ENUM(\'FOUR\', \'FIVE\', \'SIX\')');
1920
$this->addColumn('{{%newcolumns}}', 'delete_col', '"enum_itt_newcolumns_delete_col" NULL DEFAULT NULL');
21+
$this->dropColumn('{{%newcolumns}}', 'new_column_x');
2022
$this->dropColumn('{{%newcolumns}}', 'new_column');
2123
$this->execute('DROP TYPE "enum_itt_newcolumns_new_column"');
2224
}

Diff for: tests/specs/postgres_custom.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ components:
7070
enum:
7171
- active
7272
- draft
73+
status_x:
74+
type: string
75+
default: draft
76+
enum:
77+
- active
78+
- draft
79+
x-db-type: varchar(10)
7380
search:
7481
type: string
7582
x-db-type: tsvector

0 commit comments

Comments
 (0)