django_evolution.db.postgresql

Evolution operations backend for Postgres.

Classes

EvolutionOperations(database_state[, connection])

Evolution operations for Postgres databases.

class django_evolution.db.postgresql.EvolutionOperations(database_state, connection=<django.db.DefaultConnectionProxy object>)

Bases: BaseEvolutionOperations

Evolution operations for Postgres databases.

name = 'Postgres'

The name of the database type.

New in version 2.3.

default_tablespace = 'pg_default'

The default tablespace for the database, if tablespaces are supported.

New in version 2.2.

Type:

unicode

change_column_type_sets_attrs = False

Whether a column type change operation also sets new attributes.

If False, attributes will be set through the standard field change operation.

New in version 2.2.

Type:

bool

alter_field_type_map = {'bigserial': 'bigint', 'serial': 'integer', 'smallserial': 'smallint'}

A mapping of field types for use when altering types.

New in version 2.2.

get_change_column_type_sql(model, old_field, new_field)

Return SQL to change the type of a column.

New in version 2.2.

Parameters:
Returns:

The SQL statements for changing the column type.

Return type:

django_evolution.sql_result.AlterTableSQLResult

rename_column(model, old_field, new_field)

Renames the specified column.

This must be implemented by subclasses. It must return an SQLResult or AlterTableSQLResult representing the SQL needed to rename the column.

get_drop_unique_constraint_sql(model, index_name)
get_default_index_name(table_name, field)

Return a default index name for the database.

This will return an index name for the given field that matches what the database or Django database backend would automatically generate when marking a field as indexed or unique.

This can be overridden by subclasses if the database or Django database backend provides different values.

Parameters:
Returns:

The name of the index.

Return type:

str

get_indexes_for_table(table_name)

Return all known indexes on a table.

This is a fallback used only on Django 1.6, due to lack of proper introspection on that release.

Parameters:

table_name (unicode) – The name of the table.

Returns:

A dictionary mapping index names to a dictionary containing:

columns (list):

The list of columns that the index covers.

unique (bool):

Whether this is a unique index.

Return type:

dict

normalize_bool(value)
change_column_attr_decimal_type(model, mutation, field, new_max_digits, new_decimal_places)

Return SQL for changing a column’s max digits and decimal places.

This is used for DecimalField and subclasses to change the maximum number of digits or decimal places. As these are used together as a column type, they must be considered together as one attribute change.

Parameters:
  • model (type) – The model class that owns the field.

  • mutation (django_evolution.mutations.BaseModelMutation) – The mutation applying this change.

  • field (django.db.models.DecimalField) – The field being modified.

  • new_max_digits (int) – The new value for max_digits. If None, it wasn’t provided in the attribute change.

  • new_decimal_places (int) – The new value for decimal_places. If None, it wasn’t provided in the attribute change.

Returns:

The SQL for modifying the value.

Return type:

django_evolution.db.sql_result.AlterTableSQLResult