summaryrefslogtreecommitdiff
path: root/docs/build/ops.rst
blob: c8d6d771c84e519f80f614e1a145a45334bbb5fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
.. _ops:

===================
Operation Reference
===================

This file provides documentation on Alembic migration directives.

The directives here are used within user-defined migration files,
within the ``upgrade()`` and ``downgrade()`` functions, as well as
any functions further invoked by those.

All directives exist as methods on a class called :class:`.Operations`.
When migration scripts are run, this object is made available
to the script via the ``alembic.op`` datamember, which is
a *proxy* to an actual instance of :class:`.Operations`.
Currently, ``alembic.op`` is a real Python module, populated
with individual proxies for each method on :class:`.Operations`,
so symbols can be imported safely from the ``alembic.op`` namespace.

The :class:`.Operations` system is also fully extensible.  See
:ref:`operation_plugins` for details on this.

A key design philosophy to the :ref:`alembic.operations.toplevel` methods is that
to the greatest degree possible, they internally generate the
appropriate SQLAlchemy metadata, typically involving
:class:`~sqlalchemy.schema.Table` and :class:`~sqlalchemy.schema.Constraint`
objects.  This so that migration instructions can be
given in terms of just the string names and/or flags involved.
The exceptions to this
rule include the :meth:`~.Operations.add_column` and :meth:`~.Operations.create_table`
directives, which require full :class:`~sqlalchemy.schema.Column`
objects, though the table metadata is still generated here.

The functions here all require that a :class:`.MigrationContext` has been
configured within the ``env.py`` script first, which is typically
via :meth:`.EnvironmentContext.configure`.   Under normal
circumstances they are called from an actual migration script, which
itself would be invoked by the :meth:`.EnvironmentContext.run_migrations`
method.

.. module:: alembic.operations

.. autoclass:: AbstractOperations
    :members:

.. autoclass:: Operations
    :members:

.. autoclass:: BatchOperations
    :members: