Skip to content

Commit 2fad908

Browse files
committed
add more jsonschema tests
1 parent 462c3a6 commit 2fad908

6 files changed

+124
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
This is an invalid 'create_constraint' migration.
2+
Foreign key constraints cannot configure nulls_not_distinct.
3+
4+
-- create_constraint.json --
5+
{
6+
"name": "migration_name",
7+
"operations": [
8+
{
9+
"create_constraint": {
10+
"name": "my_invalid_check",
11+
"table": "my_table",
12+
"type": "foreign_key",
13+
"nulls_not_distinct": true,
14+
"references": {
15+
"columns": ["title"],
16+
"table": "referenced",
17+
"on_delete": "CASCADE",
18+
"on_update": "SET NULL"
19+
},
20+
"columns": [
21+
"my_column"
22+
],
23+
"up": {
24+
"my_column": "my_column"
25+
},
26+
"down": {
27+
"my_column": "my_column"
28+
}
29+
}
30+
}
31+
]
32+
}
33+
34+
-- valid --
35+
false
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
This is an valid 'create_constraint' migration.
2+
3+
-- create_constraint.json --
4+
{
5+
"name": "migration_name",
6+
"operations": [
7+
{
8+
"create_constraint": {
9+
"name": "my_invalid_check",
10+
"table": "my_table",
11+
"type": "unique",
12+
"nulls_not_distinct": true,
13+
"columns": [
14+
"my_column"
15+
],
16+
"up": {
17+
"my_column": "my_column"
18+
},
19+
"down": {
20+
"my_column": "my_column"
21+
}
22+
}
23+
}
24+
]
25+
}
26+
27+
-- valid --
28+
true
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
This is an invalid 'create_index' migration.
2+
Only unique indexes can set null_not_distinct.
3+
4+
-- create_index.json --
5+
{
6+
"name": "migration_name",
7+
"operations": [
8+
{
9+
"create_index": {
10+
"name": "reviews_index",
11+
"columns": {
12+
"my-column": {}
13+
},
14+
"nulls_not_distinct": true
15+
}
16+
}
17+
]
18+
}
19+
20+
-- valid --
21+
false
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
This is an valid 'create_index' migration.
2+
3+
-- create_index.json --
4+
{
5+
"name": "migration_name",
6+
"operations": [
7+
{
8+
"create_index": {
9+
"name": "reviews_index",
10+
"table": "my_table",
11+
"columns": {
12+
"my-column": {}
13+
},
14+
"unique": true,
15+
"nulls_not_distinct": true
16+
}
17+
}
18+
]
19+
}
20+
21+
-- valid --
22+
true

schema.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,24 @@
623623
"default": false
624624
}
625625
},
626+
"allOf": [
627+
{
628+
"if": {
629+
"properties": {
630+
"unique": {
631+
"const": false
632+
}
633+
}
634+
},
635+
"then": {
636+
"properties": {
637+
"nulls_not_distinct": {
638+
"const": false
639+
}
640+
}
641+
}
642+
}
643+
],
626644
"required": ["columns", "name", "table"],
627645
"type": "object"
628646
},

0 commit comments

Comments
 (0)