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 default' sub-operation to 'alter column' #346

Closed andrew-farries closed 4 months ago

andrew-farries commented 4 months ago

Allow 'alter column' operations to set the default value on a column:

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