Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple backfill-requiring changes to the same column in a single migration #659

Open
andrew-farries opened this issue Feb 6, 2025 · 0 comments

Comments

@andrew-farries
Copy link
Collaborator

andrew-farries commented Feb 6, 2025

A migration that contains multiple backfill-requiring operations on the same column will currently fail.

Fixing this is probably a large change to how pgroll works - currently operations are largely independent of one another. To make this work, column duplication and trigger creation would have to move out of the individual operations happen after all operations have Started.

Reproduction

Create a table:

{
  "name": "01_create_table",
  "operations": [
    {
      "create_table": {
        "name": "items",
        "columns": [
          {
            "name": "id",
            "type": "serial",
            "pk": true
          },
          {
            "name": "name",
            "type": "text",
            "check": {
              "name": "name_not_empty",
              "constraint": "name <> ''"
            }
          }
        ]
      }
    }
  ]
}

Then run a migration that removes a constraint from the name column and sets its nullability:

{
  "name": "14_multiple_ops",
  "operations": [
    {
      "drop_multicolumn_constraint": {
        "table": "items",
        "name": "name_not_empty",
        "down": {
          "name": "name"
        }
      }
    },
    {
      "alter_column": {
        "table": "items",
        "column": "name",
        "nullable": true,
        "up": "name",
        "down": "name"
      }
    }
  ]
}

The migration fails because both operations attempt to duplicate the name column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant