2016-01-03 18:56:22 +08:00
|
|
|
=============================
|
2014-03-15 01:34:49 +08:00
|
|
|
Database migration operations
|
|
|
|
=============================
|
|
|
|
|
|
|
|
All of these :doc:`operations </ref/migration-operations>` are available from
|
|
|
|
the ``django.contrib.postgres.operations`` module.
|
|
|
|
|
2016-11-05 21:18:11 +08:00
|
|
|
.. _create-postgresql-extensions:
|
|
|
|
|
|
|
|
Creating extension using migrations
|
|
|
|
===================================
|
|
|
|
|
|
|
|
You can create a PostgreSQL extension in your database using a migration file.
|
|
|
|
This example creates an hstore extension, but the same principles apply for
|
|
|
|
other extensions.
|
|
|
|
|
|
|
|
Set up the hstore extension in PostgreSQL before the first ``CreateModel``
|
|
|
|
or ``AddField`` operation that involves
|
|
|
|
:class:`~django.contrib.postgres.fields.HStoreField` by adding a migration with
|
|
|
|
the :class:`~django.contrib.postgres.operations.HStoreExtension` operation.
|
|
|
|
For example::
|
|
|
|
|
|
|
|
from django.contrib.postgres.operations import HStoreExtension
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
...
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
HStoreExtension(),
|
|
|
|
...
|
|
|
|
]
|
|
|
|
|
|
|
|
Creating the extension requires a database user with superuser privileges.
|
|
|
|
If the Django database user doesn't have superuser privileges, you'll have
|
|
|
|
to create the extension outside of Django migrations with a user that has
|
|
|
|
the appropriate privileges. In that case, connect to your Django database and
|
|
|
|
run the query ``CREATE EXTENSION IF NOT EXISTS hstore;``.
|
|
|
|
|
2014-03-15 01:34:49 +08:00
|
|
|
.. currentmodule:: django.contrib.postgres.operations
|
|
|
|
|
2016-01-25 05:26:11 +08:00
|
|
|
``CreateExtension``
|
|
|
|
===================
|
2014-03-15 01:34:49 +08:00
|
|
|
|
|
|
|
.. class:: CreateExtension(name)
|
|
|
|
|
|
|
|
An ``Operation`` subclass which installs PostgreSQL extensions.
|
|
|
|
|
|
|
|
.. attribute:: name
|
|
|
|
|
|
|
|
This is a required argument. The name of the extension to be installed.
|
|
|
|
|
2016-08-08 11:15:08 +08:00
|
|
|
``BtreeGinExtension``
|
|
|
|
=====================
|
|
|
|
|
|
|
|
.. class:: BtreeGinExtension()
|
|
|
|
|
|
|
|
Install the ``btree_gin`` extension.
|
|
|
|
|
2017-07-01 21:30:34 +08:00
|
|
|
``BtreeGistExtension``
|
|
|
|
======================
|
|
|
|
|
|
|
|
.. class:: BtreeGistExtension()
|
|
|
|
|
|
|
|
.. versionadded:: 2.0
|
|
|
|
|
|
|
|
Install the ``btree_gist`` extension.
|
|
|
|
|
2016-06-02 05:43:59 +08:00
|
|
|
``CITextExtension``
|
|
|
|
===================
|
|
|
|
|
|
|
|
.. class:: CITextExtension()
|
|
|
|
|
|
|
|
Installs the ``citext`` extension.
|
|
|
|
|
2017-03-30 05:52:42 +08:00
|
|
|
``CryptoExtension``
|
|
|
|
===================
|
|
|
|
|
|
|
|
.. class:: CryptoExtension()
|
|
|
|
|
|
|
|
.. versionadded:: 2.0
|
|
|
|
|
|
|
|
Installs the ``pgcrypto`` extension.
|
|
|
|
|
2016-01-25 05:26:11 +08:00
|
|
|
``HStoreExtension``
|
|
|
|
===================
|
2014-03-15 01:34:49 +08:00
|
|
|
|
|
|
|
.. class:: HStoreExtension()
|
|
|
|
|
2016-08-13 06:03:19 +08:00
|
|
|
Installs the ``hstore`` extension and also sets up the connection to
|
|
|
|
interpret hstore data for possible use in subsequent migrations.
|
2014-09-06 04:53:11 +08:00
|
|
|
|
2015-06-06 00:37:48 +08:00
|
|
|
``TrigramExtension``
|
|
|
|
====================
|
|
|
|
|
|
|
|
.. class:: TrigramExtension()
|
|
|
|
|
2016-08-13 06:03:19 +08:00
|
|
|
Installs the ``pg_trgm`` extension.
|
2015-06-06 00:37:48 +08:00
|
|
|
|
2016-01-25 05:26:11 +08:00
|
|
|
``UnaccentExtension``
|
|
|
|
=====================
|
2014-09-06 04:53:11 +08:00
|
|
|
|
|
|
|
.. class:: UnaccentExtension()
|
|
|
|
|
2016-08-13 06:03:19 +08:00
|
|
|
Installs the ``unaccent`` extension.
|