pgroll/examples/22_add_check_constraint.json
Andrew Farries c1b8c65dd5
Make naming CHECK constraints mandatory (#99)
Make it required to supply a name for the `CHECK` constraint when adding
one with the `set_check_constraint` operation.

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
https://github.com/xataio/pg-roll/pull/59
2023-09-14 11:06:13 +01:00

16 lines
360 B
JSON

{
"name": "22_add_check_constraint",
"operations": [
{
"alter_column": {
"table": "posts",
"column": "title",
"constraint_name": "title_length",
"check": "length(title) > 3",
"up": "(SELECT CASE WHEN length(title) <= 3 THEN LPAD(title, 4, '-') ELSE title END)",
"down": "title"
}
}
]
}