API Reference¶
Time Range Partitioning¶
-
class
TimeRangePartitionManager
(model: Type[django.db.models.base.Model], partition_key: str, options: dict)[source]¶ Manage time-based partition APIs.
-
attach_partition
(partition_log: Optional[collections.abc.Iterable] = None, detach_time: Optional[datetime.datetime] = None) → None[source]¶ Attach partitions.
Parameters: - partition_log (Optional[Iterable]) – All partitions are attached when you don’t specify partitions to attach.
- detach_time (Optional[datetime.datetime]) – When the partition specifies the archive time, it will not be automatically archived until that time.
-
config
¶ Get the latest PartitionConfig instance of this model. In order to avoid the race condition, we used select_for_update when querying.
Returns: The latest PartitionConfig instance of this model. Return type: PartitionConfig
-
create_partition
(max_days_to_next_partition: int = 1) → None[source]¶ The partition of the next cycle is created according to the configuration. After modifying the period field, the new period will take effect the next time. The start time of the new partition is the end time of the previous partition table, or the start time of the current archive period when no partition exists.
For example: the current time is June 5, 2018, and the archiving period is one year, then the start time of the first partition is 00:00:00 on January 1, 2018.
Parameters: max_days_to_next_partition (int) – If numbers of days remained in current partition is greater than max_days_to_next_partition
, no new partitions will be created.
-
delete_partition
(partition_log: collections.abc.Iterable) → None[source]¶ Delete partitions.
Parameters: partition_log (Iterable) – The partitions to be deleted.
-
detach_partition
(partition_log: Optional[collections.abc.Iterable] = None) → None[source]¶ Detach partitions.
Parameters: partition_log (Optional[Iterable]) – Specify a partition to archive. When you don’t specify a partition to archive, all partitions that meet the configuration rule are archived.
-
latest
¶ Get the latest PartitionLog instance of this model.
Returns: The latest PartitionLog instance of this model or none. Return type: Optional[PartitionLog]
-
-
class
PartitionConfig
(*args, **kwargs)[source]¶ You can get the configuration object of the partition table through
Model.partitioning.config
, You can only edit the following fields via the object’ssave
method:-
attach_tablespace
¶ The name of the tablespace specified when creating or attaching a partition. Modifying this field will only affect subsequent operations. A table migration may occur at this time.
-
detach_tablespace
¶ The name of the tablespace specified when detaching a partition. Modifying this field will only affect subsequent operations. A table migration may occur at this time.
-
interval
¶ Detaching period. The
detach_partition
method defaults to detach partitions before the interval * period. The default is None, ie no partition will be detached. Changing this value will trigger thedetach_partition
method.
-
period
¶ Partition period. you can only set options in the PeriodType. The default value is
PeriodType.Month
. Changing this value will trigger thedetach_partition
method.
-
-
class
PartitionLog
(*args, **kwargs)[source]¶ You can only edit the following fields via the object’s
save
method:-
delete
(using=None, keep_parents=False)[source]¶ When the instance is deleted, the partition corresponding to it will also be deleted.
-
detach_time
¶ When the value is not None, the partition will not be automatically detached before this time. The default is None.
-
is_attached
¶ Whether the partition is a attached partition. changing the value will trigger an attaching or detaching operation.
-
List Partitioning¶
-
class
ListPartitionManager
(model: Type[django.db.models.base.Model], partition_key: str, options: dict)[source]¶ Manage list-based partition APIs.
-
attach_partition
(partition_name: str, value: Union[str, int, None], tablespace: str = None) → None[source]¶ Attach partitions.
Parameters:
-