Mike Bayer [Sat, 20 Feb 2021 20:48:58 +0000 (15:48 -0500)]
Implement sys_path_prepend option
Added new config file option ``prepend_sys_path``, which is a series of
paths that will be prepended to sys.path; the default value in newly
generated alembic.ini files is ".". This fixes a long-standing issue
where for some reason running the alembic command line would not place the
local "." path in sys.path, meaning an application locally present in "."
and importable through normal channels, e.g. python interpreter, pytest,
etc. would not be located by Alembic, even though the ``env.py`` file is
loaded relative to the current path when ``alembic.ini`` contains a
relative path.
A fix for #753 was merged in November 2020 and released in 1.5.0 in January 2021.
This updates the references to #753 in cookbook.rst to note that a fix for #753 has been released.
Mike Bayer [Tue, 2 Feb 2021 05:18:48 +0000 (00:18 -0500)]
Adjust for immediate dependencies that are still ancestors
Fixed bug in versioning model where a downgrade across a revision with a
dependency on another branch, yet an ancestor is also dependent on that
branch, would produce an erroneous state in the alembic_version table,
making upgrades impossible without manually repairing the table.
Mike Bayer [Fri, 29 Jan 2021 01:10:33 +0000 (20:10 -0500)]
Remove obsolete SQLAlchemy pk issue workaround
Fixed issue where autogenerate rendering of ``op.alter_column()`` would
fail to include MySQL ``existing_nullable=False`` if the column were part
of a primary key constraint within the table metadata.
Mike Bayer [Wed, 27 Jan 2021 17:28:37 +0000 (12:28 -0500)]
Place index/uq drops before creates
Changed the default ordering of "CREATE" and "DROP" statements indexes and
unique constraints within the autogenerate process, so that for example in
an upgrade() operation, a particular index or constraint that is to be
replaced such as for a casing convention change will not produce any naming
conflicts. For foreign key constraint objects, this is already how
constraints are ordered, and for table objects, users would normally want
to use :meth:`.Operations.rename_table` in any case.
Mike Bayer [Wed, 20 Jan 2021 16:40:52 +0000 (11:40 -0500)]
ensure downrev/dependencies in tuple form before using "in"
Fixed regression where new "loop detection" feature introduced in
:ticket:`757` produced false positives for revision names that have
overlapping substrings between revision number and down revision and/or
dependency, if the downrev/dependency were not in sequence form.
Mike Bayer [Tue, 19 Jan 2021 19:26:46 +0000 (14:26 -0500)]
retrieve 1.3 transaction from branched connection properly
Fixed regression where Alembic would fail to create a transaction properly
if the :class:`sqlalchemy.engine.Connection` were a so-called "branched"
connection, that is, one where the ``.connect()`` method had been called to
create a "sub" connection.
Mike Bayer [Mon, 18 Jan 2021 17:27:38 +0000 (12:27 -0500)]
implement include_name hook
Added new hook :paramref:`.EnvironmentContext.configure.include_name`,
which complements the
:paramref:`.EnvironmentContext.configure.include_object` hook by providing
a means of preventing objects of a certain name from being autogenerated
**before** the SQLAlchemy reflection process takes place, and notably
includes explicit support for passing each schema name when
:paramref:`.EnvironmentContext.configure.include_schemas` is set to True.
This is most important especially for enviroments that make use of
:paramref:`.EnvironmentContext.configure.include_schemas` where schemas are
actually databases (e.g. MySQL) in order to prevent reflection sweeps of
the entire server.
The long deprecated
:paramref:`.EnvironmentContext.configure.include_symbol` hook is removed.
The :paramref:`.EnvironmentContext.configure.include_object`
and :paramref:`.EnvironmentContext.configure.include_name`
hooks both achieve the goals of this hook.
Mike Bayer [Tue, 12 Jan 2021 21:33:31 +0000 (16:33 -0500)]
disable SQLA 1.4 asyncio mode
The latest merge that uses SQLAlchemy's test suite
more fully is not functioning with the asyncio wrappers.
As we don't need those here right now, disable them.
CaselIT [Mon, 19 Oct 2020 21:23:08 +0000 (23:23 +0200)]
Accommodate SQLAlchemy 1.4/2.0
To accommodate SQLAlchemy 1.4 and 2.0, the migration model now no longer
assumes that the SQLAlchemy Connection will autocommit an individual
operation. This essentially means that for databases that use
non-transactional DDL (pysqlite current driver behavior, MySQL), there is
still a BEGIN/COMMIT block that will surround each individual migration.
Databases that support transactional DDL should continue to have the
same flow, either per migration or per-entire run, depending on the
value of the :paramref:`.Environment.configure.transaction_per_migration`
flag.
Compatibility is established such that the entire library should
not generate any SQLAlchemy 2.0 deprecation warnings and
SQLALCHEMY_WARN_20 is part of conftest.py. (one warning remains
for the moment that needs to be resolved on the SQLAlchemy side)
The test suite requires SQLAlchemy 1.4.0b2 for testing 1.4;
1.4.0b1 won't work.
Test suite / setup also being modernized, as we are at
SQLAlchemy 1.3 we can now remove the majority of the testing
suite plugin.
Mike Bayer [Sun, 27 Dec 2020 21:40:48 +0000 (16:40 -0500)]
Consult ApplyBatchImpl for hints on constraints to drop
Made an adjustment to the PostgreSQL dialect to allow it to work more
effectively in batch mode, where a datatype like Boolean or non-native Enum
that may have embedded rules to generate CHECK constraints will be more
correctly handled in that these constraints usually will not have been
generated on the PostgreSQL backend; previously it would inadvertently
assume they existed unconditionally in a special PG-only "drop constraint"
step.
CaselIT [Tue, 17 Nov 2020 21:32:36 +0000 (22:32 +0100)]
Add support identity columns.
Added support for rendering of "identity" elements on
:class:`.Column` objects, supported in SQLAlchemy via
the :class:`.Identity` element introduced in version 1.4.
Adding columns with identity is supported on PostgreSQL,
MSSQL and Oracle. Changing the identity options or removing
it is supported only on PostgreSQL and Oracle.
Koichiro Den [Tue, 1 Dec 2020 02:53:33 +0000 (21:53 -0500)]
Raise an exception if any loop or cycle found in a revision graph constructed.
The revision tree is now checked for cycles and loops between revision
files when the revision environment is loaded up. Scenarios such as a
revision pointing to itself, or a revision that can reach itself via a
loop, are handled and will raise the :class:`.CycleDetected` exception when
the environment is loaded (expressed from the Alembic commandline as a
failure message and nonzero return code). Previously, these situations were
silently ignored up front, and the behavior of revision traversal would
either be silently incorrect, or would produce errors such as
:class:`.RangeNotAncestorError`. Pull request courtesy Koichiro Den.
Added detection of Table prefixes in the create table render
Added rendering for the ``Table.prefixes`` element to autogenerate so that
the rendered Python code includes these directives. Pull request courtesy
Rodrigo Ce Moretto.
Mike Bayer [Thu, 5 Nov 2020 13:22:18 +0000 (08:22 -0500)]
Copy column that's already attached
Modified the ``add_column()`` operation such that the ``Column`` object in
use is shallow copied to a new instance if that ``Column`` is already
attached to a ``table()`` or ``Table``. This accommodates for the change
made in SQLAlchemy issue #5618 which prohibits a ``Column`` from being
associated with multiple ``table()`` objects. This resumes support for
using a ``Column`` inside of an Alembic operation that already refers to a
parent ``table()`` or ``Table`` as well as allows operation objects just
autogenerated to work.
Mike Bayer [Tue, 29 Sep 2020 16:55:41 +0000 (12:55 -0400)]
Add interim recipe for multi-tenant
Alembic does not have a multi-tenant story right now.
for the schema use case, search_path represents the best
way to make it happen at a rudimental level. Document
the basic idea for this as it is known to work for the moment.
Mike Bayer [Fri, 11 Sep 2020 13:56:14 +0000 (09:56 -0400)]
Use regular renderer for MySQL server default
Fixed issue where the MySQL dialect would not correctly render the server
default of a column in an alter operation, if the operation were
programmatically generated from an autogenerate pass as it would not
accommodate for the full structure of the DefaultClause construct.
Mike Bayer [Fri, 14 Aug 2020 23:28:19 +0000 (19:28 -0400)]
add MariaDB placeholder impl
in 599f27dcce62abac1f90a44f9c9a85e7dca885de we updated the
checks for "mariadb" to match SQLAlchemy 1.4. Another
change if merged will add a new dialect name "mariadb" that's
basically the mysql dialect with a different name; forwards-support
that as well.
Mike Bayer [Fri, 14 Aug 2020 20:19:58 +0000 (16:19 -0400)]
update mariadb checks
We want to revise mariadb version info stuff in
SQLAlchemy master so use _is_mariadb and
_mariadb_normalized_version_info
both of which are as far back as rel_1_1 at least
Fixed issue where the ``mssql_drop_foreign_key=True`` flag on
``op.drop_column`` would lead to incorrect syntax error due to a typo in the
SQL emitted, same typo was present in the test as well so it was not
detected. Pull request courtesy Oleg Shigorin.
Mike Bayer [Thu, 16 Jul 2020 01:23:31 +0000 (21:23 -0400)]
Support DROP of named check constraint from column for batch
Added support to drop named CHECK constraints that are specified as part of
a column, rather than table wide. Previously, only constraints associated
with the table were considered.
Mike Bayer [Tue, 2 Jun 2020 23:37:25 +0000 (19:37 -0400)]
Set create_constraint=True for Enum / Boolean tests
In SQLAlchemy [1] [2] we are changing the default
for Enum / Boolean create_constraint to False. ensure
tests that rely upon this setting being True set
it explicitly.
Fixed issue where the CAST applied to a JSON column when copying a SQLite
table during batch mode would cause the data to be lost, as SQLite's CAST
with JSON appears to convert the data to the value "0". The CAST is now
skipped in a dialect-specific manner, including for JSON columns on SQLite.
Pull request courtesy Sebastián Ramírez.
Ensure "alembic current" won't unnecessarily mutate the database
The ``alembic current`` command no longer creates an ``alembic_version``
table in the database if one does not exist already, returning no version
as the current version. This allows checking for migrations in parallel
without introducing race conditions. Pull request courtesy Nikolay
Edigaryev.
Mike Bayer [Tue, 24 Mar 2020 17:15:59 +0000 (13:15 -0400)]
Ensure default_schema_name set to None in "schema is none" test
A test here is working with the assumption that the default
schema name for the SQLite dialect is None. This assumption
is likely changing in SQLAlchemy 1.4 due to
Ia5c89eb27cc8dc2c5b8e76d6c07c46290a7901b6, so for this test
case explicitly set it to None.
Mike Bayer [Sat, 21 Mar 2020 14:21:41 +0000 (10:21 -0400)]
Remove pyproject.toml from distribution
Alembic does not want to opt-in to pep-517 at this time.
As the standard is not widely adopted at this time in any case. Per
[1] [2], the presence of this file indicates a positive opt-in
to pep-517, so it must be omitted from source distributions.
Mike Bayer [Thu, 19 Mar 2020 16:32:47 +0000 (12:32 -0400)]
Use looser tokenization for type comparison
Fixed more false-positive failures produced by the new "compare type" logic
first added in :ticket:`605`, particularly impacting MySQL string types
regarding flags such as "charset" and "collation".
Mike Bayer [Thu, 19 Mar 2020 17:15:48 +0000 (13:15 -0400)]
Don't include schema in "to" portion of Oracle RENAME table
Fixed issue in Oracle backend where a table RENAME with a schema-qualified
name would include the schema in the "to" portion, which is rejected by
Oracle.
CaselIT [Tue, 17 Mar 2020 22:03:32 +0000 (23:03 +0100)]
Support sqlalchemy 1.4 exec_driver_sql, text() for strings
Adjusted tests so that only connection-explicit execution
is used, along with the use of text() for string invocation.
Tests that are testing explicitly for deprecation warnings
will bypass SQLAlchemy warnings. Added the RemovedIn20 warning
as an error raise for these two specific deprecation cases.
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: I4f6b83366329aa95204522c9e99129021d1899fc