xataio / pgroll

PostgreSQL zero-downtime migrations made easy
https://www.xata.io
Apache License 2.0
2.97k stars 54 forks source link

Add a 'set comment' sub-operation to 'alter column' #344

Closed andrew-farries closed 4 months ago

andrew-farries commented 4 months ago

Allow 'alter column' operations to set the comment on a column:

{
  "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:

{
  "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