partition.py 948 B

1234567891011121314151617181920212223242526272829303132
  1. from django.db.migrations.operations.base import Operation
  2. class PostgresPartitionOperation(Operation):
  3. def __init__(self, model_name: str, name: str) -> None:
  4. """Initializes new instance of :see:AddDefaultPartition.
  5. Arguments:
  6. model_name:
  7. The name of the :see:PartitionedPostgresModel.
  8. name:
  9. The name to give to the new partition table.
  10. """
  11. self.model_name = model_name
  12. self.model_name_lower = model_name.lower()
  13. self.name = name
  14. def deconstruct(self):
  15. kwargs = {"model_name": self.model_name, "name": self.name}
  16. return (self.__class__.__qualname__, [], kwargs)
  17. def state_forwards(self, *args, **kwargs):
  18. pass
  19. def state_backwards(self, *args, **kwargs):
  20. pass
  21. def reduce(self, *args, **kwargs):
  22. # PartitionOperation doesn't break migrations optimizations
  23. return True