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"]
|