xataio / pgroll

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

Alter column operations should allow specification of unchanged fields #339

Open andrew-farries opened 4 months ago

andrew-farries commented 4 months ago

Alter column operations should support specifying fields that are unchanged as no-ops.

For example, this migration:

{
  "name": "35_alter_column_multiple",
  "operations": [
    {
      "alter_column": {
        "table": "events",
        "column": "name",
        "name": "event_name",
        "nullable": false,
        "up": "(SELECT CASE WHEN name IS NULL THEN 'placeholder' ELSE name END)",
        "down": "name"
      }
    }
  ]
}

Renames a field and sets it to NOT NULL. If the field is already NOT NULL, the operation should not perform any column duplication or backfilling to support setting the column nullability.