Fixed #24109 -- Allowed RunSQL and RunPython operations to be elided.

Thanks to Markus Holtermann and Tim Graham for their review.
This commit is contained in:
Simon Charette 2016-01-09 03:12:46 -05:00
parent 49f4c9f4c6
commit 729e0b086d
9 changed files with 81 additions and 8 deletions

View file

@ -196,7 +196,7 @@ Special Operations
RunSQL
------
.. class:: RunSQL(sql, reverse_sql=None, state_operations=None, hints=None)
.. class:: RunSQL(sql, reverse_sql=None, state_operations=None, hints=None, elidable=False)
Allows running of arbitrary SQL on the database - useful for more advanced
features of database backends that Django doesn't support directly, like
@ -249,6 +249,9 @@ The optional ``hints`` argument will be passed as ``**hints`` to the
routing decisions. See :ref:`topics-db-multi-db-hints` for more details on
database hints.
The optional ``elidable`` argument determines whether or not the operation will
be removed (elided) when :ref:`squashing migrations <migration-squashing>`.
.. attribute:: RunSQL.noop
Pass the ``RunSQL.noop`` attribute to ``sql`` or ``reverse_sql`` when you
@ -257,10 +260,14 @@ database hints.
.. _sqlparse: https://pypi.python.org/pypi/sqlparse
.. versionadded:: 1.10
The ``elidable`` argument was added.
RunPython
---------
.. class:: RunPython(code, reverse_code=None, atomic=True, hints=None)
.. class:: RunPython(code, reverse_code=None, atomic=True, hints=None, elidable=False)
Runs custom Python code in a historical context. ``code`` (and ``reverse_code``
if supplied) should be callable objects that accept two arguments; the first is
@ -278,6 +285,9 @@ The optional ``hints`` argument will be passed as ``**hints`` to the
routing decision. See :ref:`topics-db-multi-db-hints` for more details on
database hints.
The optional ``elidable`` argument determines whether or not the operation will
be removed (elided) when :ref:`squashing migrations <migration-squashing>`.
You are advised to write the code as a separate function above the ``Migration``
class in the migration file, and just pass it to ``RunPython``. Here's an
example of using ``RunPython`` to create some initial objects on a ``Country``
@ -366,6 +376,10 @@ attribute.
you want the operation not to do anything in the given direction. This is
especially useful in making the operation reversible.
.. versionadded:: 1.10
The ``elidable`` argument was added.
SeparateDatabaseAndState
------------------------