API Reference

class psqlextra.manager.PostgresManager(*args, **kwargs)

Adds support for PostgreSQL specifics.

truncate(cascade: bool = False, using: Optional[str] = None) → None

Truncates this model/table using the TRUNCATE statement.

This DELETES ALL ROWS. No signals will be fired.

See: https://www.postgresql.org/docs/9.1/sql-truncate.html

Parameters

cascade – Whether to delete dependent rows. If set to False, an error will be raised if there are rows in other tables referencing the rows you’re trying to delete.

class psqlextra.query.PostgresQuerySet(model=None, query=None, using=None, hints=None)

Adds support for PostgreSQL specifics.

bulk_insert(rows: Iterable[Dict[str, Any]], return_model: bool = False, using: Optional[str] = None)

Creates multiple new records in the database.

This allows specifying custom conflict behavior using .on_conflict(). If no special behavior was specified, this uses the normal Django create(..)

Parameters
  • rows – An iterable of dictionaries, where each dictionary describes the fields to insert.

  • (default (return_model) – False): If model instances should be returned rather than just dicts.

  • using – Optional name of the database connection to use for this query.

Returns

A list of either the dicts of the rows inserted, including the pk or the models of the rows inserted with defaults for any fields not specified

bulk_upsert(conflict_target: Union[List[Union[str, Tuple[str]]], BaseConstraint, Index], rows: Iterable[Dict], index_predicate: Union[django.db.models.expressions.Expression, django.db.models.query_utils.Q, str, None] = None, return_model: bool = False, using: Optional[str] = None, update_condition: Union[django.db.models.expressions.Expression, django.db.models.query_utils.Q, str, None] = None, update_values: Optional[Dict[str, Union[Any, django.db.models.expressions.Expression]]] = None)

Creates a set of new records or updates the existing ones with the specified data.

Parameters
  • conflict_target – Fields to pass into the ON CONFLICT clause.

  • rows – Rows to upsert.

  • index_predicate – The index predicate to satisfy an arbiter partial index (i.e. what partial index to use for checking conflicts)

  • (default (return_model) – False): If model instances should be returned rather than just dicts.

  • using – The name of the database connection to use for this query.

  • update_condition – Only update if this SQL expression evaluates to true.

  • update_values – Optionally, values/expressions to use when rows conflict. If not specified, all columns specified in the rows are updated with the values you specified.

Returns

A list of either the dicts of the rows upserted, including the pk or the models of the rows upserted

insert(using: Optional[str] = None, **fields)

Creates a new record in the database.

This allows specifying custom conflict behavior using .on_conflict(). If no special behavior was specified, this uses the normal Django create(..)

Parameters
  • fields – The fields of the row to create.

  • using – The name of the database connection to use for this query.

Returns

The primary key of the record that was created.

insert_and_get(using: Optional[str] = None, **fields)

Creates a new record in the database and then gets the entire row.

This allows specifying custom conflict behavior using .on_conflict(). If no special behavior was specified, this uses the normal Django create(..)

Parameters
  • fields – The fields of the row to create.

  • using – The name of the database connection to use for this query.

Returns

The model instance representing the row that was created.

on_conflict(fields: Union[List[Union[str, Tuple[str]]], BaseConstraint, Index], action: psqlextra.types.ConflictAction, index_predicate: Union[django.db.models.expressions.Expression, django.db.models.query_utils.Q, str, None] = None, update_condition: Union[django.db.models.expressions.Expression, django.db.models.query_utils.Q, str, None] = None, update_values: Optional[Dict[str, Union[Any, django.db.models.expressions.Expression]]] = None)

Sets the action to take when conflicts arise when attempting to insert/create a new row.

Parameters
  • fields – The fields the conflicts can occur in.

  • action – The action to take when the conflict occurs.

  • index_predicate – The index predicate to satisfy an arbiter partial index (i.e. what partial index to use for checking conflicts)

  • update_condition – Only update if this SQL expression evaluates to true.

  • update_values – Optionally, values/expressions to use when rows conflict. If not specified, all columns specified in the rows are updated with the values you specified.

upsert(conflict_target: Union[List[Union[str, Tuple[str]]], BaseConstraint, Index], fields: dict, index_predicate: Union[django.db.models.expressions.Expression, django.db.models.query_utils.Q, str, None] = None, using: Optional[str] = None, update_condition: Union[django.db.models.expressions.Expression, django.db.models.query_utils.Q, str, None] = None, update_values: Optional[Dict[str, Union[Any, django.db.models.expressions.Expression]]] = None) → int

Creates a new record or updates the existing one with the specified data.

Parameters
  • conflict_target – Fields to pass into the ON CONFLICT clause.

  • fields – Fields to insert/update.

  • index_predicate – The index predicate to satisfy an arbiter partial index (i.e. what partial index to use for checking conflicts)

  • using – The name of the database connection to use for this query.

  • update_condition – Only update if this SQL expression evaluates to true.

  • update_values – Optionally, values/expressions to use when rows conflict. If not specified, all columns specified in the rows are updated with the values you specified.

Returns

The primary key of the row that was created/updated.

upsert_and_get(conflict_target: Union[List[Union[str, Tuple[str]]], BaseConstraint, Index], fields: dict, index_predicate: Union[django.db.models.expressions.Expression, django.db.models.query_utils.Q, str, None] = None, using: Optional[str] = None, update_condition: Union[django.db.models.expressions.Expression, django.db.models.query_utils.Q, str, None] = None, update_values: Optional[Dict[str, Union[Any, django.db.models.expressions.Expression]]] = None)

Creates a new record or updates the existing one with the specified data and then gets the row.

Parameters
  • conflict_target – Fields to pass into the ON CONFLICT clause.

  • fields – Fields to insert/update.

  • index_predicate – The index predicate to satisfy an arbiter partial index (i.e. what partial index to use for checking conflicts)

  • using – The name of the database connection to use for this query.

  • update_condition – Only update if this SQL expression evaluates to true.

  • update_values – Optionally, values/expressions to use when rows conflict. If not specified, all columns specified in the rows are updated with the values you specified.

Returns

The model instance representing the row that was created/updated.

class psqlextra.models.PostgresModel(*args, **kwargs)

Base class for for taking advantage of PostgreSQL specific features.

class psqlextra.models.PostgresViewModel(*args, **kwargs)

Base class for creating a model that is a view.

class psqlextra.models.PostgresMaterializedViewModel(*args, **kwargs)

Base class for creating a model that is a materialized view.

classmethod refresh(concurrently: bool = False, using: Optional[str] = None) → None

Refreshes this materialized view.

Parameters
  • concurrently – Whether to tell PostgreSQL to refresh this materialized view concurrently.

  • using – Optionally, the name of the database connection to use for refreshing the materialized view.

class psqlextra.models.PostgresPartitionedModel(*args, **kwargs)

Base class for taking advantage of PostgreSQL’s 11.x native support for table partitioning.

class psqlextra.fields.HStoreField(*args, uniqueness: Optional[List[Union[str, Tuple[str, ...]]]] = None, required: Optional[List[str]] = None, **kwargs)

Improved version of Django’s :see:HStoreField that adds support for database-level constraints.

Notes

  • For the implementation of uniqueness, see the custom database back-end.

__init__(*args, uniqueness: Optional[List[Union[str, Tuple[str, ...]]]] = None, required: Optional[List[str]] = None, **kwargs)

Initializes a new instance of :see:HStoreField.

Parameters
  • uniqueness – List of keys to enforce as unique. Use tuples to enforce multiple keys together to be unique.

  • required – List of keys that should be enforced as required.

class psqlextra.expressions.HStoreRef(name: str, key: str)

Inline reference to a HStore key.

Allows selecting individual keys in annotations.

class psqlextra.expressions.DateTimeEpoch(name)

Gets the date/time column as a UNIX epoch timestamp.

class psqlextra.expressions.ExcludedCol(field_or_name: Union[django.db.models.fields.Field, str])

References a column in PostgreSQL’s special EXCLUDED column, which is used in upserts to refer to the data about to be inserted/updated.

See: https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT

class psqlextra.indexes.UniqueIndex(*expressions, fields=(), name=None, db_tablespace=None, opclasses=(), condition=None, include=None)
class psqlextra.indexes.ConditionalUniqueIndex(condition: str, fields=[], name=None)

Creates a partial unique index based on a given condition.

Useful, for example, if you need unique combination of foreign keys, but you might want to include NULL as a valid value. In that case, you can just use:

>>> class Meta:
>>>    indexes = [
>>>        ConditionalUniqueIndex(fields=['a', 'b', 'c'], condition='"c" IS NOT NULL'),
>>>        ConditionalUniqueIndex(fields=['a', 'b'], condition='"c" IS NULL')
>>>    ]
class psqlextra.indexes.CaseInsensitiveUniqueIndex(*expressions, fields=(), name=None, db_tablespace=None, opclasses=(), condition=None, include=None)
class psqlextra.locking.PostgresTableLockMode

List of table locking modes.

See: https://www.postgresql.org/docs/current/explicit-locking.html

psqlextra.locking.postgres_lock_model(model: Type[django.db.models.base.Model], lock_mode: psqlextra.locking.PostgresTableLockMode, *, using: str = 'default', schema_name: Optional[str] = None) → None

Locks the specified model with the specified mode.

The lock is held until the end of the current transaction.

Parameters
  • model – The model of which to lock the table.

  • lock_mode – Type of lock to acquire.

  • schema_name

    Optionally, the unquoted name of the schema the table to lock is in. If not specified, the table name is resolved by PostgreSQL using it’s search_path.

    Django models always reside in the default (“public”) schema. You should not specify this unless you’re doing something special.

  • using – Optional name of the database connection to use.

psqlextra.locking.postgres_lock_table(table_name: str, lock_mode: psqlextra.locking.PostgresTableLockMode, *, schema_name: Optional[str] = None, using: str = 'default') → None

Locks the specified table with the specified mode.

The lock is held until the end of the current transaction.

Parameters
  • table_name – Unquoted table name to acquire the lock on.

  • lock_mode – Type of lock to acquire.

  • schema_name – Optionally, the unquoted name of the schema the table to lock is in. If not specified, the table name is resolved by PostgreSQL using it’s search_path.

  • using – Optional name of the database connection to use.

class psqlextra.schema.PostgresSchema(name: str)

Represents a Postgres schema.

See: https://www.postgresql.org/docs/current/ddl-schemas.html

classmethod create(name: str, *, using: str = 'default') → psqlextra.schema.PostgresSchema

Creates a new schema with the specified name.

This throws if the schema already exists as that is most likely a problem that requires careful handling. Pretending everything is ok might cause the caller to overwrite data, thinking it got a empty schema.

Parameters
  • name – The name to give to the new schema (max 63 characters).

  • using – Optional name of the database connection to use.

classmethod create_random(prefix: str, *, using: str = 'default') → psqlextra.schema.PostgresSchema

Creates a new schema with a random suffix.

Parameters
  • prefix – Name to prefix the final name with. The name plus prefix cannot be longer than 63 characters.

  • using – Name of the database connection to use.

classmethod create_time_based(prefix: str, *, using: str = 'default') → psqlextra.schema.PostgresSchema

Creates a new schema with a time-based suffix.

The time is precise up to the second. Creating multiple time based schema in the same second WILL lead to conflicts.

Parameters
  • prefix – Name to prefix the final name with. The name plus prefix cannot be longer than 63 characters.

  • using – Name of the database connection to use.

delete(*, cascade: bool = False, using: str = 'default') → None

Deletes the schema and optionally deletes the contents of the schema and anything that references it.

Parameters

cascade

Cascade the delete to the contents of the schema and anything that references it.

If not set, the schema will refuse to be deleted unless it is empty and there are not remaining references.

classmethod delete_and_create(name: str, *, cascade: bool = False, using: str = 'default') → psqlextra.schema.PostgresSchema

Deletes the schema if it exists before re-creating it.

Parameters
  • name – Name of the schema to delete+create (max 63 characters).

  • cascade – Whether to delete the contents of the schema and anything that references it if it exists.

  • using – Optional name of the database connection to use.

classmethod exists(name: str, *, using: str = 'default') → bool

Gets whether a schema with the specified name exists.

Parameters
  • name – Name of the schema to check of whether it exists.

  • using – Optional name of the database connection to use.

psqlextra.schema.postgres_temporary_schema(prefix: str, *, cascade: bool = False, delete_on_throw: bool = False, using: str = 'default') → Generator[psqlextra.schema.PostgresSchema, None, None]

Creates a temporary schema that only lives in the context of this context manager.

Parameters
  • prefix – Name to prefix the final name with.

  • cascade – Whether to cascade the delete when dropping the schema. If enabled, the contents of the schema are deleted as well as anything that references the schema.

  • delete_on_throw – Whether to automatically drop the schema if any error occurs within the context manager.

  • using – Optional name of the database connection to use.

class psqlextra.partitioning.PostgresPartitioningManager(configs: List[psqlextra.partitioning.config.PostgresPartitioningConfig])

Helps managing partitions by automatically creating new partitions and deleting old ones according to the configuration.

find_config_for_model(model: psqlextra.models.partitioned.PostgresPartitionedModel) → Optional[psqlextra.partitioning.config.PostgresPartitioningConfig]

Finds the partitioning config for the specified model.

plan(skip_create: bool = False, skip_delete: bool = False, using: Optional[str] = None) → psqlextra.partitioning.plan.PostgresPartitioningPlan

Plans which partitions should be deleted/created.

Parameters
  • skip_create – If set to True, no partitions will be marked for creation, regardless of the configuration.

  • skip_delete – If set to True, no partitions will be marked for deletion, regardless of the configuration.

  • using – Optional name of the database connection to use.

Returns

A plan describing what partitions would be created and deleted if the plan is applied.

psqlextra.partitioning.partition_by_current_time(model: Type[psqlextra.models.partitioned.PostgresPartitionedModel], count: int, years: Optional[int] = None, months: Optional[int] = None, weeks: Optional[int] = None, days: Optional[int] = None, max_age: Optional[dateutil.relativedelta.relativedelta] = None, name_format: Optional[str] = None) → psqlextra.partitioning.config.PostgresPartitioningConfig

Short-hand for generating a partitioning config that partitions the specified model by time.

One specifies one of the years, months, weeks or days parameter to indicate the size of each partition. These parameters cannot be combined.

Parameters
  • count – The amount of partitions to create ahead of the current date/time.

  • years – The amount of years each partition should contain.

  • months – The amount of months each partition should contain.

  • weeks – The amount of weeks each partition should contain.

  • days – The amount of days each partition should contain.

  • max_age

    The maximum age of a partition (calculated from the start of the partition).

    Partitions older than this are deleted when running a delete/cleanup run.

  • name_format – The datetime format which is being passed to datetime.strftime to generate the partition name.

exception psqlextra.partitioning.PostgresPartitioningError

Raised when the partitioning configuration is broken or automatically creating/deleting partitions fails.

class psqlextra.partitioning.PostgresPartitioningPlan(model_plans: List[psqlextra.partitioning.plan.PostgresModelPartitioningPlan])

Describes the partitions that are going to be created/deleted.

apply(using: Optional[str] = None) → None

Applies this plan by creating/deleting all planned partitions.

property creations

Gets a complete flat list of the partitions that are going to be created.

property deletions

Gets a complete flat list of the partitions that are going to be deleted.

print() → None

Prints this plan to the terminal in a readable format.

class psqlextra.partitioning.PostgresModelPartitioningPlan(config: psqlextra.partitioning.config.PostgresPartitioningConfig, creations: List[psqlextra.partitioning.partition.PostgresPartition] = <factory>, deletions: List[psqlextra.partitioning.partition.PostgresPartition] = <factory>)

Describes the partitions that are going to be created/deleted for a particular partitioning config.

A “partitioning config” applies to one model.

apply(using: Optional[str]) → None

Applies this partitioning plan by creating and deleting the planned partitions.

Applying the plan runs in a transaction.

Parameters

using – Optional name of the database connection to use.

print() → None

Prints this model plan to the terminal in a readable format.

class psqlextra.partitioning.PostgresPartition

Base class for a PostgreSQL table partition.

abstract create(model: Type[psqlextra.models.partitioned.PostgresPartitionedModel], schema_editor: psqlextra.backend.schema.PostgresSchemaEditor, comment: Optional[str] = None) → None

Creates this partition in the database.

deconstruct() → dict

Deconstructs this partition into a dict of attributes/fields.

abstract delete(model: Type[psqlextra.models.partitioned.PostgresPartitionedModel], schema_editor: psqlextra.backend.schema.PostgresSchemaEditor) → None

Deletes this partition from the database.

abstract name() → str

Generates/computes the name for this partition.

class psqlextra.partitioning.PostgresRangePartition(from_values: Any, to_values: Any)

Base class for a PostgreSQL table partition in a range partitioned table.

create(model: Type[psqlextra.models.partitioned.PostgresPartitionedModel], schema_editor: psqlextra.backend.schema.PostgresSchemaEditor, comment: Optional[str] = None) → None

Creates this partition in the database.

deconstruct() → dict

Deconstructs this partition into a dict of attributes/fields.

delete(model: Type[psqlextra.models.partitioned.PostgresPartitionedModel], schema_editor: psqlextra.backend.schema.PostgresSchemaEditor) → None

Deletes this partition from the database.

class psqlextra.partitioning.PostgresTimePartition(size: psqlextra.partitioning.time_partition_size.PostgresTimePartitionSize, start_datetime: datetime.datetime, name_format: Optional[str] = None)

Time-based range table partition.

:see:PostgresTimePartitioningStrategy for more info.

deconstruct() → dict

Deconstructs this partition into a dict of attributes/fields.

name() → str

Generates/computes the name for this partition.

class psqlextra.partitioning.PostgresPartitioningStrategy

Base class for implementing a partitioning strategy for a partitioned table.

abstract to_create() → Generator[psqlextra.partitioning.partition.PostgresPartition, None, None]

Generates a list of partitions to be created.

abstract to_delete() → Generator[psqlextra.partitioning.partition.PostgresPartition, None, None]

Generates a list of partitions to be deleted.

class psqlextra.partitioning.PostgresTimePartitioningStrategy(start_datetime: datetime.datetime, size: psqlextra.partitioning.time_partition_size.PostgresTimePartitionSize, count: int, max_age: Optional[dateutil.relativedelta.relativedelta] = None)
class psqlextra.partitioning.PostgresRangePartitioningStrategy

Base class for implementing a partitioning strategy for a range partitioned table.

class psqlextra.partitioning.PostgresCurrentTimePartitioningStrategy(size: psqlextra.partitioning.time_partition_size.PostgresTimePartitionSize, count: int, max_age: Optional[dateutil.relativedelta.relativedelta] = None, name_format: Optional[str] = None)

Implments a time based partitioning strategy where each partition contains values for a specific time period.

All buckets will be equal in size and start at the start of the unit. With monthly partitioning, partitions start on the 1st and with weekly partitioning, partitions start on monday.

to_create() → Generator[psqlextra.partitioning.time_partition.PostgresTimePartition, None, None]

Generates a list of partitions to be created.

to_delete() → Generator[psqlextra.partitioning.time_partition.PostgresTimePartition, None, None]

Generates a list of partitions to be deleted.

class psqlextra.partitioning.PostgresPartitioningConfig(model: Type[psqlextra.models.partitioned.PostgresPartitionedModel], strategy: psqlextra.partitioning.strategy.PostgresPartitioningStrategy)

Configuration for partitioning a specific model according to the specified strategy.

class psqlextra.partitioning.PostgresTimePartitionSize(years: Optional[int] = None, months: Optional[int] = None, weeks: Optional[int] = None, days: Optional[int] = None)

