-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for primary key constraints in
create_table
operation (#…
…594) This PR adds support for setting primary key constraints in the `constraints` option of `create_table`. Please note that if you set primary keys in `columns`, you are not allowed to configure `primary_key` constraints. Example: ```json { "name": "50_create_table_with_table_constraint", "operations": [ { "create_table": { "name": "phonebook", "columns": [ { "name": "id", "type": "serial", }, { "name": "name", "type": "varchar(255)" } ], "constraints": [ { "name": "my_pk", "type": "primary_key", "columns": [ "id" ] } ] } } ] } ```
- Loading branch information
Showing
14 changed files
with
347 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...nal/jsonschema/testdata/create-table-10-invalid-primary-key-constraints-extra-check.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
This is an invalid 'create_table' migration. | ||
Primary key constraint must not constain a check expression. | ||
|
||
-- create_table.json -- | ||
{ | ||
"name": "migration_name", | ||
"operations": [ | ||
{ | ||
"create_table": { | ||
"name": "posts", | ||
"columns": [ | ||
{ | ||
"name": "title", | ||
"type": "varchar(255)" | ||
}, | ||
{ | ||
"name": "user_id", | ||
"type": "integer", | ||
"nullable": true | ||
} | ||
], | ||
"constraints": [ | ||
{ | ||
"name": "my_invalid_pk", | ||
"type": "primary_key", | ||
"columns": [ | ||
"title" | ||
], | ||
"check": "this should not be set" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
|
||
-- valid -- | ||
false |
34 changes: 34 additions & 0 deletions
34
...jsonschema/testdata/create-table-11-invalid-primary-key-constraints-missing-columns.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
This is an invalid 'create_table' migration. | ||
Primary key constraint must have columns set | ||
|
||
-- create_table.json -- | ||
{ | ||
"name": "migration_name", | ||
"operations": [ | ||
{ | ||
"create_table": { | ||
"name": "posts", | ||
"columns": [ | ||
{ | ||
"name": "title", | ||
"type": "varchar(255)" | ||
}, | ||
{ | ||
"name": "user_id", | ||
"type": "integer", | ||
"nullable": true | ||
} | ||
], | ||
"constraints": [ | ||
{ | ||
"name": "my_invalid_pk", | ||
"type": "primary_key" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
|
||
-- valid -- | ||
false |
36 changes: 36 additions & 0 deletions
36
internal/jsonschema/testdata/create-table-12-valid-primary-key-constraint.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
This is a valid 'create_table' migration. | ||
|
||
-- create_table.json -- | ||
{ | ||
"name": "migration_name", | ||
"operations": [ | ||
{ | ||
"create_table": { | ||
"name": "posts", | ||
"columns": [ | ||
{ | ||
"name": "title", | ||
"type": "varchar(255)" | ||
}, | ||
{ | ||
"name": "user_id", | ||
"type": "integer" | ||
} | ||
], | ||
"constraints": [ | ||
{ | ||
"name": "my_pk", | ||
"type": "primary_key", | ||
"columns": [ | ||
"title", | ||
"user_id" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
|
||
-- valid -- | ||
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.