File: range_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 (46 lines) | stat: -rw-r--r-- 1,290 bytes parent folder | download
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
42
43
44
45
46
from typing import Any, Optional, Type

from psqlextra.backend.schema import PostgresSchemaEditor
from psqlextra.models import PostgresPartitionedModel

from .partition import PostgresPartition


class PostgresRangePartition(PostgresPartition):
    """Base class for a PostgreSQL table partition in a range partitioned
    table."""

    def __init__(self, from_values: Any, to_values: Any) -> None:
        self.from_values = from_values
        self.to_values = to_values

    def deconstruct(self) -> dict:
        return {
            **super().deconstruct(),
            "from_values": self.from_values,
            "to_values": self.to_values,
        }

    def create(
        self,
        model: Type[PostgresPartitionedModel],
        schema_editor: PostgresSchemaEditor,
        comment: Optional[str] = None,
    ) -> None:
        schema_editor.add_range_partition(
            model=model,
            name=self.name(),
            from_values=self.from_values,
            to_values=self.to_values,
            comment=comment,
        )

    def delete(
        self,
        model: Type[PostgresPartitionedModel],
        schema_editor: PostgresSchemaEditor,
    ) -> None:
        schema_editor.delete_partition(model, self.name())


__all__ = ["PostgresRangePartition"]