3YOURMIND / django-migration-linter

:rocket: Detect backward incompatible migrations for your django project
https://pypi.python.org/pypi/django-migration-linter/
Apache License 2.0
514 stars 56 forks source link

Only make a connection to the DB if necessary #255

Open mjvankampen opened 1 year ago

mjvankampen commented 1 year ago

When updating to Django 4 I noticed that suddenly our CI failed as there was no valid database while linting migrations. This change will only connect to a DB when it is necessary (i.e. check only applied or unapplied migrations). That way you don't have to do trickery in your settings file when you run the linter without a DB.

mjvankampen commented 1 year ago

Ah sorry not related to Django4 but still I think this PR is valid.

mjvankampen commented 11 months ago

Sorry I’m somewhat new to databases and Django (coming from an embedded environment). While setting up CI/CD I noticed that to lint migrations you need to connect to the database. On a higher level I don’t really understand that as you don’t need to know the current state of the database as that is captured in your migrations already. Except if you only want to lint unapplied migrations for example.

From your reply the MigrationLoader is needed to lint the migrations and the MigrationLoader needs a connection to a database (the state of the db does not matter?) which is I guess hard to get around.

Ps. Love the project and its helped me capture some bad migrations already!

Please let me know if I understand correctly, then I’ve learned something and will work around it (like spin up a DB for linting).