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

Allow for migration dry-runs to verify up SQL #169

Open
andrew-farries opened this issue Oct 4, 2023 · 0 comments
Open

Allow for migration dry-runs to verify up SQL #169

andrew-farries opened this issue Oct 4, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@andrew-farries
Copy link
Collaborator

Provide a way to allow the up SQL to be verified for correctness before performing any DDL operations.

For example, in this add CHECK constraint migration:

{
  "name": "22_add_check_constraint",
  "operations": [
    {
      "alter_column": {
        "table": "posts",
        "column": "title",
        "check": {
          "name": "title_length",
          "constraint": "length(title) > 3"
        },
        "up": "(SELECT CASE WHEN length(title) <= 3 THEN LPAD(title, 4, '-') ELSE title END)",
        "down": "title"
      }
    }
  ]
}

The up SQL ensures that any title values written to the old schema will be rewritten to match the CHECK constraint in the new schema. It is the migration author's responsibility to ensure that this SQL works and produces a value that really does satisfy the constraint. If the up SQL fails then the backfill operation on start will fail and the migration will be rolled back.

Having a way to test the up SQL against all (or a subset) of the values in the table before performing any DDL operations would provide a better user experience and help migration authors validate migrations before execution.

@andrew-farries andrew-farries added the enhancement New feature or request label Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant