]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commit
Ensure SQLite default expressions are parenthesized
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 25 Jun 2019 15:40:56 +0000 (11:40 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 25 Jun 2019 20:31:43 +0000 (16:31 -0400)
commitd4951ffb66f933ca332baf85faa15c7547523ecb
tree2d783ac42d6657f423cf36a56e624e402f8da828
parent26453a8b284743bd590a86208968ca862caa67ca
Ensure SQLite default expressions are parenthesized

- SQLite server default reflection will ensure parenthesis are surrounding a
column default expression that is detected as being a non-constant
expression, such as a ``datetime()`` default, to accommodate for the
requirement that SQL expressions have to be parenthesized when being sent
as DDL.  Parenthesis are not added to constant expressions to allow for
maximum cross-compatibility with other dialects and existing test suites
(such as Alembic's), which necessarily entails scanning the expression to
eliminate for constant numeric and string values. The logic is added to the
two "reflection->DDL round trip" paths which are currently autogenerate and
batch migration.  Within autogenerate, the logic is on the rendering side,
whereas in batch the logic is installed as a column reflection hook.

- Improved SQLite server default comparison to accommodate for a ``text()``
construct that added parenthesis directly vs. a construct that relied
upon the SQLAlchemy SQLite dialect to render the parenthesis, as well
as improved support for various forms of constant expressions such as
values that are quoted vs. non-quoted.

- Fixed bug where the "literal_binds" flag was not being set when
autogenerate would create a server default value, meaning server default
comparisons would fail for functions that contained literal values.

Fixes: #579
Change-Id: I78b87573b8ecd15cb4ced08f054902f574e3956c
alembic/autogenerate/compare.py
alembic/autogenerate/render.py
alembic/ddl/impl.py
alembic/ddl/sqlite.py
alembic/operations/batch.py
alembic/testing/fixtures.py
alembic/testing/requirements.py
docs/build/unreleased/579.rst [new file with mode: 0644]
tests/test_batch.py
tests/test_postgresql.py
tests/test_sqlite.py