File: delete_list_partition.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 (26 lines) | stat: -rw-r--r-- 867 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
from .delete_partition import PostgresDeletePartition


class PostgresDeleteListPartition(PostgresDeletePartition):
    """Deletes a list partition that's part of a.

    :see:PartitionedPostgresModel.
    """

    def database_backwards(
        self, app_label, schema_editor, from_state, to_state
    ):
        model = to_state.apps.get_model(app_label, self.model_name)
        model_state = to_state.models[(app_label, self.model_name_lower)]

        if self.allow_migrate_model(schema_editor.connection.alias, model):
            partition_state = model_state.partitions[self.name]
            schema_editor.add_list_partition(
                model, partition_state.name, partition_state.values
            )

    def describe(self) -> str:
        return "Deletes list partition '%s' on %s" % (
            self.name,
            self.model_name,
        )