operations.py 930 B

12345678910111213141516171819202122232425262728293031
  1. from django.db.migrations import RunPython
  2. class StartCacheVersioning(RunPython):
  3. def __init__(self, cache):
  4. code = start_cache_versioning(cache)
  5. reverse_code = stop_cache_versioning(cache)
  6. super().__init__(code, reverse_code)
  7. class StopCacheVersioning(RunPython):
  8. def __init__(self, cache):
  9. code = stop_cache_versioning(cache)
  10. reverse_code = start_cache_versioning(cache)
  11. super().__init__(code, reverse_code)
  12. def start_cache_versioning(cache):
  13. def migration_operation(apps, _):
  14. CacheVersion = apps.get_model("misago_cache", "CacheVersion")
  15. CacheVersion.objects.create(cache=cache)
  16. return migration_operation
  17. def stop_cache_versioning(cache):
  18. def migration_operation(apps, _):
  19. CacheVersion = apps.get_model("misago_cache", "CacheVersion")
  20. CacheVersion.objects.filter(cache=cache).delete()
  21. return migration_operation