File: 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 (38 lines) | stat: -rw-r--r-- 1,019 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
from abc import abstractmethod
from typing import Optional, Type

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


class PostgresPartition:
    """Base class for a PostgreSQL table partition."""

    @abstractmethod
    def name(self) -> str:
        """Generates/computes the name for this partition."""

    @abstractmethod
    def create(
        self,
        model: Type[PostgresPartitionedModel],
        schema_editor: PostgresSchemaEditor,
        comment: Optional[str] = None,
    ) -> None:
        """Creates this partition in the database."""

    @abstractmethod
    def delete(
        self,
        model: Type[PostgresPartitionedModel],
        schema_editor: PostgresSchemaEditor,
    ) -> None:
        """Deletes this partition from the database."""

    def deconstruct(self) -> dict:
        """Deconstructs this partition into a dict of attributes/fields."""

        return {"name": self.name()}


__all__ = ["PostgresPartition"]