-
Notifications
You must be signed in to change notification settings - Fork 48
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
Support creating foreign key constraints on the create table operation #79
Conversation
Allow references on columns in `CREATE TABLE` operations so that foreign keys can be created.
Unique bool `json:"unique"` | ||
PrimaryKey bool `json:"pk"` | ||
Default *string `json:"default"` | ||
References *ColumnReference `json:"references"` |
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.
I wonder if we should make this part of the column definition or the table. The reason is that foreign keys can also be a constraint at the table level, and they can reference several columns instead of just one.
I guess we are fine with this for now and we can allow foreign key definition at the table level later? It would definitely be needed to support multi column foreign keys
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.
I've created #81 to track multi-column foreign keys.
#80) Allow the **add column** operation to create foreign key columns. An example of such an operation is: ```json { "name": "17_add_rating_column", "operations": [ { "add_column": { "table": "orders", "column": { "name": "user_id", "type": "integer", "references": { "table": "users", "column": "id", } } } } ] } ``` Most of the work to support the operation is in #79. * The constraint is added on `Start` (named according to the temporary name of the new column). * The entire new column, including the foreign key constraint, is removed on `Rollback`. * The constraint is renamed to use the final name of the new column on `Complete`. Test cases are included for both nullable and non-nullable FKs.
Allow creating foreign key columns when doing a create table operation. For example:
Here the
user_id
column references theid
column in theusers
table.The constraint is added to the table on
Start
and removed onRollback
.