-
Notifications
You must be signed in to change notification settings - Fork 106
Description
Provide a way to allow the up
SQL to be verified for correctness before performing any DDL operations.
For example, in this add CHECK
constraint migration:
{
"name": "22_add_check_constraint",
"operations": [
{
"alter_column": {
"table": "posts",
"column": "title",
"check": {
"name": "title_length",
"constraint": "length(title) > 3"
},
"up": "(SELECT CASE WHEN length(title) <= 3 THEN LPAD(title, 4, '-') ELSE title END)",
"down": "title"
}
}
]
}
The up
SQL ensures that any title
values written to the old schema will be rewritten to match the CHECK
constraint in the new schema. It is the migration author's responsibility to ensure that this SQL works and produces a value that really does satisfy the constraint. If the up
SQL fails then the backfill operation on start will fail and the migration will be rolled back.
Having a way to test the up
SQL against all (or a subset) of the values in the table before performing any DDL operations would provide a better user experience and help migration authors validate migrations before execution.