-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
constraints
option to create_table
and unique
constraint su…
…pport (#585) This PR adds support for a new option of `create_table` operation named `constraints`. It expects a list of `constraints` that is defined on the table when the table is created. At the moment the only constraint we support is `unique`. But it includes support for all options of unique constraints including `NULLS NOT DISTINCT`, index configuration settings, constraint deference, etc. Once I am done with these table constraints, I will open a follow-up PR to extend the constraint options for column constraints and `create_constraint` operation. Example migration: ```json { "name": "50_create_table_with_table_constraint", "operations": [ { "create_table": { "name": "phonebook", "columns": [ { "name": "id", "type": "serial", "pk": true }, { "name": "name", "type": "varchar(255)" }, { "name": "city", "type": "varchar(255)" }, { "name": "phone", "type": "varchar(255)" } ], "constraints": [ { "name": "unique_numbers", "type": "unique", "columns": ["phone"], "index_parameters": { "include_columns": ["name"] } } ] } } ] } ``` The table definition above turns into this table in PostgreSQL: ``` postgres=# \d phonebook Table "public.phonebook" Column | Type | Collation | Nullable | Default --------+------------------------+-----------+----------+--------------------------------------- id | integer | | not null | nextval('phonebook_id_seq'::regclass) name | character varying(255) | | not null | city | character varying(255) | | not null | phone | character varying(255) | | not null | Indexes: "phonebook_pkey" PRIMARY KEY, btree (id) "unique_numbers" UNIQUE CONSTRAINT, btree (phone) INCLUDE (name) ``` Part of #580
- Loading branch information
Showing
10 changed files
with
535 additions
and
10 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
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,43 @@ | ||
{ | ||
"name": "50_create_table_with_table_constraint", | ||
"operations": [ | ||
{ | ||
"create_table": { | ||
"name": "phonebook", | ||
"columns": [ | ||
{ | ||
"name": "id", | ||
"type": "serial", | ||
"pk": true | ||
}, | ||
{ | ||
"name": "name", | ||
"type": "varchar(255)" | ||
}, | ||
{ | ||
"name": "city", | ||
"type": "varchar(255)" | ||
}, | ||
{ | ||
"name": "phone", | ||
"type": "varchar(255)" | ||
} | ||
], | ||
"constraints": [ | ||
{ | ||
"name": "unique_numbers", | ||
"type": "unique", | ||
"columns": [ | ||
"phone" | ||
], | ||
"index_parameters": { | ||
"include_columns": [ | ||
"name" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
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.