xataio / pgroll

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

Reconsider using `nullable` over `not_null` #491

Open andrew-farries opened 4 days ago

andrew-farries commented 4 days ago

In #132 it was decided to use nullable over not_null to set column nullability in create_table, add_column and alter_column operations, for example:

{
  "name": "03_add_column_to_products",
  "operations": [
    {
      "add_column": {
        "table": "products",
        "up": "UPPER(name)",
        "column": {
          "name": "description",
          "type": "varchar(255)",
          "nullable": true
        }
      }
    }
  ]
}

As a breaking change before v1 we should consider whether we want to reverse this decision and use not_null instead.

Using not_null is less surprising as columns in Postgres are nullable by default, whereas by using nullable's implicit default of false we reverse this expectation.

exekias commented 4 days ago

this is entirely on me 🙏 , but I agree not_null is much better! btw, to do this backward compatible we could allow both nullable and not_null (but not both at the same time, at least if their values disagree) today. Then deprecate nullable with 1.0.