Skip to content

Commit 039af2b

Browse files
committed
Change lot of tests 4 - Fix failing tests + Add docs
1 parent 60779f6 commit 039af2b

22 files changed

+217
-211
lines changed

README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,13 @@ User:
597597
598598
## Handling of `NOT NULL` constraints
599599
600-
`NOT NULL` in DB migrations is determined by `nullable` and `required` properties of the OpenAPI schema.
600+
`NOT NULL` in DB migrations is determined by `nullable` properties of the OpenAPI schema.
601601
e.g. attribute = 'my_property'.
602602
603603
- If you define attribute neither "required" nor via "nullable", then it is by default `NOT NULL` ([as per OpenAPI spec](https://github.com/OAI/OpenAPI-Specification/blob/main/proposals/2019-10-31-Clarify-Nullable.md)):
604+
- `nullable` and `required` of OpenAPI spec is not related. They have separate purpose.
605+
- `nullable` will help in creating migrations ([`null()`](https://www.yiiframework.com/doc/api/2.0/yii-db-columnschemabuilder#null()-detail) and [`notNull()`](https://www.yiiframework.com/doc/api/2.0/yii-db-columnschemabuilder#notNull()-detail)) only
606+
- `required` will help in creating model validation rules only
604607
605608
```yaml
606609
ExampleSchema:
@@ -609,7 +612,7 @@ e.g. attribute = 'my_property'.
609612
type: string
610613
```
611614

612-
- If you define attribute in "required", then it is `NOT NULL`
615+
- In below example, if you define attribute in "required", then it is `NOT NULL`, because `nullable` is present and it defaults to `false`
613616

614617
```yaml
615618
ExampleSchema:
@@ -620,7 +623,7 @@ e.g. attribute = 'my_property'.
620623
type: string
621624
```
622625
623-
- If you define attribute via "nullable", then it overrides "required", e.g. allow `NULL` in this case:
626+
- If you define attribute via "nullable", e.g. allow `NULL` in this case:
624627

625628
```yaml
626629
ExampleSchema:
@@ -632,7 +635,7 @@ e.g. attribute = 'my_property'.
632635
nullable: true
633636
```
634637

635-
- If you define attribute via "nullable", then it overrides "required", e.g. `NOT NULL` in this case:
638+
- If you define attribute via "nullable" e.g. `NOT NULL` in this case:
636639

637640
```yaml
638641
test_table:

tests/specs/blog_v2/migrations_mysql_db/m200000_000005_change_table_v2_comments.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class m200000_000005_change_table_v2_comments extends \yii\db\Migration
77
{
88
public function up()
99
{
10-
$this->dropForeignKey('fk_v2_comments_author_id_v2_users_id', '{{%v2_comments}}');
1110
$this->dropForeignKey('fk_v2_comments_post_id_v2_posts_uid', '{{%v2_comments}}');
11+
$this->dropForeignKey('fk_v2_comments_author_id_v2_users_id', '{{%v2_comments}}');
1212
$this->addColumn('{{%v2_comments}}', 'user_id', $this->bigInteger()->notNull()->after('post_id')->comment('The User'));
1313
$this->dropColumn('{{%v2_comments}}', 'author_id');
1414
$this->alterColumn('{{%v2_comments}}', 'message', $this->text()->notNull());
@@ -27,7 +27,7 @@ public function down()
2727
$this->alterColumn('{{%v2_comments}}', 'message', 'json NOT NULL');
2828
$this->addColumn('{{%v2_comments}}', 'author_id', $this->integer()->notNull()->after('post_id'));
2929
$this->dropColumn('{{%v2_comments}}', 'user_id');
30-
$this->addForeignKey('fk_v2_comments_post_id_v2_posts_uid', '{{%v2_comments}}', 'post_id', 'itt_v2_posts', 'uid');
3130
$this->addForeignKey('fk_v2_comments_author_id_v2_users_id', '{{%v2_comments}}', 'author_id', 'itt_v2_users', 'id');
31+
$this->addForeignKey('fk_v2_comments_post_id_v2_posts_uid', '{{%v2_comments}}', 'post_id', 'itt_v2_posts', 'uid');
3232
}
3333
}

tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000000_create_table_alldbdatatypes.php

+37-37
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,48 @@ public function up()
99
{
1010
$this->createTable('{{%alldbdatatypes}}', [
1111
'id' => $this->bigPrimaryKey(),
12-
0 => 'string_col varchar(255) NULL DEFAULT NULL',
13-
1 => 'varchar_col varchar(132) NULL DEFAULT NULL',
14-
2 => 'text_col text NULL DEFAULT NULL',
15-
3 => 'varchar_4_col varchar(4) NULL DEFAULT NULL',
16-
4 => 'char_4_col char(4) NULL DEFAULT NULL',
17-
5 => 'char_5_col char NULL DEFAULT NULL',
12+
0 => 'string_col varchar(255) NOT NULL',
13+
1 => 'varchar_col varchar(132) NOT NULL',
14+
2 => 'text_col text NOT NULL',
15+
3 => 'varchar_4_col varchar(4) NOT NULL',
16+
4 => 'char_4_col char(4) NOT NULL',
17+
5 => 'char_5_col char NOT NULL',
1818
6 => 'char_6_col char NOT NULL',
1919
7 => 'char_7_col char(6) NOT NULL',
20-
8 => 'char_8_col char NULL DEFAULT \'d\'',
21-
9 => 'decimal_col decimal(12,3) NULL DEFAULT NULL',
22-
10 => 'varbinary_col varbinary(5) NULL DEFAULT NULL',
23-
11 => 'blob_col blob NULL DEFAULT NULL',
24-
12 => 'bit_col bit NULL DEFAULT NULL',
25-
13 => 'bit_2 bit(1) NULL DEFAULT NULL',
26-
14 => 'bit_3 bit(64) NULL DEFAULT NULL',
27-
15 => 'ti tinyint NULL DEFAULT NULL',
28-
16 => 'ti_2 tinyint(1) NULL DEFAULT NULL',
29-
17 => 'ti_3 tinyint(2) NULL DEFAULT NULL',
30-
18 => 'si_col smallint NULL DEFAULT NULL',
31-
19 => 'si_col_2 smallint unsigned zerofill NULL DEFAULT NULL',
32-
20 => 'mi mediumint(10) unsigned zerofill comment "comment" NULL DEFAULT 7',
33-
21 => 'bi bigint NULL DEFAULT NULL',
34-
22 => 'int_col int NULL DEFAULT NULL',
35-
23 => 'int_col_2 integer NULL DEFAULT NULL',
36-
24 => 'numeric_col numeric NULL DEFAULT NULL',
37-
25 => 'float_col float NULL DEFAULT NULL',
38-
26 => 'float_2 float(10, 2) NULL DEFAULT NULL',
39-
27 => 'float_3 float(8) NULL DEFAULT NULL',
40-
28 => 'double_col double NULL DEFAULT NULL',
41-
29 => 'double_p double precision(10,2) NULL DEFAULT NULL',
42-
30 => 'double_p_2 double precision NULL DEFAULT NULL',
43-
31 => 'real_col real NULL DEFAULT NULL',
44-
32 => 'date_col date NULL DEFAULT NULL',
45-
33 => 'time_col time NULL DEFAULT NULL',
46-
34 => 'datetime_col datetime NULL DEFAULT NULL',
47-
35 => 'timestamp_col timestamp NULL DEFAULT NULL',
48-
36 => 'year_col year NULL DEFAULT NULL',
20+
8 => 'char_8_col char NOT NULL DEFAULT \'d\'',
21+
9 => 'decimal_col decimal(12,3) NOT NULL',
22+
10 => 'varbinary_col varbinary(5) NOT NULL',
23+
11 => 'blob_col blob NOT NULL',
24+
12 => 'bit_col bit NOT NULL',
25+
13 => 'bit_2 bit(1) NOT NULL',
26+
14 => 'bit_3 bit(64) NOT NULL',
27+
15 => 'ti tinyint NOT NULL',
28+
16 => 'ti_2 tinyint(1) NOT NULL',
29+
17 => 'ti_3 tinyint(2) NOT NULL',
30+
18 => 'si_col smallint NOT NULL',
31+
19 => 'si_col_2 smallint unsigned zerofill NOT NULL',
32+
20 => 'mi mediumint(10) unsigned zerofill comment "comment" NOT NULL DEFAULT 7',
33+
21 => 'bi bigint NOT NULL',
34+
22 => 'int_col int NOT NULL',
35+
23 => 'int_col_2 integer NOT NULL',
36+
24 => 'numeric_col numeric NOT NULL',
37+
25 => 'float_col float NOT NULL',
38+
26 => 'float_2 float(10, 2) NOT NULL',
39+
27 => 'float_3 float(8) NOT NULL',
40+
28 => 'double_col double NOT NULL',
41+
29 => 'double_p double precision(10,2) NOT NULL',
42+
30 => 'double_p_2 double precision NOT NULL',
43+
31 => 'real_col real NOT NULL',
44+
32 => 'date_col date NOT NULL',
45+
33 => 'time_col time NOT NULL',
46+
34 => 'datetime_col datetime NOT NULL',
47+
35 => 'timestamp_col timestamp NOT NULL',
48+
36 => 'year_col year NOT NULL',
4949
37 => 'json_col json NOT NULL',
5050
38 => 'json_col_def json NOT NULL DEFAULT \'[]\'',
5151
39 => 'json_col_def_2 json NOT NULL DEFAULT \'[]\'',
52-
40 => 'blob_def blob NULL DEFAULT \'the blob\'',
53-
41 => 'text_def text NULL DEFAULT \'the text\'',
52+
40 => 'blob_def blob NOT NULL DEFAULT \'the blob\'',
53+
41 => 'text_def text NOT NULL DEFAULT \'the text\'',
5454
42 => 'json_def json NOT NULL DEFAULT \'{"a":"b"}\'',
5555
]);
5656
}

tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000001_change_table_editcolumns.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ class m200000_000001_change_table_editcolumns extends \yii\db\Migration
77
{
88
public function up()
99
{
10-
$this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN first_name varchar(255) NULL DEFAULT NULL AFTER tag')->execute();
10+
$this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN first_name varchar(255) NOT NULL AFTER tag')->execute();
1111
$this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN json_col_def_n json NOT NULL DEFAULT \'[]\' AFTER numeric_col')->execute();
1212
$this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN json_col_def_n_2 json NOT NULL DEFAULT \'[]\'')->execute();
1313
$this->alterColumn('{{%editcolumns}}', 'name', $this->string(255)->notNull()->defaultValue('Horse-2'));
1414
$this->alterColumn('{{%editcolumns}}', 'string_col', $this->text()->null()->defaultValue(null));
15-
$this->alterColumn('{{%editcolumns}}', 'dec_col', $this->decimal(12,2)->null()->defaultValue("3.14"));
15+
$this->alterColumn('{{%editcolumns}}', 'dec_col', $this->decimal(12,2)->notNull()->defaultValue("3.14"));
1616
$this->alterColumn('{{%editcolumns}}', 'str_col_def', $this->string(3)->notNull());
1717
$this->alterColumn('{{%editcolumns}}', 'json_col', $this->text()->notNull()->defaultValue('fox jumps over dog'));
1818
$this->alterColumn('{{%editcolumns}}', 'json_col_2', 'json NOT NULL DEFAULT \'[]\'');
19-
$this->alterColumn('{{%editcolumns}}', 'numeric_col', $this->double()->null()->defaultValue(null));
19+
$this->alterColumn('{{%editcolumns}}', 'numeric_col', $this->double()->notNull());
2020
}
2121

2222
public function down()

tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000002_create_table_newcolumns.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public function up()
1010
$this->createTable('{{%newcolumns}}', [
1111
'id' => $this->primaryKey(),
1212
0 => 'name varchar(255) NOT NULL',
13-
'last_name' => $this->text()->null()->defaultValue(null),
14-
1 => 'dec_col decimal(12,4) NULL DEFAULT NULL',
13+
'last_name' => $this->text()->notNull(),
14+
1 => 'dec_col decimal(12,4) NOT NULL',
1515
2 => 'json_col json NOT NULL',
16-
3 => 'varchar_col varchar(5) NULL DEFAULT NULL',
17-
4 => 'numeric_col double precision NULL DEFAULT NULL',
16+
3 => 'varchar_col varchar(5) NOT NULL',
17+
4 => 'numeric_col double precision NOT NULL',
1818
5 => 'json_col_def_n json NOT NULL DEFAULT \'[]\'',
1919
]);
2020
}

tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000003_create_table_pristines.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ public function up()
1010
$this->createTable('{{%pristines}}', [
1111
0 => 'custom_id_col integer primary key auto_increment NOT NULL',
1212
1 => 'name text NOT NULL',
13-
'tag' => $this->text()->null()->defaultValue('4 leg'),
14-
2 => 'new_col varchar(17) NULL DEFAULT NULL',
15-
3 => 'col_5 decimal(12,4) NULL DEFAULT NULL',
16-
4 => 'col_6 decimal(11,2) NULL DEFAULT NULL',
17-
5 => 'col_7 decimal(10,2) NULL DEFAULT NULL',
13+
'tag' => $this->text()->notNull()->defaultValue('4 leg'),
14+
2 => 'new_col varchar(17) NOT NULL',
15+
3 => 'col_5 decimal(12,4) NOT NULL',
16+
4 => 'col_6 decimal(11,2) NOT NULL',
17+
5 => 'col_7 decimal(10,2) NOT NULL',
1818
6 => 'col_8 json NOT NULL',
19-
7 => 'col_9 varchar(9) NULL DEFAULT NULL',
20-
8 => 'col_10 varchar(10) NULL DEFAULT NULL',
21-
9 => 'col_11 text NULL DEFAULT NULL',
22-
10 => 'price decimal(10,2) NULL DEFAULT 0 COMMENT \'price in EUR\'',
19+
7 => 'col_9 varchar(9) NOT NULL',
20+
8 => 'col_10 varchar(10) NOT NULL',
21+
9 => 'col_11 text NOT NULL',
22+
10 => 'price decimal(10,2) NOT NULL DEFAULT 0 COMMENT \'price in EUR\'',
2323
]);
2424
}
2525

tests/specs/x_db_type/edit_column/mysql/app/migrations_mysql_db/m200000_000000_create_table_alldbdatatypes.php

+37-37
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,48 @@ public function up()
99
{
1010
$this->createTable('{{%alldbdatatypes}}', [
1111
'id' => $this->bigPrimaryKey(),
12-
0 => 'string_col varchar(255) NULL DEFAULT NULL',
13-
1 => 'varchar_col varchar(132) NULL DEFAULT NULL',
14-
2 => 'text_col text NULL',
15-
3 => 'varchar_4_col varchar(4) NULL DEFAULT NULL',
16-
4 => 'char_4_col char(4) NULL DEFAULT NULL',
17-
5 => 'char_5_col char NULL DEFAULT NULL',
12+
0 => 'string_col varchar(255) NOT NULL',
13+
1 => 'varchar_col varchar(132) NOT NULL',
14+
2 => 'text_col text NOT NULL',
15+
3 => 'varchar_4_col varchar(4) NOT NULL',
16+
4 => 'char_4_col char(4) NOT NULL',
17+
5 => 'char_5_col char NOT NULL',
1818
6 => 'char_6_col char NOT NULL',
1919
7 => 'char_7_col char(6) NOT NULL',
20-
8 => 'char_8_col char NULL DEFAULT \'d\'',
21-
9 => 'decimal_col decimal(12,3) NULL DEFAULT NULL',
22-
10 => 'varbinary_col varbinary(5) NULL DEFAULT NULL',
23-
11 => 'blob_col blob NULL',
24-
12 => 'bit_col bit NULL DEFAULT NULL',
25-
13 => 'bit_2 bit(1) NULL DEFAULT NULL',
26-
14 => 'bit_3 bit(64) NULL DEFAULT NULL',
27-
15 => 'ti tinyint NULL DEFAULT NULL',
28-
16 => 'ti_2 tinyint(1) NULL DEFAULT NULL',
29-
17 => 'ti_3 tinyint(2) NULL DEFAULT NULL',
30-
18 => 'si_col smallint NULL DEFAULT NULL',
31-
19 => 'si_col_2 smallint unsigned zerofill NULL DEFAULT NULL',
32-
20 => 'mi mediumint(10) unsigned zerofill comment "comment" NULL DEFAULT 7',
33-
21 => 'bi bigint NULL DEFAULT NULL',
34-
22 => 'int_col int NULL DEFAULT NULL',
35-
23 => 'int_col_2 integer NULL DEFAULT NULL',
36-
24 => 'numeric_col numeric NULL DEFAULT NULL',
37-
25 => 'float_col float NULL DEFAULT NULL',
38-
26 => 'float_2 float(10, 2) NULL DEFAULT NULL',
39-
27 => 'float_3 float(8) NULL DEFAULT NULL',
40-
28 => 'double_col double NULL DEFAULT NULL',
41-
29 => 'double_p double precision(10,2) NULL DEFAULT NULL',
42-
30 => 'double_p_2 double precision NULL DEFAULT NULL',
43-
31 => 'real_col real NULL DEFAULT NULL',
44-
32 => 'date_col date NULL DEFAULT NULL',
45-
33 => 'time_col time NULL DEFAULT NULL',
46-
34 => 'datetime_col datetime NULL DEFAULT NULL',
47-
35 => 'timestamp_col timestamp NULL DEFAULT NULL',
48-
36 => 'year_col year NULL DEFAULT NULL',
20+
8 => 'char_8_col char NOT NULL DEFAULT \'d\'',
21+
9 => 'decimal_col decimal(12,3) NOT NULL',
22+
10 => 'varbinary_col varbinary(5) NOT NULL',
23+
11 => 'blob_col blob NOT NULL',
24+
12 => 'bit_col bit NOT NULL',
25+
13 => 'bit_2 bit(1) NOT NULL',
26+
14 => 'bit_3 bit(64) NOT NULL',
27+
15 => 'ti tinyint NOT NULL',
28+
16 => 'ti_2 tinyint(1) NOT NULL',
29+
17 => 'ti_3 tinyint(2) NOT NULL',
30+
18 => 'si_col smallint NOT NULL',
31+
19 => 'si_col_2 smallint unsigned zerofill NOT NULL',
32+
20 => 'mi mediumint(10) unsigned zerofill comment "comment" NOT NULL DEFAULT 7',
33+
21 => 'bi bigint NOT NULL',
34+
22 => 'int_col int NOT NULL',
35+
23 => 'int_col_2 integer NOT NULL',
36+
24 => 'numeric_col numeric NOT NULL',
37+
25 => 'float_col float NOT NULL',
38+
26 => 'float_2 float(10, 2) NOT NULL',
39+
27 => 'float_3 float(8) NOT NULL',
40+
28 => 'double_col double NOT NULL',
41+
29 => 'double_p double precision(10,2) NOT NULL',
42+
30 => 'double_p_2 double precision NOT NULL',
43+
31 => 'real_col real NOT NULL',
44+
32 => 'date_col date NOT NULL',
45+
33 => 'time_col time NOT NULL',
46+
34 => 'datetime_col datetime NOT NULL',
47+
35 => 'timestamp_col timestamp NOT NULL',
48+
36 => 'year_col year NOT NULL',
4949
37 => 'json_col json NOT NULL',
5050
38 => 'json_col_def json NOT NULL',
5151
39 => 'json_col_def_2 json NOT NULL',
52-
40 => 'blob_def blob NULL',
53-
41 => 'text_def text NULL',
52+
40 => 'blob_def blob NOT NULL',
53+
41 => 'text_def text NOT NULL',
5454
42 => 'json_def json NOT NULL',
5555
]);
5656
}

tests/specs/x_db_type/edit_column/mysql/app/migrations_mysql_db/m200000_000001_change_table_editcolumns.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ class m200000_000001_change_table_editcolumns extends \yii\db\Migration
77
{
88
public function up()
99
{
10-
$this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN first_name varchar(255) NULL DEFAULT NULL AFTER tag')->execute();
10+
$this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN first_name varchar(255) NOT NULL AFTER tag')->execute();
1111
$this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN json_col_def_n json NOT NULL AFTER numeric_col')->execute();
1212
$this->db->createCommand('ALTER TABLE {{%editcolumns}} ADD COLUMN json_col_def_n_2 json NOT NULL')->execute();
1313
$this->alterColumn('{{%editcolumns}}', 'name', $this->string(255)->notNull()->defaultValue('Horse-2'));
1414
$this->alterColumn('{{%editcolumns}}', 'string_col', $this->text()->null());
15-
$this->alterColumn('{{%editcolumns}}', 'dec_col', $this->decimal(12,2)->null()->defaultValue("3.14"));
15+
$this->alterColumn('{{%editcolumns}}', 'dec_col', $this->decimal(12,2)->notNull()->defaultValue("3.14"));
1616
$this->alterColumn('{{%editcolumns}}', 'str_col_def', $this->string(3)->notNull());
1717
$this->alterColumn('{{%editcolumns}}', 'json_col', $this->text()->notNull());
1818
$this->alterColumn('{{%editcolumns}}', 'json_col_2', 'json NOT NULL');
19-
$this->alterColumn('{{%editcolumns}}', 'numeric_col', $this->double()->null()->defaultValue(null));
19+
$this->alterColumn('{{%editcolumns}}', 'numeric_col', $this->double()->notNull());
2020
}
2121

2222
public function down()

tests/specs/x_db_type/edit_column/mysql/app/migrations_mysql_db/m200000_000003_create_table_pristines.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ public function up()
1010
$this->createTable('{{%pristines}}', [
1111
0 => 'custom_id_col integer primary key auto_increment NOT NULL',
1212
1 => 'name text NOT NULL',
13-
'tag' => $this->text()->null(),
14-
2 => 'new_col varchar(17) NULL DEFAULT NULL',
15-
3 => 'col_5 decimal(12,4) NULL DEFAULT NULL',
16-
4 => 'col_6 decimal(11,2) NULL DEFAULT NULL',
17-
5 => 'col_7 decimal(10,2) NULL DEFAULT NULL',
13+
'tag' => $this->text()->notNull(),
14+
2 => 'new_col varchar(17) NOT NULL',
15+
3 => 'col_5 decimal(12,4) NOT NULL',
16+
4 => 'col_6 decimal(11,2) NOT NULL',
17+
5 => 'col_7 decimal(10,2) NOT NULL',
1818
6 => 'col_8 json NOT NULL',
19-
7 => 'col_9 varchar(9) NULL DEFAULT NULL',
20-
8 => 'col_10 varchar(10) NULL DEFAULT NULL',
21-
9 => 'col_11 text NULL',
22-
10 => 'price decimal(10,2) NULL DEFAULT 0 COMMENT \'price in EUR\'',
19+
7 => 'col_9 varchar(9) NOT NULL',
20+
8 => 'col_10 varchar(10) NOT NULL',
21+
9 => 'col_11 text NOT NULL',
22+
10 => 'price decimal(10,2) NOT NULL DEFAULT 0 COMMENT \'price in EUR\'',
2323
]);
2424
}
2525

0 commit comments

Comments
 (0)