summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorTom Carrick <tom@carrick.eu>2020-09-30 14:00:59 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-10-21 10:53:44 +0200
commitf5e07601b233a50e6bcca438f65fd7028277f78b (patch)
treeededb7ae60773eaad5afc7746431fe309e86d0bd /docs
parent0362b0e986303858081f607ffad2e8e14be8775e (diff)
Fixed #32046 -- Added CreateCollation/RemoveCollation operations for PostgreSQL.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/postgres/fields.txt10
-rw-r--r--docs/ref/contrib/postgres/operations.txt50
-rw-r--r--docs/releases/3.2.txt5
3 files changed, 65 insertions, 0 deletions
diff --git a/docs/ref/contrib/postgres/fields.txt b/docs/ref/contrib/postgres/fields.txt
index cd3908cf2e..df9ebc48d6 100644
--- a/docs/ref/contrib/postgres/fields.txt
+++ b/docs/ref/contrib/postgres/fields.txt
@@ -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``
===============
diff --git a/docs/ref/contrib/postgres/operations.txt b/docs/ref/contrib/postgres/operations.txt
index 5e4c7af6a5..ff37728d27 100644
--- a/docs/ref/contrib/postgres/operations.txt
+++ b/docs/ref/contrib/postgres/operations.txt
@@ -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
===========================
diff --git a/docs/releases/3.2.txt b/docs/releases/3.2.txt
index 232b20cb23..2f0f2f5a6d 100644
--- a/docs/releases/3.2.txt
+++ b/docs/releases/3.2.txt
@@ -135,6 +135,11 @@ Minor features
now checks that the extension already exists in the database and skips the
migration if so.
+* The new :class:`~django.contrib.postgres.operations.CreateCollation` and
+ :class:`~django.contrib.postgres.operations.RemoveCollation` operations
+ allow creating and dropping collations on PostgreSQL. See
+ :ref:`manage-postgresql-collations` for more details.
+
:mod:`django.contrib.redirects`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~