delete_list_partition.py 867 B

1234567891011121314151617181920212223242526
  1. from .delete_partition import PostgresDeletePartition
  2. class PostgresDeleteListPartition(PostgresDeletePartition):
  3. """Deletes a list 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_list_partition(
  14. model, partition_state.name, partition_state.values
  15. )
  16. def describe(self) -> str:
  17. return "Deletes list partition '%s' on %s" % (
  18. self.name,
  19. self.model_name,
  20. )