apply_state.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from django.db.migrations.operations.base import Operation
  2. class ApplyState(Operation):
  3. """Takes an abritrary operation and migrates the project state but does not
  4. apply the operation to the database.
  5. This is very similar to the :see:RunSQL `state_operations`
  6. parameter. This is useful if you want to tell Django that an
  7. operation was applied without actually applying it.
  8. """
  9. reduces_to_sql = False
  10. def __init__(self, state_operation: Operation) -> None:
  11. self.state_operation = state_operation
  12. def deconstruct(self):
  13. kwargs = {"state_operation": self.state_operation}
  14. return (self.__class__.__qualname__, [], kwargs)
  15. @property
  16. def reversible(self):
  17. return True
  18. def state_forwards(self, app_label, state):
  19. self.state_operation.state_forwards(app_label, state)
  20. def state_backwards(self, app_label, state):
  21. self.state_operation.state_backwards(app_label, state)
  22. def database_forwards(self, app_label, schema_editor, from_state, to_state):
  23. pass
  24. def database_backwards(
  25. self, app_label, schema_editor, from_state, to_state
  26. ):
  27. pass
  28. def describe(self):
  29. return "Apply state: " + self.state_operation.describe()