diff options
author | CaselIT <cfederico87@gmail.com> | 2021-04-18 11:41:04 +0200 |
---|---|---|
committer | CaselIT <cfederico87@gmail.com> | 2021-06-22 23:05:35 +0200 |
commit | b511670231e99c5278d58e789f9efb7855488b41 (patch) | |
tree | 231ab1213581dc6db708f478d2d54d48dcd16518 /docs/build/cookbook.rst | |
parent | b1e5a23c0f53482dd06b013ce8a9453dd0e5eb5d (diff) | |
download | alembic-b511670231e99c5278d58e789f9efb7855488b41.tar.gz |
Drop compatibility with python 2.7.
Now alembic supports only python from version 3.6.
Change-Id: Iccf124c2d74af801d90a16c9003cdad318768625
Diffstat (limited to 'docs/build/cookbook.rst')
-rw-r--r-- | docs/build/cookbook.rst | 54 |
1 files changed, 1 insertions, 53 deletions
diff --git a/docs/build/cookbook.rst b/docs/build/cookbook.rst index d523062..a3de0f8 100644 --- a/docs/build/cookbook.rst +++ b/docs/build/cookbook.rst @@ -307,7 +307,7 @@ We'll use a simple value object called ``ReplaceableObject`` that can represent any named set of SQL text to send to a "CREATE" statement of some kind:: - class ReplaceableObject(object): + class ReplaceableObject: def __init__(self, name, sqltext): self.name = name self.sqltext = sqltext @@ -1445,58 +1445,6 @@ branched revision tree:: :meth:`.ScriptDirectory.get_heads` -Support Non-Ascii Migration Scripts / Messages under Python 2 -============================================================== - -To work with a migration file that has non-ascii characters in it under Python -2, the ``script.py.mako`` file inside of the Alembic environment has to have an -encoding comment added to the top that will render into a ``.py`` file: - -.. code-block:: mako - - <%text># coding: utf-8</%text> - -Additionally, individual fields if they are to have non-ascii characters in -them may require decode operations on the template values. Such as, if the -revision message given on the command line to ``alembic revision`` has -non-ascii characters in it, under Python 2 the command interface passes this -through as bytes, and Alembic has no decode step built in for this as it is not -necessary under Python 3. To decode, add a decoding step to the template for -each variable that potentially may have non-ascii characters within it. An -example of applying this to the "message" field is as follows: - -.. code-block:: mako - - <%! - import sys - %>\ - <%text># coding: utf-8</%text> - """${message.decode("utf-8") \ - if sys.version_info < (3, ) \ - and isinstance(message, str) else message} - - Revision ID: ${up_revision} - Revises: ${down_revision | comma,n} - Create Date: ${create_date} - - """ - from alembic import op - import sqlalchemy as sa - ${imports if imports else ""} - - # revision identifiers, used by Alembic. - revision = ${repr(up_revision)} - down_revision = ${repr(down_revision)} - branch_labels = ${repr(branch_labels)} - depends_on = ${repr(depends_on)} - - - def upgrade(): - ${upgrades if upgrades else "pass"} - - - def downgrade(): - ${downgrades if downgrades else "pass"} Using Asyncio with Alembic ========================== |