Size of a time-based range partition table.

class psqlextra.backend.migrations.operations.ApplyState(state_operation: django.db.migrations.operations.base.Operation)

Takes an abritrary operation and migrates the project state but does not apply the operation to the database.

This is very similar to the :see:RunSQL state_operations parameter. This is useful if you want to tell Django that an operation was applied without actually applying it.

database_backwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the reverse direction - e.g. if this were CreateModel, it would in fact drop the model’s table.

database_forwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the normal (forwards) direction.

deconstruct()

Return a 3-tuple of class import path (or just name if it lives under django.db.migrations), positional arguments, and keyword arguments.

describe()

Output a brief summary of what the action does.

property reversible

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

state_forwards(app_label, state)

Take the state from the previous migration, and mutate it so that it matches what this migration would perform.

class psqlextra.backend.migrations.operations.PostgresAddHashPartition(model_name: str, name: str, modulus: int, remainder: int)

Adds a new hash partition to a :see:PartitionedPostgresModel.

Each partition will hold the rows for which the hash value of the partition key divided by the specified modulus will produce the specified remainder.

database_backwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the reverse direction - e.g. if this were CreateModel, it would in fact drop the model’s table.

database_forwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the normal (forwards) direction.

deconstruct()

Return a 3-tuple of class import path (or just name if it lives under django.db.migrations), positional arguments, and keyword arguments.

describe() → str

Output a brief summary of what the action does.

state_forwards(app_label, state)

Take the state from the previous migration, and mutate it so that it matches what this migration would perform.

class psqlextra.backend.migrations.operations.PostgresAddListPartition(model_name, name, values)

Adds a new list partition to a :see:PartitionedPostgresModel.

database_backwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the reverse direction - e.g. if this were CreateModel, it would in fact drop the model’s table.

database_forwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the normal (forwards) direction.

deconstruct()

Return a 3-tuple of class import path (or just name if it lives under django.db.migrations), positional arguments, and keyword arguments.

describe() → str

Output a brief summary of what the action does.

state_forwards(app_label, state)

Take the state from the previous migration, and mutate it so that it matches what this migration would perform.

class psqlextra.backend.migrations.operations.PostgresAddRangePartition(model_name: str, name: str, from_values, to_values)

Adds a new range partition to a :see:PartitionedPostgresModel.

database_backwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the reverse direction - e.g. if this were CreateModel, it would in fact drop the model’s table.

database_forwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the normal (forwards) direction.

deconstruct()

Return a 3-tuple of class import path (or just name if it lives under django.db.migrations), positional arguments, and keyword arguments.

describe() → str

Output a brief summary of what the action does.

state_forwards(app_label, state)

Take the state from the previous migration, and mutate it so that it matches what this migration would perform.

class psqlextra.backend.migrations.operations.PostgresAddDefaultPartition(model_name: str, name: str)

Adds a new default partition to a :see:PartitionedPostgresModel.

database_backwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the reverse direction - e.g. if this were CreateModel, it would in fact drop the model’s table.

database_forwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the normal (forwards) direction.

describe() → str

Output a brief summary of what the action does.

state_forwards(app_label, state)

Take the state from the previous migration, and mutate it so that it matches what this migration would perform.

class psqlextra.backend.migrations.operations.PostgresDeleteDefaultPartition(model_name: str, name: str)

Deletes a default partition that’s part of a.

:see:PartitionedPostgresModel.

database_backwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the reverse direction - e.g. if this were CreateModel, it would in fact drop the model’s table.

describe() → str

Output a brief summary of what the action does.

class psqlextra.backend.migrations.operations.PostgresDeleteHashPartition(model_name: str, name: str)

Deletes a hash partition that’s part of a.

:see:PartitionedPostgresModel.

database_backwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the reverse direction - e.g. if this were CreateModel, it would in fact drop the model’s table.

describe() → str

Output a brief summary of what the action does.

class psqlextra.backend.migrations.operations.PostgresDeleteListPartition(model_name: str, name: str)

Deletes a list partition that’s part of a.

:see:PartitionedPostgresModel.

