Support multiple 'alter column' sub operations (#338)
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
2024-04-22 14:11:15 +03:00
|
|
|
{
|
|
|
|
"name": "35_alter_column_multiple",
|
|
|
|
"operations": [
|
|
|
|
{
|
|
|
|
"alter_column": {
|
|
|
|
"table": "events",
|
|
|
|
"column": "name",
|
|
|
|
"name": "event_name",
|
|
|
|
"type": "text",
|
2024-04-25 13:47:44 +03:00
|
|
|
"default": "'unknown event'",
|
Support multiple 'alter column' sub operations (#338)
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
2024-04-22 14:11:15 +03:00
|
|
|
"nullable": false,
|
Add a 'set comment' sub-operation to 'alter column' (#344)
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
2024-04-29 12:40:10 +03:00
|
|
|
"comment": "the full name of the event",
|
Support multiple 'alter column' sub operations (#338)
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
2024-04-22 14:11:15 +03:00
|
|
|
"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)",
|
2024-05-16 13:57:53 +03:00
|
|
|
"down": "event_name"
|
Support multiple 'alter column' sub operations (#338)
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
2024-04-22 14:11:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|