diff --git a/src/lib/ColumnToCode.php b/src/lib/ColumnToCode.php index fb4f8748..e9a570bc 100644 --- a/src/lib/ColumnToCode.php +++ b/src/lib/ColumnToCode.php @@ -169,7 +169,7 @@ public function getCode(bool $quoted = false):string $default = ''; } elseif (ApiGenerator::isPostgres() && $this->isEnum()) { $default = - $this->rawParts['default'] !== null ? ' DEFAULT ' . self::escapeQuotes(trim($this->rawParts['default'])) : ''; + $this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : ''; } else { $default = $this->rawParts['default'] !== null ? ' DEFAULT ' . trim($this->rawParts['default']) : ''; } @@ -178,13 +178,10 @@ public function getCode(bool $quoted = false):string if ((ApiGenerator::isMysql() || ApiGenerator::isMariaDb()) && $this->rawParts['position']) { $code .= ' ' . $this->rawParts['position']; } - if ((ApiGenerator::isMysql() || ApiGenerator::isMariaDb()) && $this->isEnum()) { - return $quoted ? "'" . $code . "'" : $code; - } if (ApiGenerator::isPostgres() && $this->alterByXDbType) { - return $quoted ? "'" . $this->rawParts['type'] . "'" : $this->rawParts['type']; + return $quoted ? VarDumper::export($this->rawParts['type']) : $this->rawParts['type']; } - return $quoted ? "'" . $code . "'" : $code; + return $quoted ? VarDumper::export($code) : $code; } public function getAlterExpression(bool $addUsingExpression = false):string @@ -226,7 +223,7 @@ public function isJson():bool public function isEnum():bool { - return !empty($this->column->enumValues); + return BaseMigrationBuilder::isEnum($this->column); } public function isDecimal() @@ -313,14 +310,14 @@ public static function mysqlEnumToString(array $enum):string private function defaultValueJson(array $value):string { if ($this->alter === true) { - return "'" . str_replace('"', '\"', Json::encode($value)). "'"; + return "'" . str_replace('"', '\"', Json::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT)) . "'"; } - return "\\'" . new Expression(Json::encode($value)) . "\\'"; + return "'" . Json::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT) . "'"; } private function defaultValueArray(array $value):string { - return "'{" . str_replace('"', "\"", trim(Json::encode($value), '[]')) . "}'"; + return "'{" . trim(Json::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT), '[]') . "}'"; } private function resolve():void @@ -442,10 +439,10 @@ private function resolveDefaultValue():void break; case 'object': if ($value instanceof JsonExpression) { - $this->fluentParts['default'] = "defaultValue('" . Json::encode($value->getValue()) . "')"; + $this->fluentParts['default'] = "defaultValue('" . Json::encode($value->getValue(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT) . "')"; $this->rawParts['default'] = $this->defaultValueJson($value->getValue()); } elseif ($value instanceof ArrayExpression) { - $this->fluentParts['default'] = "defaultValue('" . Json::encode($value->getValue()) . "')"; + $this->fluentParts['default'] = "defaultValue('" . Json::encode($value->getValue(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT) . "')"; $this->rawParts['default'] = $this->defaultValueArray($value->getValue()); } else { // $value instanceof \yii\db\Expression @@ -454,19 +451,15 @@ private function resolveDefaultValue():void } break; case 'array': - $this->fluentParts['default'] = "defaultValue('" . Json::encode($value) . "')"; + $this->fluentParts['default'] = "defaultValue('" . Json::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT) . "')"; $this->rawParts['default'] = $this->isJson() ? $this->defaultValueJson($value) : $this->defaultValueArray($value); break; default: $this->fluentParts['default'] = $expectInteger - ? 'defaultValue(' . $value . ')' : 'defaultValue("' . self::escapeQuotes((string)$value) . '")'; - $this->rawParts['default'] = $expectInteger ? $value : self::wrapQuotes($value); - - if ((ApiGenerator::isMysql() || ApiGenerator::isMariaDb()) && $this->isEnum()) { - $this->rawParts['default'] = self::escapeQuotes($this->rawParts['default']); - } + ? 'defaultValue(' . $value . ')' : 'defaultValue(' . VarDumper::export((string)$value) . ')'; + $this->rawParts['default'] = $expectInteger ? $value : VarDumper::export((string)$value); } } diff --git a/src/lib/migrations/BaseMigrationBuilder.php b/src/lib/migrations/BaseMigrationBuilder.php index 39985f85..d4c49c21 100644 --- a/src/lib/migrations/BaseMigrationBuilder.php +++ b/src/lib/migrations/BaseMigrationBuilder.php @@ -479,10 +479,7 @@ public function newColStr(string $tableAlias, \cebe\yii2openapi\db\ColumnSchema public static function isEnum(\yii\db\ColumnSchema $columnSchema): bool { - if (!empty($columnSchema->enumValues) && is_array($columnSchema->enumValues)) { - return true; - } - return false; + return !empty($columnSchema->enumValues) && is_array($columnSchema->enumValues) && empty($columnSchema->xDbType); } public static function isEnumValuesChanged( diff --git a/src/lib/migrations/MigrationRecordBuilder.php b/src/lib/migrations/MigrationRecordBuilder.php index 420cb25b..98ee03b8 100644 --- a/src/lib/migrations/MigrationRecordBuilder.php +++ b/src/lib/migrations/MigrationRecordBuilder.php @@ -88,7 +88,7 @@ public function addColumn(string $tableAlias, ColumnSchema $column, ?string $pos if (is_string($column->xDbType) && !empty($column->xDbType)) { $converter = $this->columnToCode($tableAlias, $column, false, false, false, false, $position); $name = static::quote($column->name); - return sprintf(self::ADD_COLUMN_RAW, $tableAlias, $name, $converter->getCode()); + return sprintf(self::ADD_COLUMN_RAW, $tableAlias, $name, ColumnToCode::escapeQuotes($converter->getCode())); } $converter = $this->columnToCode($tableAlias, $column, false, false, false, false, $position); @@ -103,7 +103,7 @@ public function addDbColumn(string $tableAlias, ColumnSchema $column, ?string $p if (property_exists($column, 'xDbType') && is_string($column->xDbType) && !empty($column->xDbType)) { $converter = $this->columnToCode($tableAlias, $column, true, false, false, false, $position); $name = static::quote($column->name); - return sprintf(self::ADD_COLUMN_RAW, $tableAlias, $column->name, $converter->getCode()); + return sprintf(self::ADD_COLUMN_RAW, $tableAlias, $column->name, ColumnToCode::escapeQuotes($converter->getCode())); } $converter = $this->columnToCode($tableAlias, $column, true, false, false, false, $position); return sprintf(self::ADD_COLUMN, $tableAlias, $column->name, $converter->getCode(true)); @@ -120,7 +120,7 @@ public function alterColumn(string $tableAlias, ColumnSchema $column):string ApiGenerator::isPostgres() ? self::ALTER_COLUMN_RAW_PGSQL : self::ALTER_COLUMN_RAW, $tableAlias, $column->name, - $converter->getCode() + ColumnToCode::escapeQuotes($converter->getCode()) ); } $converter = $this->columnToCode($tableAlias, $column, true); @@ -340,7 +340,7 @@ public static function makeString(array $codeColumns): string } } - $codeColumns = str_replace([PHP_EOL, "\\\'"], [PHP_EOL . self::INDENT.' ', "'"], $finalStr); + $codeColumns = str_replace([PHP_EOL], [PHP_EOL . self::INDENT.' '], $finalStr); $codeColumns = trim($codeColumns); $codeColumns = '['.PHP_EOL.self::INDENT.' '.$codeColumns.PHP_EOL . self::INDENT.']'; return $codeColumns; diff --git a/src/lib/migrations/PostgresMigrationBuilder.php b/src/lib/migrations/PostgresMigrationBuilder.php index 01a1cbfd..b8c9324d 100644 --- a/src/lib/migrations/PostgresMigrationBuilder.php +++ b/src/lib/migrations/PostgresMigrationBuilder.php @@ -147,6 +147,10 @@ protected function createEnumMigrations():void $tableAlias = $this->model->getTableAlias(); $enums = $this->model->getEnumAttributes(); foreach ($enums as $attr) { + if (!empty($attr->xDbType)) { + // do not generate enum types when custom x-db-type is used + continue; + } $this->migration ->addUpCode($this->recordBuilder->createEnum($tableAlias, $attr->columnName, $attr->enumValues), true) ->addDownCode($this->recordBuilder->dropEnum($tableAlias, $attr->columnName), true); diff --git a/tests/migrations/m100000_000000_pgsql.php b/tests/migrations/m100000_000000_pgsql.php index a200fbef..c4abf80a 100644 --- a/tests/migrations/m100000_000000_pgsql.php +++ b/tests/migrations/m100000_000000_pgsql.php @@ -103,6 +103,7 @@ public function safeUp() 'json3' => $this->json()->defaultValue(Json::encode(['foo' => 'bar', 'bar' => 'baz'])), 'json4' => "json DEFAULT '" . new Expression(Json::encode(['ffo' => 'bar'])) . "'", 'status' => '"'.$enumTypeName.'"', + 'status_x' => 'varchar(10)', 'search' => 'tsvector' ]); $columns = [ diff --git a/tests/specs/blog/migrations/m200000_000001_create_table_users.php b/tests/specs/blog/migrations/m200000_000001_create_table_users.php index 22583a78..a90792e9 100644 --- a/tests/specs/blog/migrations/m200000_000001_create_table_users.php +++ b/tests/specs/blog/migrations/m200000_000001_create_table_users.php @@ -12,7 +12,7 @@ public function up() 'username' => $this->string(200)->notNull(), 'email' => $this->string(200)->notNull(), 'password' => $this->string()->notNull(), - 'role' => $this->string(20)->null()->defaultValue("reader"), + 'role' => $this->string(20)->null()->defaultValue('reader'), 'flags' => $this->integer()->null()->defaultValue(0), 'created_at' => $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)"), ]); diff --git a/tests/specs/blog/migrations_maria_db/m200000_000001_create_table_users.php b/tests/specs/blog/migrations_maria_db/m200000_000001_create_table_users.php index 22583a78..a90792e9 100644 --- a/tests/specs/blog/migrations_maria_db/m200000_000001_create_table_users.php +++ b/tests/specs/blog/migrations_maria_db/m200000_000001_create_table_users.php @@ -12,7 +12,7 @@ public function up() 'username' => $this->string(200)->notNull(), 'email' => $this->string(200)->notNull(), 'password' => $this->string()->notNull(), - 'role' => $this->string(20)->null()->defaultValue("reader"), + 'role' => $this->string(20)->null()->defaultValue('reader'), 'flags' => $this->integer()->null()->defaultValue(0), 'created_at' => $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)"), ]); diff --git a/tests/specs/blog/migrations_mysql_db/m200000_000001_create_table_users.php b/tests/specs/blog/migrations_mysql_db/m200000_000001_create_table_users.php index 22583a78..a90792e9 100644 --- a/tests/specs/blog/migrations_mysql_db/m200000_000001_create_table_users.php +++ b/tests/specs/blog/migrations_mysql_db/m200000_000001_create_table_users.php @@ -12,7 +12,7 @@ public function up() 'username' => $this->string(200)->notNull(), 'email' => $this->string(200)->notNull(), 'password' => $this->string()->notNull(), - 'role' => $this->string(20)->null()->defaultValue("reader"), + 'role' => $this->string(20)->null()->defaultValue('reader'), 'flags' => $this->integer()->null()->defaultValue(0), 'created_at' => $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)"), ]); diff --git a/tests/specs/blog/migrations_pgsql_db/m200000_000001_create_table_users.php b/tests/specs/blog/migrations_pgsql_db/m200000_000001_create_table_users.php index b845e46e..e2bc0165 100644 --- a/tests/specs/blog/migrations_pgsql_db/m200000_000001_create_table_users.php +++ b/tests/specs/blog/migrations_pgsql_db/m200000_000001_create_table_users.php @@ -12,7 +12,7 @@ public function safeUp() 'username' => $this->string(200)->notNull(), 'email' => $this->string(200)->notNull(), 'password' => $this->string()->notNull(), - 'role' => $this->string(20)->null()->defaultValue("reader"), + 'role' => $this->string(20)->null()->defaultValue('reader'), 'flags' => $this->integer()->null()->defaultValue(0), 'created_at' => $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)"), ]); diff --git a/tests/specs/blog_v2/migrations/m200000_000005_create_table_v2_comments.php b/tests/specs/blog_v2/migrations/m200000_000005_create_table_v2_comments.php index a9a0a74b..679a98a4 100644 --- a/tests/specs/blog_v2/migrations/m200000_000005_create_table_v2_comments.php +++ b/tests/specs/blog_v2/migrations/m200000_000005_create_table_v2_comments.php @@ -12,7 +12,7 @@ public function up() 'post_id' => $this->bigInteger()->notNull(), 'user_id' => $this->bigInteger()->null()->defaultValue(null), 'message' => $this->text()->notNull(), - 'meta_data' => $this->string(300)->null()->defaultValue(""), + 'meta_data' => $this->string(300)->null()->defaultValue(''), 'created_at' => $this->timestamp()->notNull(), ]); $this->addForeignKey('fk_v2_comments_post_id_v2_posts_id', '{{%v2_comments}}', 'post_id', '{{%v2_posts}}', 'id'); diff --git a/tests/specs/blog_v2/migrations_maria_db/m200000_000004_change_table_v2_users.php b/tests/specs/blog_v2/migrations_maria_db/m200000_000004_change_table_v2_users.php index d9c99f76..bf1c82fd 100644 --- a/tests/specs/blog_v2/migrations_maria_db/m200000_000004_change_table_v2_users.php +++ b/tests/specs/blog_v2/migrations_maria_db/m200000_000004_change_table_v2_users.php @@ -23,7 +23,7 @@ public function down() $this->dropIndex('v2_users_login_key', '{{%v2_users}}'); $this->createIndex('v2_users_username_key', '{{%v2_users}}', 'username', true); $this->alterColumn('{{%v2_users}}', 'created_at', $this->timestamp()->null()->defaultExpression("current_timestamp()")); - $this->alterColumn('{{%v2_users}}', 'role', $this->string(20)->null()->defaultValue("reader")); + $this->alterColumn('{{%v2_users}}', 'role', $this->string(20)->null()->defaultValue('reader')); $this->alterColumn('{{%v2_users}}', 'email', $this->string(200)->notNull()); $this->addColumn('{{%v2_users}}', 'username', $this->string(200)->notNull()); $this->dropColumn('{{%v2_users}}', 'login'); diff --git a/tests/specs/blog_v2/migrations_maria_db/m200000_000005_change_table_v2_comments.php b/tests/specs/blog_v2/migrations_maria_db/m200000_000005_change_table_v2_comments.php index 76c3b841..75553729 100644 --- a/tests/specs/blog_v2/migrations_maria_db/m200000_000005_change_table_v2_comments.php +++ b/tests/specs/blog_v2/migrations_maria_db/m200000_000005_change_table_v2_comments.php @@ -12,7 +12,7 @@ public function up() $this->addColumn('{{%v2_comments}}', 'user_id', $this->bigInteger()->null()->defaultValue(null)->after('post_id')); $this->dropColumn('{{%v2_comments}}', 'author_id'); $this->alterColumn('{{%v2_comments}}', 'message', $this->text()->notNull()); - $this->alterColumn('{{%v2_comments}}', 'meta_data', $this->string(300)->null()->defaultValue("")); + $this->alterColumn('{{%v2_comments}}', 'meta_data', $this->string(300)->null()->defaultValue('')); $this->alterColumn('{{%v2_comments}}', 'created_at', $this->timestamp()->notNull()); $this->addForeignKey('fk_v2_comments_post_id_v2_posts_id', '{{%v2_comments}}', 'post_id', '{{%v2_posts}}', 'id'); $this->addForeignKey('fk_v2_comments_user_id_v2_users_id', '{{%v2_comments}}', 'user_id', '{{%v2_users}}', 'id'); diff --git a/tests/specs/blog_v2/migrations_mysql_db/m200000_000004_change_table_v2_users.php b/tests/specs/blog_v2/migrations_mysql_db/m200000_000004_change_table_v2_users.php index 45515e1b..b7a1f5e3 100644 --- a/tests/specs/blog_v2/migrations_mysql_db/m200000_000004_change_table_v2_users.php +++ b/tests/specs/blog_v2/migrations_mysql_db/m200000_000004_change_table_v2_users.php @@ -23,7 +23,7 @@ public function down() $this->dropIndex('v2_users_login_key', '{{%v2_users}}'); $this->createIndex('v2_users_username_key', '{{%v2_users}}', 'username', true); $this->alterColumn('{{%v2_users}}', 'created_at', $this->timestamp()->null()->defaultExpression("CURRENT_TIMESTAMP")); - $this->alterColumn('{{%v2_users}}', 'role', $this->string(20)->null()->defaultValue("reader")); + $this->alterColumn('{{%v2_users}}', 'role', $this->string(20)->null()->defaultValue('reader')); $this->alterColumn('{{%v2_users}}', 'email', $this->string(200)->notNull()); $this->addColumn('{{%v2_users}}', 'username', $this->string(200)->notNull()); $this->dropColumn('{{%v2_users}}', 'login'); diff --git a/tests/specs/blog_v2/migrations_mysql_db/m200000_000005_change_table_v2_comments.php b/tests/specs/blog_v2/migrations_mysql_db/m200000_000005_change_table_v2_comments.php index 598c3e68..5861542c 100644 --- a/tests/specs/blog_v2/migrations_mysql_db/m200000_000005_change_table_v2_comments.php +++ b/tests/specs/blog_v2/migrations_mysql_db/m200000_000005_change_table_v2_comments.php @@ -12,7 +12,7 @@ public function up() $this->addColumn('{{%v2_comments}}', 'user_id', $this->bigInteger()->null()->defaultValue(null)->after('post_id')); $this->dropColumn('{{%v2_comments}}', 'author_id'); $this->alterColumn('{{%v2_comments}}', 'message', $this->text()->notNull()); - $this->alterColumn('{{%v2_comments}}', 'meta_data', $this->string(300)->null()->defaultValue("")); + $this->alterColumn('{{%v2_comments}}', 'meta_data', $this->string(300)->null()->defaultValue('')); $this->alterColumn('{{%v2_comments}}', 'created_at', $this->timestamp()->notNull()); $this->addForeignKey('fk_v2_comments_post_id_v2_posts_id', '{{%v2_comments}}', 'post_id', '{{%v2_posts}}', 'id'); $this->addForeignKey('fk_v2_comments_user_id_v2_users_id', '{{%v2_comments}}', 'user_id', '{{%v2_users}}', 'id'); diff --git a/tests/specs/enum/change/maria/app/migrations_maria_db/m200000_000001_create_table_newcolumns.php b/tests/specs/enum/change/maria/app/migrations_maria_db/m200000_000001_create_table_newcolumns.php index 36971de6..a1f55f6f 100644 --- a/tests/specs/enum/change/maria/app/migrations_maria_db/m200000_000001_create_table_newcolumns.php +++ b/tests/specs/enum/change/maria/app/migrations_maria_db/m200000_000001_create_table_newcolumns.php @@ -10,6 +10,7 @@ public function up() $this->createTable('{{%newcolumns}}', [ 'id' => $this->primaryKey(), 'new_column' => 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\'', + 0 => 'new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'', ]); } diff --git a/tests/specs/enum/change/mysql/app/migrations_mysql_db/m200000_000001_create_table_newcolumns.php b/tests/specs/enum/change/mysql/app/migrations_mysql_db/m200000_000001_create_table_newcolumns.php index 36971de6..a1f55f6f 100644 --- a/tests/specs/enum/change/mysql/app/migrations_mysql_db/m200000_000001_create_table_newcolumns.php +++ b/tests/specs/enum/change/mysql/app/migrations_mysql_db/m200000_000001_create_table_newcolumns.php @@ -10,6 +10,7 @@ public function up() $this->createTable('{{%newcolumns}}', [ 'id' => $this->primaryKey(), 'new_column' => 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\'', + 0 => 'new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'', ]); } diff --git a/tests/specs/enum/change/pgsql/app/migrations_pgsql_db/m200000_000001_create_table_newcolumns.php b/tests/specs/enum/change/pgsql/app/migrations_pgsql_db/m200000_000001_create_table_newcolumns.php index dc4901ee..97da2e43 100644 --- a/tests/specs/enum/change/pgsql/app/migrations_pgsql_db/m200000_000001_create_table_newcolumns.php +++ b/tests/specs/enum/change/pgsql/app/migrations_pgsql_db/m200000_000001_create_table_newcolumns.php @@ -11,6 +11,7 @@ public function safeUp() $this->createTable('{{%newcolumns}}', [ 'id' => $this->primaryKey(), 'new_column' => '"enum_itt_newcolumns_new_column" NOT NULL DEFAULT \'ONE\'', + 0 => '"new_column_x" varchar(10) NOT NULL DEFAULT \'ONE\'', ]); } diff --git a/tests/specs/enum/fresh/maria/app/migrations_maria_db/m200000_000001_create_table_newcolumns.php b/tests/specs/enum/fresh/maria/app/migrations_maria_db/m200000_000001_create_table_newcolumns.php index 36971de6..a1f55f6f 100644 --- a/tests/specs/enum/fresh/maria/app/migrations_maria_db/m200000_000001_create_table_newcolumns.php +++ b/tests/specs/enum/fresh/maria/app/migrations_maria_db/m200000_000001_create_table_newcolumns.php @@ -10,6 +10,7 @@ public function up() $this->createTable('{{%newcolumns}}', [ 'id' => $this->primaryKey(), 'new_column' => 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\'', + 0 => 'new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'', ]); } diff --git a/tests/specs/enum/fresh/mysql/app/migrations_mysql_db/m200000_000001_create_table_newcolumns.php b/tests/specs/enum/fresh/mysql/app/migrations_mysql_db/m200000_000001_create_table_newcolumns.php index 36971de6..a1f55f6f 100644 --- a/tests/specs/enum/fresh/mysql/app/migrations_mysql_db/m200000_000001_create_table_newcolumns.php +++ b/tests/specs/enum/fresh/mysql/app/migrations_mysql_db/m200000_000001_create_table_newcolumns.php @@ -10,6 +10,7 @@ public function up() $this->createTable('{{%newcolumns}}', [ 'id' => $this->primaryKey(), 'new_column' => 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\'', + 0 => 'new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'', ]); } diff --git a/tests/specs/enum/fresh/mysql/enum.yaml b/tests/specs/enum/fresh/mysql/enum.yaml index 2dcc0a94..0b623634 100644 --- a/tests/specs/enum/fresh/mysql/enum.yaml +++ b/tests/specs/enum/fresh/mysql/enum.yaml @@ -59,6 +59,16 @@ components: default: ONE nullable: false + new_column_x: + type: string + enum: + - ONE + - TWO + - THREE + default: + ONE + x-db-type: varchar(10) + nullable: false Editcolumn: type: object diff --git a/tests/specs/enum/fresh/pgsql/app/migrations_pgsql_db/m200000_000001_create_table_newcolumns.php b/tests/specs/enum/fresh/pgsql/app/migrations_pgsql_db/m200000_000001_create_table_newcolumns.php index dc4901ee..97da2e43 100644 --- a/tests/specs/enum/fresh/pgsql/app/migrations_pgsql_db/m200000_000001_create_table_newcolumns.php +++ b/tests/specs/enum/fresh/pgsql/app/migrations_pgsql_db/m200000_000001_create_table_newcolumns.php @@ -11,6 +11,7 @@ public function safeUp() $this->createTable('{{%newcolumns}}', [ 'id' => $this->primaryKey(), 'new_column' => '"enum_itt_newcolumns_new_column" NOT NULL DEFAULT \'ONE\'', + 0 => '"new_column_x" varchar(10) NOT NULL DEFAULT \'ONE\'', ]); } diff --git a/tests/specs/enum/new_column/maria/app/migrations_maria_db/m200000_000001_change_table_newcolumns.php b/tests/specs/enum/new_column/maria/app/migrations_maria_db/m200000_000001_change_table_newcolumns.php index 4ef6a191..78f6b2e5 100644 --- a/tests/specs/enum/new_column/maria/app/migrations_maria_db/m200000_000001_change_table_newcolumns.php +++ b/tests/specs/enum/new_column/maria/app/migrations_maria_db/m200000_000001_change_table_newcolumns.php @@ -7,13 +7,15 @@ class m200000_000001_change_table_newcolumns extends \yii\db\Migration { public function up() { - $this->addColumn('{{%newcolumns}}', 'new_column', 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\''); + $this->addColumn('{{%newcolumns}}', 'new_column', 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\' AFTER id'); + $this->db->createCommand('ALTER TABLE {{%newcolumns}} ADD COLUMN new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'')->execute(); $this->dropColumn('{{%newcolumns}}', 'delete_col'); } public function down() { $this->addColumn('{{%newcolumns}}', 'delete_col', 'enum("FOUR", "FIVE", "SIX") NULL DEFAULT NULL'); + $this->dropColumn('{{%newcolumns}}', 'new_column_x'); $this->dropColumn('{{%newcolumns}}', 'new_column'); } } diff --git a/tests/specs/enum/new_column/mysql/app/migrations_mysql_db/m200000_000001_change_table_newcolumns.php b/tests/specs/enum/new_column/mysql/app/migrations_mysql_db/m200000_000001_change_table_newcolumns.php index 4ef6a191..78f6b2e5 100644 --- a/tests/specs/enum/new_column/mysql/app/migrations_mysql_db/m200000_000001_change_table_newcolumns.php +++ b/tests/specs/enum/new_column/mysql/app/migrations_mysql_db/m200000_000001_change_table_newcolumns.php @@ -7,13 +7,15 @@ class m200000_000001_change_table_newcolumns extends \yii\db\Migration { public function up() { - $this->addColumn('{{%newcolumns}}', 'new_column', 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\''); + $this->addColumn('{{%newcolumns}}', 'new_column', 'enum("ONE", "TWO", "THREE") NOT NULL DEFAULT \'ONE\' AFTER id'); + $this->db->createCommand('ALTER TABLE {{%newcolumns}} ADD COLUMN new_column_x varchar(10) NOT NULL DEFAULT \'ONE\'')->execute(); $this->dropColumn('{{%newcolumns}}', 'delete_col'); } public function down() { $this->addColumn('{{%newcolumns}}', 'delete_col', 'enum("FOUR", "FIVE", "SIX") NULL DEFAULT NULL'); + $this->dropColumn('{{%newcolumns}}', 'new_column_x'); $this->dropColumn('{{%newcolumns}}', 'new_column'); } } diff --git a/tests/specs/enum/new_column/pgsql/app/migrations_pgsql_db/m200000_000001_change_table_newcolumns.php b/tests/specs/enum/new_column/pgsql/app/migrations_pgsql_db/m200000_000001_change_table_newcolumns.php index a1d79e66..87517589 100644 --- a/tests/specs/enum/new_column/pgsql/app/migrations_pgsql_db/m200000_000001_change_table_newcolumns.php +++ b/tests/specs/enum/new_column/pgsql/app/migrations_pgsql_db/m200000_000001_change_table_newcolumns.php @@ -9,6 +9,7 @@ public function safeUp() { $this->execute('CREATE TYPE "enum_itt_newcolumns_new_column" AS ENUM(\'ONE\', \'TWO\', \'THREE\')'); $this->addColumn('{{%newcolumns}}', 'new_column', '"enum_itt_newcolumns_new_column" NOT NULL DEFAULT \'ONE\''); + $this->db->createCommand('ALTER TABLE {{%newcolumns}} ADD COLUMN "new_column_x" varchar(10) NOT NULL DEFAULT \'ONE\'')->execute(); $this->dropColumn('{{%newcolumns}}', 'delete_col'); $this->execute('DROP TYPE "enum_itt_newcolumns_delete_col"'); } @@ -17,6 +18,7 @@ public function safeDown() { $this->execute('CREATE TYPE "enum_itt_newcolumns_delete_col" AS ENUM(\'FOUR\', \'FIVE\', \'SIX\')'); $this->addColumn('{{%newcolumns}}', 'delete_col', '"enum_itt_newcolumns_delete_col" NULL DEFAULT NULL'); + $this->dropColumn('{{%newcolumns}}', 'new_column_x'); $this->dropColumn('{{%newcolumns}}', 'new_column'); $this->execute('DROP TYPE "enum_itt_newcolumns_new_column"'); } diff --git a/tests/specs/postgres_custom.yaml b/tests/specs/postgres_custom.yaml index 519af1ab..e3d9a810 100644 --- a/tests/specs/postgres_custom.yaml +++ b/tests/specs/postgres_custom.yaml @@ -70,6 +70,13 @@ components: enum: - active - draft + status_x: + type: string + default: draft + enum: + - active + - draft + x-db-type: varchar(10) search: type: string x-db-type: tsvector diff --git a/tests/specs/postgres_custom/migrations_pgsql_db/m200000_000000_change_table_v3_pgcustom.php b/tests/specs/postgres_custom/migrations_pgsql_db/m200000_000000_change_table_v3_pgcustom.php index c04adc88..a1ffe61a 100644 --- a/tests/specs/postgres_custom/migrations_pgsql_db/m200000_000000_change_table_v3_pgcustom.php +++ b/tests/specs/postgres_custom/migrations_pgsql_db/m200000_000000_change_table_v3_pgcustom.php @@ -16,6 +16,7 @@ public function safeUp() $this->alterColumn('{{%v3_pgcustom}}', 'json4', "SET NOT NULL"); $this->alterColumn('{{%v3_pgcustom}}', 'json4', "SET DEFAULT '{\"foo\":\"bar\",\"bar\":\"baz\"}'"); $this->alterColumn('{{%v3_pgcustom}}', 'status', "SET DEFAULT 'draft'"); + $this->alterColumn('{{%v3_pgcustom}}', 'status_x', "SET DEFAULT 'draft'"); $this->createIndex('v3_pgcustom_search_gin_index', '{{%v3_pgcustom}}', 'search', 'gin(to_tsvector(\'english\', status))'); } @@ -31,5 +32,6 @@ public function safeDown() $this->alterColumn('{{%v3_pgcustom}}', 'json4', "DROP NOT NULL"); $this->alterColumn('{{%v3_pgcustom}}', 'json4', "SET DEFAULT '{\"ffo\":\"bar\"}'"); $this->alterColumn('{{%v3_pgcustom}}', 'status', "DROP DEFAULT"); + $this->alterColumn('{{%v3_pgcustom}}', 'status_x', "DROP DEFAULT"); } } diff --git a/tests/specs/postgres_custom/models/CustomFaker.php b/tests/specs/postgres_custom/models/CustomFaker.php index 6c7de598..3732716d 100644 --- a/tests/specs/postgres_custom/models/CustomFaker.php +++ b/tests/specs/postgres_custom/models/CustomFaker.php @@ -36,6 +36,7 @@ public function generateModel($attributes = []) $model->json3 = []; $model->json4 = []; $model->status = $faker->randomElement(['active','draft']); + $model->status_x = $faker->randomElement(['active','draft']); if (!is_callable($attributes)) { $model->setAttributes($attributes, false); } else { diff --git a/tests/specs/postgres_custom/models/base/Custom.php b/tests/specs/postgres_custom/models/base/Custom.php index be227825..f7bbc803 100644 --- a/tests/specs/postgres_custom/models/base/Custom.php +++ b/tests/specs/postgres_custom/models/base/Custom.php @@ -12,6 +12,7 @@ * @property array $json3 * @property array $json4 * @property string $status + * @property string $status_x * @property string $search * */ @@ -25,7 +26,7 @@ public static function tableName() public function rules() { return [ - 'trim' => [['status'], 'trim'], + 'trim' => [['status', 'status_x'], 'trim'], 'num_integer' => [['num'], 'integer'], 'num_default' => [['num'], 'default', 'value' => 0], 'json1_default' => [['json1'], 'default', 'value' => []], @@ -48,6 +49,12 @@ public function rules() 'draft', ]], 'status_default' => [['status'], 'default', 'value' => 'draft'], + 'status_x_string' => [['status_x'], 'string', 'max' => 10], + 'status_x_in' => [['status_x'], 'in', 'range' => [ + 'active', + 'draft', + ]], + 'status_x_default' => [['status_x'], 'default', 'value' => 'draft'], 'safe' => [['json1', 'json2', 'json3', 'json4'], 'safe'], ]; } diff --git a/tests/specs/x_db_default_expression/maria/edit/app/migrations_maria_db/m200000_000000_change_table_fruits.php b/tests/specs/x_db_default_expression/maria/edit/app/migrations_maria_db/m200000_000000_change_table_fruits.php index 6d8bc8e9..8bf7bff0 100644 --- a/tests/specs/x_db_default_expression/maria/edit/app/migrations_maria_db/m200000_000000_change_table_fruits.php +++ b/tests/specs/x_db_default_expression/maria/edit/app/migrations_maria_db/m200000_000000_change_table_fruits.php @@ -8,14 +8,14 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration public function up() { $this->alterColumn('{{%fruits}}', 'ts', $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)")); - $this->alterColumn('{{%fruits}}', 'ts2', $this->timestamp()->null()->defaultValue("2011-11-11 00:00:00")); - $this->alterColumn('{{%fruits}}', 'ts3', $this->timestamp()->null()->defaultValue("2022-11-11 00:00:00")); - $this->alterColumn('{{%fruits}}', 'ts4', $this->timestamp()->null()->defaultValue("2022-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts2', $this->timestamp()->null()->defaultValue('2011-11-11 00:00:00')); + $this->alterColumn('{{%fruits}}', 'ts3', $this->timestamp()->null()->defaultValue('2022-11-11 00:00:00')); + $this->alterColumn('{{%fruits}}', 'ts4', $this->timestamp()->null()->defaultValue('2022-11-11 00:00:00')); $this->alterColumn('{{%fruits}}', 'ts5', $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)")); - $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->null()->defaultValue("2000-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->null()->defaultValue('2000-11-11 00:00:00')); $this->alterColumn('{{%fruits}}', 'd', $this->date()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); $this->alterColumn('{{%fruits}}', 'd2', $this->text()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); - $this->alterColumn('{{%fruits}}', 'd3', $this->text()->null()->defaultValue("text default")); + $this->alterColumn('{{%fruits}}', 'd3', $this->text()->null()->defaultValue('text default')); $this->alterColumn('{{%fruits}}', 'ts7', $this->date()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); } @@ -25,8 +25,8 @@ public function down() $this->alterColumn('{{%fruits}}', 'd3', $this->text()->null()->defaultValue(null)); $this->alterColumn('{{%fruits}}', 'd2', $this->text()->null()->defaultValue(null)); $this->alterColumn('{{%fruits}}', 'd', $this->date()->null()->defaultValue(null)); - $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->notNull()->defaultValue("0000-00-00 00:00:00")); - $this->alterColumn('{{%fruits}}', 'ts5', $this->timestamp()->notNull()->defaultValue("0000-00-00 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->notNull()->defaultValue('0000-00-00 00:00:00')); + $this->alterColumn('{{%fruits}}', 'ts5', $this->timestamp()->notNull()->defaultValue('0000-00-00 00:00:00')); $this->alterColumn('{{%fruits}}', 'ts4', $this->timestamp()->notNull()->defaultExpression("current_timestamp()")); $this->alterColumn('{{%fruits}}', 'ts3', $this->datetime()->null()->defaultValue(null)); $this->alterColumn('{{%fruits}}', 'ts2', $this->datetime()->null()->defaultValue(null)); diff --git a/tests/specs/x_db_default_expression/maria/edit_expression/app/migrations_maria_db/m200000_000000_change_table_fruits.php b/tests/specs/x_db_default_expression/maria/edit_expression/app/migrations_maria_db/m200000_000000_change_table_fruits.php index 8e2f1f01..f709a2fd 100644 --- a/tests/specs/x_db_default_expression/maria/edit_expression/app/migrations_maria_db/m200000_000000_change_table_fruits.php +++ b/tests/specs/x_db_default_expression/maria/edit_expression/app/migrations_maria_db/m200000_000000_change_table_fruits.php @@ -8,28 +8,28 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration public function up() { $this->alterColumn('{{%fruits}}', 'ts', $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)")); - $this->alterColumn('{{%fruits}}', 'ts2', $this->timestamp()->null()->defaultValue("2011-11-11 00:00:00")); - $this->alterColumn('{{%fruits}}', 'ts3', $this->timestamp()->null()->defaultValue("2022-11-11 00:00:00")); - $this->alterColumn('{{%fruits}}', 'ts4', $this->timestamp()->null()->defaultValue("2022-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts2', $this->timestamp()->null()->defaultValue('2011-11-11 00:00:00')); + $this->alterColumn('{{%fruits}}', 'ts3', $this->timestamp()->null()->defaultValue('2022-11-11 00:00:00')); + $this->alterColumn('{{%fruits}}', 'ts4', $this->timestamp()->null()->defaultValue('2022-11-11 00:00:00')); $this->alterColumn('{{%fruits}}', 'ts5', $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)")); - $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->null()->defaultValue("2000-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->null()->defaultValue('2000-11-11 00:00:00')); $this->alterColumn('{{%fruits}}', 'd', $this->date()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); $this->alterColumn('{{%fruits}}', 'd2', $this->text()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); - $this->alterColumn('{{%fruits}}', 'd3', $this->text()->null()->defaultValue("text default")); + $this->alterColumn('{{%fruits}}', 'd3', $this->text()->null()->defaultValue('text default')); $this->alterColumn('{{%fruits}}', 'ts7', $this->date()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); } public function down() { - $this->alterColumn('{{%fruits}}', 'ts7', $this->date()->null()->defaultValue("2011-11-11")); + $this->alterColumn('{{%fruits}}', 'ts7', $this->date()->null()->defaultValue('2011-11-11')); $this->alterColumn('{{%fruits}}', 'd3', $this->text()->null()->defaultValue(null)); $this->alterColumn('{{%fruits}}', 'd2', $this->text()->null()->defaultValue(null)); - $this->alterColumn('{{%fruits}}', 'd', $this->date()->null()->defaultValue("2011-11-11")); + $this->alterColumn('{{%fruits}}', 'd', $this->date()->null()->defaultValue('2011-11-11')); $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->notNull()->defaultExpression("current_timestamp()")); - $this->alterColumn('{{%fruits}}', 'ts5', $this->timestamp()->notNull()->defaultValue("2011-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts5', $this->timestamp()->notNull()->defaultValue('2011-11-11 00:00:00')); $this->alterColumn('{{%fruits}}', 'ts4', $this->timestamp()->notNull()->defaultExpression("current_timestamp()")); $this->alterColumn('{{%fruits}}', 'ts3', $this->datetime()->null()->defaultExpression("current_timestamp()")); $this->alterColumn('{{%fruits}}', 'ts2', $this->datetime()->null()->defaultExpression("current_timestamp()")); - $this->alterColumn('{{%fruits}}', 'ts', $this->datetime()->null()->defaultValue("2011-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts', $this->datetime()->null()->defaultValue('2011-11-11 00:00:00')); } } diff --git a/tests/specs/x_db_default_expression/maria/simple/app/migrations_maria_db/m200000_000000_create_table_fruits.php b/tests/specs/x_db_default_expression/maria/simple/app/migrations_maria_db/m200000_000000_create_table_fruits.php index 3348044e..8285456b 100644 --- a/tests/specs/x_db_default_expression/maria/simple/app/migrations_maria_db/m200000_000000_create_table_fruits.php +++ b/tests/specs/x_db_default_expression/maria/simple/app/migrations_maria_db/m200000_000000_create_table_fruits.php @@ -9,8 +9,8 @@ public function up() { $this->createTable('{{%fruits}}', [ 'ts' => $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)"), - 'ts2' => $this->timestamp()->null()->defaultValue("2011-11-11 00:00:00"), - 'ts3' => $this->timestamp()->null()->defaultValue("2022-11-11 00:00:00"), + 'ts2' => $this->timestamp()->null()->defaultValue('2011-11-11 00:00:00'), + 'ts3' => $this->timestamp()->null()->defaultValue('2022-11-11 00:00:00'), 0 => 'ts4 timestamp NULL DEFAULT \'2022-11-11 00:00:00\'', 1 => 'ts5 timestamp NULL DEFAULT (CURRENT_TIMESTAMP)', 2 => 'ts6 timestamp NULL DEFAULT \'2000-11-11 00:00:00\'', diff --git a/tests/specs/x_db_default_expression/mysql/edit/app/migrations_mysql_db/m200000_000000_change_table_fruits.php b/tests/specs/x_db_default_expression/mysql/edit/app/migrations_mysql_db/m200000_000000_change_table_fruits.php index 6782b722..01eefe40 100644 --- a/tests/specs/x_db_default_expression/mysql/edit/app/migrations_mysql_db/m200000_000000_change_table_fruits.php +++ b/tests/specs/x_db_default_expression/mysql/edit/app/migrations_mysql_db/m200000_000000_change_table_fruits.php @@ -8,11 +8,11 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration public function up() { $this->alterColumn('{{%fruits}}', 'ts', $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)")); - $this->alterColumn('{{%fruits}}', 'ts2', $this->timestamp()->null()->defaultValue("2011-11-11 00:00:00")); - $this->alterColumn('{{%fruits}}', 'ts3', $this->timestamp()->null()->defaultValue("2022-11-11 00:00:00")); - $this->alterColumn('{{%fruits}}', 'ts4', $this->timestamp()->null()->defaultValue("2022-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts2', $this->timestamp()->null()->defaultValue('2011-11-11 00:00:00')); + $this->alterColumn('{{%fruits}}', 'ts3', $this->timestamp()->null()->defaultValue('2022-11-11 00:00:00')); + $this->alterColumn('{{%fruits}}', 'ts4', $this->timestamp()->null()->defaultValue('2022-11-11 00:00:00')); $this->alterColumn('{{%fruits}}', 'ts5', $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)")); - $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->null()->defaultValue("2000-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->null()->defaultValue('2000-11-11 00:00:00')); $this->alterColumn('{{%fruits}}', 'd', $this->date()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); $this->alterColumn('{{%fruits}}', 'd2', $this->text()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); $this->alterColumn('{{%fruits}}', 'ts7', $this->date()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); diff --git a/tests/specs/x_db_default_expression/mysql/edit_expression/app/migrations_mysql_db/m200000_000000_change_table_fruits.php b/tests/specs/x_db_default_expression/mysql/edit_expression/app/migrations_mysql_db/m200000_000000_change_table_fruits.php index d678505e..b130a4fa 100644 --- a/tests/specs/x_db_default_expression/mysql/edit_expression/app/migrations_mysql_db/m200000_000000_change_table_fruits.php +++ b/tests/specs/x_db_default_expression/mysql/edit_expression/app/migrations_mysql_db/m200000_000000_change_table_fruits.php @@ -8,11 +8,11 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration public function up() { $this->alterColumn('{{%fruits}}', 'ts', $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)")); - $this->alterColumn('{{%fruits}}', 'ts2', $this->timestamp()->null()->defaultValue("2011-11-11 00:00:00")); - $this->alterColumn('{{%fruits}}', 'ts3', $this->timestamp()->null()->defaultValue("2022-11-11 00:00:00")); - $this->alterColumn('{{%fruits}}', 'ts4', $this->timestamp()->null()->defaultValue("2022-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts2', $this->timestamp()->null()->defaultValue('2011-11-11 00:00:00')); + $this->alterColumn('{{%fruits}}', 'ts3', $this->timestamp()->null()->defaultValue('2022-11-11 00:00:00')); + $this->alterColumn('{{%fruits}}', 'ts4', $this->timestamp()->null()->defaultValue('2022-11-11 00:00:00')); $this->alterColumn('{{%fruits}}', 'ts5', $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)")); - $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->null()->defaultValue("2000-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->null()->defaultValue('2000-11-11 00:00:00')); $this->alterColumn('{{%fruits}}', 'd', $this->date()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); $this->alterColumn('{{%fruits}}', 'd2', $this->text()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); $this->alterColumn('{{%fruits}}', 'ts7', $this->date()->null()->defaultExpression("(CURRENT_DATE + INTERVAL 1 YEAR)")); @@ -20,14 +20,14 @@ public function up() public function down() { - $this->alterColumn('{{%fruits}}', 'ts7', $this->date()->null()->defaultValue("2011-11-11")); + $this->alterColumn('{{%fruits}}', 'ts7', $this->date()->null()->defaultValue('2011-11-11')); $this->alterColumn('{{%fruits}}', 'd2', $this->text()->null()); - $this->alterColumn('{{%fruits}}', 'd', $this->date()->null()->defaultValue("2011-11-11")); + $this->alterColumn('{{%fruits}}', 'd', $this->date()->null()->defaultValue('2011-11-11')); $this->alterColumn('{{%fruits}}', 'ts6', $this->timestamp()->null()->defaultExpression("CURRENT_TIMESTAMP")); - $this->alterColumn('{{%fruits}}', 'ts5', $this->timestamp()->null()->defaultValue("2011-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts5', $this->timestamp()->null()->defaultValue('2011-11-11 00:00:00')); $this->alterColumn('{{%fruits}}', 'ts4', $this->timestamp()->null()->defaultExpression("CURRENT_TIMESTAMP")); $this->alterColumn('{{%fruits}}', 'ts3', $this->datetime()->null()->defaultExpression("CURRENT_TIMESTAMP")); $this->alterColumn('{{%fruits}}', 'ts2', $this->datetime()->null()->defaultExpression("CURRENT_TIMESTAMP")); - $this->alterColumn('{{%fruits}}', 'ts', $this->datetime()->null()->defaultValue("2011-11-11 00:00:00")); + $this->alterColumn('{{%fruits}}', 'ts', $this->datetime()->null()->defaultValue('2011-11-11 00:00:00')); } } diff --git a/tests/specs/x_db_default_expression/mysql/simple/app/migrations_mysql_db/m200000_000000_create_table_fruits.php b/tests/specs/x_db_default_expression/mysql/simple/app/migrations_mysql_db/m200000_000000_create_table_fruits.php index e60beee3..11f7238b 100644 --- a/tests/specs/x_db_default_expression/mysql/simple/app/migrations_mysql_db/m200000_000000_create_table_fruits.php +++ b/tests/specs/x_db_default_expression/mysql/simple/app/migrations_mysql_db/m200000_000000_create_table_fruits.php @@ -9,8 +9,8 @@ public function up() { $this->createTable('{{%fruits}}', [ 'ts' => $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)"), - 'ts2' => $this->timestamp()->null()->defaultValue("2011-11-11 00:00:00"), - 'ts3' => $this->timestamp()->null()->defaultValue("2022-11-11 00:00:00"), + 'ts2' => $this->timestamp()->null()->defaultValue('2011-11-11 00:00:00'), + 'ts3' => $this->timestamp()->null()->defaultValue('2022-11-11 00:00:00'), 0 => 'ts4 timestamp NULL DEFAULT \'2022-11-11 00:00:00\'', 1 => 'ts5 timestamp NULL DEFAULT (CURRENT_TIMESTAMP)', 2 => 'ts6 timestamp NULL DEFAULT \'2000-11-11 00:00:00\'', diff --git a/tests/specs/x_db_default_expression/pgsql/simple/app/migrations_pgsql_db/m200000_000000_create_table_fruits.php b/tests/specs/x_db_default_expression/pgsql/simple/app/migrations_pgsql_db/m200000_000000_create_table_fruits.php index 5b1494cf..60533da5 100644 --- a/tests/specs/x_db_default_expression/pgsql/simple/app/migrations_pgsql_db/m200000_000000_create_table_fruits.php +++ b/tests/specs/x_db_default_expression/pgsql/simple/app/migrations_pgsql_db/m200000_000000_create_table_fruits.php @@ -9,8 +9,8 @@ public function safeUp() { $this->createTable('{{%fruits}}', [ 'ts' => $this->timestamp()->null()->defaultExpression("(CURRENT_TIMESTAMP)"), - 'ts2' => $this->timestamp()->null()->defaultValue("2011-11-11 00:00:00"), - 'ts3' => $this->timestamp()->null()->defaultValue("2022-11-11 00:00:00"), + 'ts2' => $this->timestamp()->null()->defaultValue('2011-11-11 00:00:00'), + 'ts3' => $this->timestamp()->null()->defaultValue('2022-11-11 00:00:00'), 0 => '"ts4" timestamp NULL DEFAULT \'2022-11-11 00:00:00\'', 1 => '"ts5" timestamp NULL DEFAULT (CURRENT_TIMESTAMP)', 2 => '"ts6" timestamp NULL DEFAULT \'2000-11-11 00:00:00\'', diff --git a/tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000001_change_table_editcolumns.php b/tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000001_change_table_editcolumns.php index b1b08de8..239c0a9b 100644 --- a/tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000001_change_table_editcolumns.php +++ b/tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000001_change_table_editcolumns.php @@ -10,11 +10,11 @@ public function up() $this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN first_name varchar(255) NULL DEFAULT NULL AFTER tag')->execute(); $this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN json_col_def_n json NOT NULL DEFAULT \'[]\' AFTER numeric_col')->execute(); $this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN json_col_def_n_2 json NOT NULL DEFAULT \'[]\'')->execute(); - $this->alterColumn('{{%editcolumns}}', 'name', $this->string(255)->notNull()->defaultValue("Horse-2")); + $this->alterColumn('{{%editcolumns}}', 'name', $this->string(255)->notNull()->defaultValue('Horse-2')); $this->alterColumn('{{%editcolumns}}', 'string_col', $this->text()->null()->defaultValue(null)); $this->alterColumn('{{%editcolumns}}', 'dec_col', $this->decimal(12,2)->null()->defaultValue("3.14")); $this->alterColumn('{{%editcolumns}}', 'str_col_def', $this->string(3)->notNull()); - $this->alterColumn('{{%editcolumns}}', 'json_col', $this->text()->notNull()->defaultValue("fox jumps over dog")); + $this->alterColumn('{{%editcolumns}}', 'json_col', $this->text()->notNull()->defaultValue('fox jumps over dog')); $this->alterColumn('{{%editcolumns}}', 'json_col_2', 'json NOT NULL DEFAULT \'[]\''); $this->alterColumn('{{%editcolumns}}', 'numeric_col', $this->double()->null()->defaultValue(null)); } @@ -24,10 +24,10 @@ public function down() $this->alterColumn('{{%editcolumns}}', 'numeric_col', $this->integer(11)->null()->defaultValue(null)); $this->alterColumn('{{%editcolumns}}', 'json_col_2', 'json NULL DEFAULT NULL'); $this->alterColumn('{{%editcolumns}}', 'json_col', 'json NULL DEFAULT NULL'); - $this->alterColumn('{{%editcolumns}}', 'str_col_def', $this->string(255)->null()->defaultValue("hi there")); + $this->alterColumn('{{%editcolumns}}', 'str_col_def', $this->string(255)->null()->defaultValue('hi there')); $this->alterColumn('{{%editcolumns}}', 'dec_col', $this->decimal(12,4)->null()->defaultValue(null)); $this->alterColumn('{{%editcolumns}}', 'string_col', $this->string(255)->notNull()); - $this->alterColumn('{{%editcolumns}}', 'name', $this->string(255)->notNull()->defaultValue("Horse")); + $this->alterColumn('{{%editcolumns}}', 'name', $this->string(255)->notNull()->defaultValue('Horse')); $this->dropColumn('{{%editcolumns}}', 'json_col_def_n_2'); $this->dropColumn('{{%editcolumns}}', 'json_col_def_n'); $this->dropColumn('{{%editcolumns}}', 'first_name'); diff --git a/tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php b/tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php index 6e7ab8a7..1e27d8d6 100644 --- a/tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php +++ b/tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php @@ -10,7 +10,7 @@ public function up() $this->createTable('{{%pristines}}', [ 0 => 'custom_id_col integer primary key auto_increment NOT NULL', 1 => 'name text NOT NULL', - 'tag' => $this->text()->null()->defaultValue("4 leg"), + 'tag' => $this->text()->null()->defaultValue('4 leg'), 2 => 'new_col varchar(17) NULL DEFAULT NULL', 3 => 'col_5 decimal(12,4) NULL DEFAULT NULL', 4 => 'col_6 decimal(11,2) NULL DEFAULT NULL', diff --git a/tests/specs/x_db_type/edit_column/mysql/app/migrations_mysql_db/m200000_000001_change_table_editcolumns.php b/tests/specs/x_db_type/edit_column/mysql/app/migrations_mysql_db/m200000_000001_change_table_editcolumns.php index c990c03a..b4d63bd3 100644 --- a/tests/specs/x_db_type/edit_column/mysql/app/migrations_mysql_db/m200000_000001_change_table_editcolumns.php +++ b/tests/specs/x_db_type/edit_column/mysql/app/migrations_mysql_db/m200000_000001_change_table_editcolumns.php @@ -10,7 +10,7 @@ public function up() $this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN first_name varchar(255) NULL DEFAULT NULL AFTER tag')->execute(); $this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN json_col_def_n json NOT NULL AFTER numeric_col')->execute(); $this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN json_col_def_n_2 json NOT NULL')->execute(); - $this->alterColumn('{{%editcolumns}}', 'name', $this->string(255)->notNull()->defaultValue("Horse-2")); + $this->alterColumn('{{%editcolumns}}', 'name', $this->string(255)->notNull()->defaultValue('Horse-2')); $this->alterColumn('{{%editcolumns}}', 'string_col', $this->text()->null()); $this->alterColumn('{{%editcolumns}}', 'dec_col', $this->decimal(12,2)->null()->defaultValue("3.14")); $this->alterColumn('{{%editcolumns}}', 'str_col_def', $this->string(3)->notNull()); @@ -24,10 +24,10 @@ public function down() $this->alterColumn('{{%editcolumns}}', 'numeric_col', $this->integer()->null()->defaultValue(null)); $this->alterColumn('{{%editcolumns}}', 'json_col_2', 'json NULL'); $this->alterColumn('{{%editcolumns}}', 'json_col', 'json NULL'); - $this->alterColumn('{{%editcolumns}}', 'str_col_def', $this->string(255)->null()->defaultValue("hi there")); + $this->alterColumn('{{%editcolumns}}', 'str_col_def', $this->string(255)->null()->defaultValue('hi there')); $this->alterColumn('{{%editcolumns}}', 'dec_col', $this->decimal(12,4)->null()->defaultValue(null)); $this->alterColumn('{{%editcolumns}}', 'string_col', $this->string(255)->notNull()); - $this->alterColumn('{{%editcolumns}}', 'name', $this->string(255)->notNull()->defaultValue("Horse")); + $this->alterColumn('{{%editcolumns}}', 'name', $this->string(255)->notNull()->defaultValue('Horse')); $this->dropColumn('{{%editcolumns}}', 'json_col_def_n_2'); $this->dropColumn('{{%editcolumns}}', 'json_col_def_n'); $this->dropColumn('{{%editcolumns}}', 'first_name'); diff --git a/tests/specs/x_db_type/edit_column/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php b/tests/specs/x_db_type/edit_column/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php index a5ac94cd..aab6bb88 100644 --- a/tests/specs/x_db_type/edit_column/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php +++ b/tests/specs/x_db_type/edit_column/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php @@ -10,7 +10,7 @@ public function safeUp() $this->createTable('{{%pristines}}', [ 0 => '"custom_id_col" serial primary key NOT NULL', 1 => '"name" text NOT NULL', - 'tag' => $this->text()->null()->defaultValue("4 leg"), + 'tag' => $this->text()->null()->defaultValue('4 leg'), 2 => '"new_col" varchar NULL DEFAULT NULL', 3 => '"col_5" decimal(12,4) NULL DEFAULT NULL', 4 => '"col_6" decimal(11,2) NULL DEFAULT NULL', diff --git a/tests/specs/x_db_type/fresh/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php b/tests/specs/x_db_type/fresh/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php index 6e7ab8a7..1e27d8d6 100644 --- a/tests/specs/x_db_type/fresh/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php +++ b/tests/specs/x_db_type/fresh/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php @@ -10,7 +10,7 @@ public function up() $this->createTable('{{%pristines}}', [ 0 => 'custom_id_col integer primary key auto_increment NOT NULL', 1 => 'name text NOT NULL', - 'tag' => $this->text()->null()->defaultValue("4 leg"), + 'tag' => $this->text()->null()->defaultValue('4 leg'), 2 => 'new_col varchar(17) NULL DEFAULT NULL', 3 => 'col_5 decimal(12,4) NULL DEFAULT NULL', 4 => 'col_6 decimal(11,2) NULL DEFAULT NULL', diff --git a/tests/specs/x_db_type/fresh/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php b/tests/specs/x_db_type/fresh/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php index a5ac94cd..aab6bb88 100644 --- a/tests/specs/x_db_type/fresh/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php +++ b/tests/specs/x_db_type/fresh/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php @@ -10,7 +10,7 @@ public function safeUp() $this->createTable('{{%pristines}}', [ 0 => '"custom_id_col" serial primary key NOT NULL', 1 => '"name" text NOT NULL', - 'tag' => $this->text()->null()->defaultValue("4 leg"), + 'tag' => $this->text()->null()->defaultValue('4 leg'), 2 => '"new_col" varchar NULL DEFAULT NULL', 3 => '"col_5" decimal(12,4) NULL DEFAULT NULL', 4 => '"col_6" decimal(11,2) NULL DEFAULT NULL', diff --git a/tests/specs/x_db_type/new_column/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php b/tests/specs/x_db_type/new_column/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php index 6e7ab8a7..1e27d8d6 100644 --- a/tests/specs/x_db_type/new_column/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php +++ b/tests/specs/x_db_type/new_column/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php @@ -10,7 +10,7 @@ public function up() $this->createTable('{{%pristines}}', [ 0 => 'custom_id_col integer primary key auto_increment NOT NULL', 1 => 'name text NOT NULL', - 'tag' => $this->text()->null()->defaultValue("4 leg"), + 'tag' => $this->text()->null()->defaultValue('4 leg'), 2 => 'new_col varchar(17) NULL DEFAULT NULL', 3 => 'col_5 decimal(12,4) NULL DEFAULT NULL', 4 => 'col_6 decimal(11,2) NULL DEFAULT NULL', diff --git a/tests/specs/x_db_type/new_column/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php b/tests/specs/x_db_type/new_column/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php index a5ac94cd..aab6bb88 100644 --- a/tests/specs/x_db_type/new_column/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php +++ b/tests/specs/x_db_type/new_column/pgsql/app/migrations_pgsql_db/m200000_000003_create_table_pristines.php @@ -10,7 +10,7 @@ public function safeUp() $this->createTable('{{%pristines}}', [ 0 => '"custom_id_col" serial primary key NOT NULL', 1 => '"name" text NOT NULL', - 'tag' => $this->text()->null()->defaultValue("4 leg"), + 'tag' => $this->text()->null()->defaultValue('4 leg'), 2 => '"new_col" varchar NULL DEFAULT NULL', 3 => '"col_5" decimal(12,4) NULL DEFAULT NULL', 4 => '"col_6" decimal(11,2) NULL DEFAULT NULL', diff --git a/tests/unit/AttributeResolverTest.php b/tests/unit/AttributeResolverTest.php index 124b56e4..ae07cdf7 100644 --- a/tests/unit/AttributeResolverTest.php +++ b/tests/unit/AttributeResolverTest.php @@ -59,7 +59,7 @@ public function testResolve(string $schemaName, Schema $openApiSchema, DbModel $ $schema = new ComponentSchema($openApiSchema, $schemaName); $resolver = new AttributeResolver($schemaName, $schema, new JunctionSchemas([])); $model = $resolver->resolve(); - echo $schemaName . PHP_EOL; + //echo $schemaName . PHP_EOL; self::assertEquals($expected->name, $model->name); self::assertEquals($expected->tableName, $model->tableName); self::assertEquals($expected->description, $model->description); diff --git a/tests/unit/MigrationsGeneratorTest.php b/tests/unit/MigrationsGeneratorTest.php index 440502a9..a74a7434 100644 --- a/tests/unit/MigrationsGeneratorTest.php +++ b/tests/unit/MigrationsGeneratorTest.php @@ -148,7 +148,7 @@ public function simpleDbModelsProviderForNonMysqlDb():array '$this->createTable(\'{{%dummy}}\', [ \'id\' => $this->primaryKey(), \'title\' => $this->string(60)->notNull(), - \'article\' => $this->text()->null()->defaultValue(""), + \'article\' => $this->text()->null()->defaultValue(\'\'), ]);', "\$this->createIndex('dummy_title_index', '{{%dummy}}', 'title', false);", "\$this->createIndex('dummy_article_hash_index', '{{%dummy}}', 'article', 'hash');",