delete_range_partition.py 952 B

1234567891011121314151617181920212223242526272829
  1. from .delete_partition import PostgresDeletePartition
  2. class PostgresDeleteRangePartition(PostgresDeletePartition):
  3. """Deletes a range partition that's part of a.
  4. :see:PartitionedPostgresModel.
  5. """
  6. def database_backwards(
  7. self, app_label, schema_editor, from_state, to_state
  8. ):
  9. model = to_state.apps.get_model(app_label, self.model_name)
  10. model_state = to_state.models[(app_label, self.model_name_lower)]
  11. if self.allow_migrate_model(schema_editor.connection.alias, model):
  12. partition_state = model_state.partitions[self.name]
  13. schema_editor.add_range_partition(
  14. model,
  15. partition_state.name,
  16. partition_state.from_values,
  17. partition_state.to_values,
  18. )
  19. def describe(self) -> str:
  20. return "Deletes range partition '%s' on %s" % (
  21. self.name,
  22. self.model_name,
  23. )