Skip to content

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

@andrew-farries

Description

@andrew-farries

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions