Fixed #32046 -- Added CreateCollation/RemoveCollation operations for PostgreSQL.

This commit is contained in:
Tom Carrick 2020-09-30 14:00:59 +02:00 committed by Mariusz Felisiak
parent 0362b0e986
commit f5e07601b2
6 changed files with 366 additions and 5 deletions

View file

@ -285,6 +285,16 @@ transform do not change. For example::
.. _citext: https://www.postgresql.org/docs/current/citext.html
.. _the performance considerations: https://www.postgresql.org/docs/current/citext.html#id-1.11.7.17.7
.. admonition:: Case-insensitive collations
On PostgreSQL 12+, it's preferable to use non-deterministic collations
instead of the ``citext`` extension. You can create them using the
:class:`~django.contrib.postgres.operations.CreateCollation` migration
operation. For more details, see :ref:`manage-postgresql-collations` and
the PostgreSQL documentation about `non-deterministic collations`_.
.. _non-deterministic collations: https://www.postgresql.org/docs/current/collation.html#COLLATION-NONDETERMINISTIC
``HStoreField``
===============

View file

@ -115,6 +115,56 @@ them. In that case, connect to your Django database and run the query
Installs the ``unaccent`` extension.
.. _manage-postgresql-collations:
Managing collations using migrations
====================================
.. versionadded:: 3.2
If you need to filter or order a column using a particular collation that your
operating system provides but PostgreSQL does not, you can manage collations in
your database using a migration file. These collations can then be used with
the ``db_collation`` parameter on :class:`~django.db.models.CharField`,
:class:`~django.db.models.TextField`, and their subclasses.
For example, to create a collation for German phone book ordering::
from django.contrib.postgres.operations import CreateCollation
class Migration(migrations.Migration):
...
operations = [
CreateCollation(
'german_phonebook',
provider='icu',
locale='und-u-ks-level2',
),
...
]
.. class:: CreateCollation(name, locale, *, provider='libc', deterministic=True)
Creates a collation with the given ``name``, ``locale`` and ``provider``.
Set the ``deterministic`` parameter to ``False`` to create a
non-deterministic collation, such as for case-insensitive filtering.
.. class:: RemoveCollation(name, locale, *, provider='libc', deterministic=True)
Removes the collations named ``name``.
When reversed this is creating a collation with the provided ``locale``,
``provider``, and ``deterministic`` arguments. Therefore, ``locale`` is
required to make this operation reversible.
.. admonition:: Restrictions
PostgreSQL 9.6 only supports the ``'libc'`` provider.
Non-deterministic collations are supported only on PostgreSQL 12+.
Concurrent index operations
===========================