Ensure that 'alter column' operations that rename a column and also
specify `down` SQL (such as those that alter some other column attribute
at the time of the rename) must use the new name of the column in the
`down` SQL.
Without this change, the `down` SQL would require the use of the old
column name.
Fixes#350
Allow 'alter column' operations to set the comment on a column:
```json
{
"name": "02_change_comment",
"operations": [
{
"alter_column": {
"table": "events",
"column": "name",
"comment": "The full name of the event"
}
}
]
}
```
This is a versioned migration so the column to which the comment is
applied is duplicated and backfilled according to the `up` and `down`
SQL supplied with the 'alter column' operation. `up` and `down` default
to a simple copy of the field between new and old columns.
The intention is that this can be combined with a 'change type'
sub-operation if there is some column metadata that should be updated as
part of the type change:
```json
{
"name": "35_alter_column_multiple",
"operations": [
{
"alter_column": {
"table": "events",
"column": "name",
"name": "event_name",
"type": "text",
"comment": "{type: some-metadata}",
"up": "name",
"down": "name"
}
}
]
}
```
Fixes#328
Allow 'alter column' operations to set the default value on a column:
```json
{
"name": "02_change_default",
"operations": [
{
"alter_column": {
"table": "events",
"column": "name",
"default": "'new default value'"
}
}
]
}
```
This is a versioned migration so the column to which the default is
applied is duplicated and backfilled according to the `up` and `down`
SQL supplied with the 'alter column' operation. `up` and `down` default
to a simple copy of the field between new and old columns.
Fixes#327
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