Support creating foreign key constraints on the create table operation (#79)
Allow creating foreign key columns when doing a **create table**
operation. For example:
```json
{
"name": "19_create_orders_table",
"operations": [
{
"create_table": {
"name": "orders",
"columns": [
{
"name": "id",
"type": "serial",
"pk": true
},
{
"name": "user_id",
"type": "integer",
"references": {
"table": "users",
"column": "id"
}
},
{
"name": "quantity",
"type": "int"
}
]
}
}
]
}
```
Here the `user_id` column references the `id` column in the `users`
table.
The constraint is added to the table on `Start` and removed on
`Rollback`.
2023-09-05 15:25:43 +03:00
|
|
|
{
|
|
|
|
"name": "19_create_orders_table",
|
|
|
|
"operations": [
|
|
|
|
{
|
|
|
|
"create_table": {
|
|
|
|
"name": "orders",
|
|
|
|
"columns": [
|
|
|
|
{
|
|
|
|
"name": "id",
|
|
|
|
"type": "serial",
|
|
|
|
"pk": true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "user_id",
|
|
|
|
"type": "integer",
|
|
|
|
"references": {
|
2023-09-15 13:39:17 +03:00
|
|
|
"name": "fk_users_id",
|
Support creating foreign key constraints on the create table operation (#79)
Allow creating foreign key columns when doing a **create table**
operation. For example:
```json
{
"name": "19_create_orders_table",
"operations": [
{
"create_table": {
"name": "orders",
"columns": [
{
"name": "id",
"type": "serial",
"pk": true
},
{
"name": "user_id",
"type": "integer",
"references": {
"table": "users",
"column": "id"
}
},
{
"name": "quantity",
"type": "int"
}
]
}
}
]
}
```
Here the `user_id` column references the `id` column in the `users`
table.
The constraint is added to the table on `Start` and removed on
`Rollback`.
2023-09-05 15:25:43 +03:00
|
|
|
"table": "users",
|
|
|
|
"column": "id"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "quantity",
|
|
|
|
"type": "int"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|