delete_default_partition.py 825 B

123456789101112131415161718192021222324
  1. from .delete_partition import PostgresDeletePartition
  2. class PostgresDeleteDefaultPartition(PostgresDeletePartition):
  3. """Deletes a default 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_default_partition(model, partition_state.name)
  14. def describe(self) -> str:
  15. return "Deletes default partition '%s' on %s" % (
  16. self.name,
  17. self.model_name,
  18. )