Skip to content

feat(migrations): improve migrations immutability #10

@graduenz

Description

@graduenz

Context

Right now, migrations can be created once, be applied, and there is nothing that prevents that migration to be modified accidentally by the user, ending up doing no effect because the migration has already been recorded as applied.

Requirements

Come up with something that prevents applied migrations from being changed after they have been applied.

Below is an overview of my initial idea:

  • Track the every executed SQL command during a migration, combine it, hash, and store the hash
  • If the hash ever changes, that means the migration has been modified
  • Add a new function in the migrations package, like migrations.EnsureImmutability or migrations.ValidateAppliedMigrations, that:
    • Runs every applied migration again using an alternative SQLExecutor implementation that doesn't actually execute the script, only tracks the commands
    • For each migration, combine the commands and hash it (same process of when it's actually executed)
    • Compare the produced hash with the recorded hash
    • Return a list of errors (migrations that have been applied and had their hash was changed)
    • Let the user can decide what to do with the errors (such as panic the program startup)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions