Commit Graph

2 Commits

Author SHA1 Message Date
Andrew Farries
bc3a574326
Make naming FOREIGN KEY constraints mandatory (#100)
Make it required to supply a name for a foreign key constraint created
in either the `create_table`, `add_column` or `set_foreign_key`
operations.

It should be possible to drop constraints with a later migration (not
yet implemented), so requiring a name and not relying on automatic
generation of constraint names will make this easier.

The same thing was done for indexes in #59 and `CHECK` constraints in
#99.
2023-09-15 11:39:17 +01:00
Andrew Farries
f94d2521f0
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 13:25:43 +01:00