mirror of
https://github.com/xataio/pgroll.git
synced 2024-09-11 13:55:28 +03:00
Allow 'alter column' operations to include multiple sub-operations. This means migrations like this one are now possible: ```json { "name": "35_alter_column_multiple", "operations": [ { "alter_column": { "table": "events", "column": "name", "name": "event_name", "type": "text", "nullable": false, "unique": { "name": "events_event_name_unique" }, "check": { "name": "event_name_length", "constraint": "length(name) > 3" }, "up": "(SELECT CASE WHEN name IS NULL THEN 'placeholder' ELSE name END)", "down": "name" } } ] } ``` This 'alter column' operation: * Renames a column * Changes its type * Sets it `NOT NULL` * Adds a unique constraint * Adds a check constraint Previously, this would have required 5 different operations. Builds on https://github.com/xataio/pgroll/pull/337. Fixes https://github.com/xataio/pgroll/issues/336
24 lines
556 B
JSON
24 lines
556 B
JSON
{
|
|
"name": "35_alter_column_multiple",
|
|
"operations": [
|
|
{
|
|
"alter_column": {
|
|
"table": "events",
|
|
"column": "name",
|
|
"name": "event_name",
|
|
"type": "text",
|
|
"nullable": false,
|
|
"unique": {
|
|
"name": "events_event_name_unique"
|
|
},
|
|
"check": {
|
|
"name": "event_name_length",
|
|
"constraint": "length(name) > 3"
|
|
},
|
|
"up": "(SELECT CASE WHEN name IS NULL OR LENGTH(name) <= 3 THEN 'placeholder' ELSE name END)",
|
|
"down": "name"
|
|
}
|
|
}
|
|
]
|
|
}
|