# Path: psqlextra/backend/migrations/state/partitioning.py
# class PostgresPartitionedModelState(PostgresModelState):
#     """Represents the state of a :see:PostgresPartitionedModel in the
#     migrations."""
# 
#     def __init__(
#         self,
#         *args,
#         partitions: List[PostgresPartitionState] = [],
#         partitioning_options={},
#         **kwargs
#     ):
#         """Initializes a new instance of :see:PostgresPartitionedModelState.
# 
#         Arguments:
#             partitioning_options:
#                 Dictionary of options for partitioning.
# 
#                 See: PostgresPartitionedModelMeta for a list.
#         """
# 
#         super().__init__(*args, **kwargs)
# 
#         self.partitions: Dict[str, PostgresPartitionState] = {
#             partition.name: partition for partition in partitions
#         }
#         self.partitioning_options = dict(partitioning_options)
# 
#     def add_partition(self, partition: PostgresPartitionState):
#         """Adds a partition to this partitioned model state."""
# 
#         self.partitions[partition.name] = partition
# 
#     def delete_partition(self, name: str):
#         """Deletes a partition from this partitioned model state."""
# 
#         del self.partitions[name]
# 
#     @classmethod
#     def _pre_new(
#         cls,
#         model: PostgresPartitionedModel,
#         model_state: "PostgresPartitionedModelState",
#     ) -> "PostgresPartitionedModelState":
#         """Called when a new model state is created from the specified
#         model."""
# 
#         model_state.partitions = dict()
#         model_state.partitioning_options = dict(
#             model._partitioning_meta.original_attrs
#         )
#         return model_state
# 
#     def _pre_clone(
#         self, model_state: "PostgresPartitionedModelState"
#     ) -> "PostgresPartitionedModelState":
#         """Called when this model state is cloned."""
# 
#         model_state.partitions = dict(self.partitions)
#         model_state.partitioning_options = dict(self.partitioning_options)
#         return model_state
# 
#     def _pre_render(self, name: str, bases, attributes):
#         """Called when this model state is rendered into a model."""
# 
#         partitioning_meta = type(
#             "PartitioningMeta", (), dict(self.partitioning_options)
#         )
#         return (
#             name,
#             bases,
#             {**attributes, "PartitioningMeta": partitioning_meta},
#         )
# 
#     @classmethod
#     def _get_base_model_class(self) -> Type[PostgresPartitionedModel]:
#         """Gets the class to use as a base class for rendered models."""
# 
#         return PostgresPartitionedModel


from django.db.migrations.operations.models import CreateModel
from psqlextra.backend.migrations.state import PostgresPartitionedModelState



class PostgresCreatePartitionedModel(CreateModel):
    """Creates the model as a native PostgreSQL 11.x partitioned table."""

    serialization_expand_args = [
        "fields",
        "options",
        "managers",
        "partitioning_options",
    ]

    def __init__(
        self,
        name,
        fields,
        options=None,
        partitioning_options={},
        bases=None,
        managers=None,
    ):
        super().__init__(name, fields, options, bases, managers)

        self.partitioning_options = partitioning_options or {}

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

# Path: psqlextra/backend/migrations/state/partitioning.py
# class PostgresPartitionedModelState(PostgresModelState):
#     """Represents the state of a :see:PostgresPartitionedModel in the
#     migrations."""
# 
#     def __init__(
#         self,
#         *args,
#         partitions: List[PostgresPartitionState] = [],
#         partitioning_options={},
#         **kwargs
#     ):
#         """Initializes a new instance of :see:PostgresPartitionedModelState.
# 
#         Arguments:
#             partitioning_options:
#                 Dictionary of options for partitioning.
# 
#                 See: PostgresPartitionedModelMeta for a list.
#         """
# 
#         super().__init__(*args, **kwargs)
# 
#         self.partitions: Dict[str, PostgresPartitionState] = {
#             partition.name: partition for partition in partitions
#         }
#         self.partitioning_options = dict(partitioning_options)
# 
#     def add_partition(self, partition: PostgresPartitionState):
#         """Adds a partition to this partitioned model state."""
# 
#         self.partitions[partition.name] = partition
# 
#     def delete_partition(self, name: str):
#         """Deletes a partition from this partitioned model state."""
# 
#         del self.partitions[name]
# 
#     @classmethod
#     def _pre_new(
#         cls,
#         model: PostgresPartitionedModel,
#         model_state: "PostgresPartitionedModelState",
#     ) -> "PostgresPartitionedModelState":
#         """Called when a new model state is created from the specified
#         model."""
# 
#         model_state.partitions = dict()
#         model_state.partitioning_options = dict(
#             model._partitioning_meta.original_attrs
#         )
#         return model_state
# 
#     def _pre_clone(
#         self, model_state: "PostgresPartitionedModelState"
#     ) -> "PostgresPartitionedModelState":
#         """Called when this model state is cloned."""
# 
#         model_state.partitions = dict(self.partitions)
#         model_state.partitioning_options = dict(self.partitioning_options)
#         return model_state
# 
#     def _pre_render(self, name: str, bases, attributes):
#         """Called when this model state is rendered into a model."""
# 
#         partitioning_meta = type(
#             "PartitioningMeta", (), dict(self.partitioning_options)
#         )
#         return (
#             name,
#             bases,
#             {**attributes, "PartitioningMeta": partitioning_meta},
#         )
# 
#     @classmethod
#     def _get_base_model_class(self) -> Type[PostgresPartitionedModel]:
#         """Gets the class to use as a base class for rendered models."""
# 
#         return PostgresPartitionedModel


# Path: psqlextra/backend/migrations/operations/create_partitioned_model.py
from django.db.migrations.operations.models import CreateModel
from psqlextra.backend.migrations.state import PostgresPartitionedModelState




class PostgresCreatePartitionedModel(CreateModel):
    """Creates the model as a native PostgreSQL 11.x partitioned table."""

    serialization_expand_args = [
        "fields",
        "options",
        "managers",
        "partitioning_options",
    ]

    def __init__(
        self,
        name,
        fields,
        options=None,
        partitioning_options={},
        bases=None,
        managers=None,
    ):
        super().__init__(name, fields, options, bases, managers)

        self.partitioning_options = partitioning_options or {}

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

            PostgresPartitionedModelState(