Skip to content

Commit 2852214

Browse files
Documentation section on configuring Alembic
1 parent a3085b3 commit 2852214

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

docs/index.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,38 @@ You can then generate an initial migration::
4949

5050
$ flask db migrate -m "Initial migration."
5151

52-
The migration script needs to be reviewed and edited, as Alembic currently does not detect every change you make to your models. In particular, Alembic is currently unable to detect table name changes, column name changes, or anonymously named constraints. A detailed summary of limitations can be found in the `Alembic autogenerate documentation <http://alembic.zzzcomputing.com/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect>`_. Once finalized, the migration script also needs to be added to version control.
52+
The migration script needs to be reviewed and edited, as Alembic is not always able to detect every change you make to your models. In particular, Alembic is currently unable to detect table name changes, column name changes, or anonymously named constraints. A detailed summary of limitations can be found in the `Alembic autogenerate documentation <https://alembic.sqlalchemy.org/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect>`_. Once finalized, the migration script also needs to be added to version control.
5353

54-
Then you can apply the migration to the database::
54+
Then you can apply the changes described by the migration script to your database::
5555

5656
$ flask db upgrade
5757
58-
Then each time the database models change repeat the ``migrate`` and ``upgrade`` commands.
58+
Each time the database models change, repeat the ``migrate`` and ``upgrade`` commands.
5959

6060
To sync the database in another system just refresh the `migrations` folder from source control and run the ``upgrade`` command.
6161

6262
To see all the commands that are available run this command::
6363

6464
$ flask db --help
6565

66-
Note that the application script must be set in the ``FLASK_APP`` environment variable for all the above commands to work, as required by the ``flask`` command line script.
66+
Note that the application script must be set in the ``FLASK_APP`` environment variable for all the above commands to work, as required by the ``flask`` command.
67+
68+
Alembic Configuration Options
69+
-----------------------------
70+
71+
Starting with version 4.0, Flask-Migrate automatically enables the following options that are disabled by default in Alembic:
72+
73+
- ``compare_type=True``: This option configures the automatic migration generation subsystem to detect column type changes.
74+
- ``render_as_batch=True``: This option generates migration scripts using `batch mode <https://alembic.sqlalchemy.org/en/latest/batch.html>`_, an operational mode that works around limitations of many ``ALTER`` commands in the SQLite database by implementing a "move and copy" workflow. Enabling this mode should make no difference when working with other databases.
75+
76+
To manually configure these or `other Alembic options <https://alembic.sqlalchemy.org/en/latest/api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure>`_, pass them as keyword arguments to the ``Migrate`` constructor. Example::
77+
78+
migrate = Migrate(app, db, render_as_batch=False)
6779

6880
Configuration Callbacks
6981
-----------------------
7082

71-
Sometimes applications need to dynamically insert their own settings into the Alembic configuration. A function decorated with the ``configure`` callback will be invoked after the configuration is read, and before it is used. The function can modify the configuration object, or replace it with a different one.
83+
Sometimes applications need to dynamically insert their own settings into the Alembic configuration. A function decorated with the ``configure`` callback will be invoked after the configuration is read, and before it is applied. The function can modify the configuration object, or replace it with a different one.
7284

7385
::
7486

0 commit comments

Comments
 (0)