Skip to content

Enable comparing migrations to implementation in tests. #724

@Luttik

Description

@Luttik

I would love to have the option to check, in my ci pipeline, if the migrations are up to date with the implementation of the models in the code.

We are almost there
I feel like we can get quite close to this. We can spin up an SQLite and apply the migration to the database, we can even call command.revision(alembic_cfg, autogenerate=True). However, that, of course, creates a migration file instead of returning a concise list of changes to the python runtime.

My search for solutions
It seems like the generation of changes happens somewhere in alembic.autogenerate.compare._populate_migration_script but since this is a protected method I am hesitant to develop against it.

What I would love
I would absolutely love it if there would be some documentation on how to properly test alembic:

  • Assert that upgrading works
  • Assert that downgrading works
  • Assert that migrations are up-to-date with the current codebase. (IMO the most important one)

Of course, the documentation would actually require a good interface to do those things with. But I do believe this would eliminate a significant set of production database issues.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions