Skip to content

Detect invalid migration state when using --reuse-db #883

Open
@tolomea

Description

@tolomea

When using --reuse-db it would be nice if pytest-django could detect that the database it's reusing has applied migrations that don't exist (due to changing branch or code edits) and rebuild it from scratch.

Our migrations take about 30 seconds to run. So per the doco here https://pytest-django.readthedocs.io/en/latest/database.html#example-work-flow-with-reuse-db-and-create-db I have --reuse-db in pytest.ini.
Which is great most of the time but frequently when I switch between branches with migrations or otherwise mess with migrations I will get a complete test suite fail (but slowly and with massive amounts of error output). Then I need to run with --create-db and further that needs to be done separately for both single and multi threaded test runs and I have to remember to take it back off the args for followup runs or I will eat another 30 seconds each time.

It would be very very nice if pytest-django realised that the set of migrations in the db and the migrations on the drive are different and did a rebuild. Even just comparing the file names would be a vast improvement.
The migration table also has an applied timestamp, so detecting that the mod time on the file is newer than the applied time might also be possible.

This was spun out from #422

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