File: apply_state.py

package info (click to toggle)
python-django-postgres-extra 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,096 kB
  • sloc: python: 9,057; makefile: 17; sh: 7; sql: 1
file content (41 lines) | stat: -rw-r--r-- 1,264 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from django.db.migrations.operations.base import Operation


class ApplyState(Operation):
    """Takes an abritrary operation and migrates the project state but does not
    apply the operation to the database.

    This is very similar to the :see:RunSQL `state_operations`
    parameter. This is useful if you want to tell Django that an
    operation was applied without actually applying it.
    """

    reduces_to_sql = False

    def __init__(self, state_operation: Operation) -> None:
        self.state_operation = state_operation

    def deconstruct(self):
        kwargs = {"state_operation": self.state_operation}
        return (self.__class__.__qualname__, [], kwargs)

    @property
    def reversible(self):
        return True

    def state_forwards(self, app_label, state):
        self.state_operation.state_forwards(app_label, state)

    def state_backwards(self, app_label, state):
        self.state_operation.state_backwards(app_label, state)

    def database_forwards(self, app_label, schema_editor, from_state, to_state):
        pass

    def database_backwards(
        self, app_label, schema_editor, from_state, to_state
    ):
        pass

    def describe(self):
        return "Apply state: " + self.state_operation.describe()