database_backwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the reverse direction - e.g. if this were CreateModel, it would in fact drop the model’s table.

describe() → str

Output a brief summary of what the action does.

class psqlextra.backend.migrations.operations.PostgresDeleteRangePartition(model_name: str, name: str)

Deletes a range partition that’s part of a.

:see:PartitionedPostgresModel.

database_backwards(app_label, schema_editor, from_state, to_state)

Perform the mutation on the database schema in the reverse direction - e.g. if this were CreateModel, it would in fact drop the model’s table.

describe() → str

Output a brief summary of what the action does.

class psqlextra.backend.migrations.operations.PostgresCreatePartitionedModel(name, fields, options=None, partitioning_options={}, bases=None, managers=None)

Creates the model as a native PostgreSQL 11.x partitioned table.

database_backwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation backwards.

database_forwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation forwards.

deconstruct()

Return a 3-tuple of class import path (or just name if it lives under django.db.migrations), positional arguments, and keyword arguments.

describe()

Gets a human readable text describing this migration.

reduce(*args, **kwargs)

Return either a list of operations the actual operation should be replaced with or a boolean that indicates whether or not the specified operation can be optimized across.

state_forwards(app_label, state)

Take the state from the previous migration, and mutate it so that it matches what this migration would perform.

class psqlextra.backend.migrations.operations.PostgresDeletePartitionedModel(name)

Deletes the specified partitioned model.

database_backwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation backwards.

database_forwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation forwards.

describe()

Gets a human readable text describing this migration.

class psqlextra.backend.migrations.operations.PostgresCreateViewModel(name, fields, options=None, view_options={}, bases=None, managers=None)

Creates the model as a native PostgreSQL 11.x view.

database_backwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation backwards.

database_forwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation forwards.

deconstruct()

Return a 3-tuple of class import path (or just name if it lives under django.db.migrations), positional arguments, and keyword arguments.

describe()

Gets a human readable text describing this migration.

state_forwards(app_label, state)

Take the state from the previous migration, and mutate it so that it matches what this migration would perform.

class psqlextra.backend.migrations.operations.PostgresCreateMaterializedViewModel(name, fields, options=None, view_options={}, bases=None, managers=None)

Creates the model as a native PostgreSQL 11.x materialzed view.

database_backwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation backwards.

database_forwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation forwards.

deconstruct()

Return a 3-tuple of class import path (or just name if it lives under django.db.migrations), positional arguments, and keyword arguments.

describe()

Gets a human readable text describing this migration.

state_forwards(app_label, state)

Take the state from the previous migration, and mutate it so that it matches what this migration would perform.

class psqlextra.backend.migrations.operations.PostgresDeleteViewModel(name)

Deletes the specified view model.

database_backwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation backwards.

database_forwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation forwards.

describe()

Gets a human readable text describing this migration.

class psqlextra.backend.migrations.operations.PostgresDeleteMaterializedViewModel(name)

Deletes the specified materialized view model.

database_backwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation backwards.

database_forwards(app_label, schema_editor, from_state, to_state)

Apply this migration operation forwards.

describe()

Gets a human readable text describing this migration.

class psqlextra.types.ConflictAction

Possible actions to take on a conflict.

NOTHING = 'NOTHING'
UPDATE = 'UPDATE'
all = <bound method ConflictAction.all of <enum 'ConflictAction'>>
class psqlextra.types.PostgresPartitioningMethod

Methods of partitioning supported by PostgreSQL 11.x native support for table partitioning.

HASH = 'hash'
LIST = 'list'
RANGE = 'range'
class psqlextra.types.StrEnum

An enumeration.

all = <bound method StrEnum.all of <enum 'StrEnum'>>
values = <bound method StrEnum.values of <enum 'StrEnum'>>
psqlextra.util.postgres_manager(model: Type[django.db.models.base.Model]) → Generator[psqlextra.manager.manager.PostgresManager, None, None]

Allows you to use the :see:PostgresManager with the specified model instance on the fly.

Parameters

model – The model or model instance to use this on.