-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add constraints
option to create_table
and unique
constraint support
#585
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good 👍 I left some comments.
I haven't had time to review the sql2pgroll
part of the changes yet, will review that as soon as I can.
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.
Thanks, I was going to ask about potential duplication between the Constraint
type added in this behaviour and the kinds of constraints that are possible via OpAlterColumn
.
constraint += fmt.Sprintf("UNIQUE %s (%s)", nullsDistinct, strings.Join(quoteColumnNames(w.Columns), ", ")) | ||
constraint += w.addIndexParameters() | ||
constraint += w.addDeferrable() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional: we could use strings.Builder
and pass it to the addIndexParameters
and addDeferrable
methods to avoid all the string concatenation.
@@ -47,3 +47,4 @@ | |||
47_add_table_foreign_key_constraint.json | |||
48_drop_tickets_check.json | |||
49_unset_not_null_on_indexed_column.json | |||
50_create_table_with_table_constraint.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be updated because I have another example in a PR....
This PR adds support for a new option of
create_table
operation namedconstraints
.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 optionsof 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 andcreate_constraint
operation.Example migration:
The table definition above turns into this table in PostgreSQL:
Part of #580