aspiredu / django-safemigrate

Safely run migrations before deployment
MIT License
68 stars 0 forks source link

Support automating Safe.after_deploy migrations #51

Closed tim-schilling closed 1 month ago

tim-schilling commented 2 months ago

I'd like to solve the problem of running Safe.after_deploy afterwards where I’m waiting to confirm a problem didn’t occur first. In these cases, I tend to forget to migrate those commands so I’d like to automate it.

One idea is to have a new model that tracks when a migration is detected. Then create a new management command that would need to be called periodically that would use a timedelta on the Safe.after_deploy migrations to determine which migrations can be migrated in the background.

From Ryan:

I can imagine this including some configuration in the migration itself to determine what kind of mandatory delay is required before running it. That kinda sounds like it could be a workable idea. What if we

  1. make a post_migrate signal receiver to notice when it's first seen and marked as "ready" (not blocked) by safemigrate .
  2. have the pre_migrate signal compare the required delay and the (possible) record in the database to see if it's ready to go. If so, it would automatically convert to an always.

Maybe the new marking could something like safe = timedelta(days=7)

That would avoid a new property. It would be an alternative to Safe.after_deploy. It doesn't generalize nicely, since there's no good meaning in that data type that would map to "before_deploy only" that I can see just yet.

Continuing on that thread, maybe we go with safe = Safe.after_deploy(delay=timedelta(days=7)) to maintain consistency and avoid a typecheck.