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
Mike Bayer [Tue, 17 Mar 2020 14:27:40 +0000 (10:27 -0400)]
Support computed reflection.
Adjusted autogen comparison to accommodate for backends that support
computed column reflection, dependent on SQLAlchemy version 1.3.16 or
higher. This emits a warning if the SQL expression inside of a
:class:`.Computed` value changes between the metadata and the database, as
these expressions can't be changed without dropping and recreating the
column.
Mike Bayer [Thu, 12 Mar 2020 23:59:34 +0000 (19:59 -0400)]
Don't raise on pytest deprecation warnings
py.test 5.4.0 emits deprecation warnings for pytest.Class.
make sure we don't raise for these, and log the code that will
be used for 5.4.0 when we bump requirements.
Mike Bayer [Thu, 5 Mar 2020 17:13:46 +0000 (12:13 -0500)]
Vendor assert_raises[_message], add new check constraint target
SQLAlchemy in 1.3 / master is now checking that re-thrown exceptions
have a cause, which we haven't implemented for Alembic yet.
If we did implement this for Alembic, we'd still need to
vendor these two anyway to test. See
https://github.com/sqlalchemy/sqlalchemy/issues/4849
Also add "table_or_column_check_constraint" target so that
builds can pass, this was added for 1.4 / master
in
https://github.com/sqlalchemy/sqlalchemy/commit/ca2e4f385802799c2584782a8528e19a9e5513bc
Ke Zhu [Fri, 28 Feb 2020 21:00:57 +0000 (16:00 -0500)]
Respects ResultProxy.supports_sane_rowcount()
The check for matched rowcount when the alembic_version table is updated or
deleted from is now conditional based on whether or not the dialect
supports the concept of "rowcount" for UPDATE or DELETE rows matched. Some
third party dialects do not support this concept. Pull request courtesy Ke
Zhu.
Paul Becotte [Mon, 24 Feb 2020 14:39:55 +0000 (09:39 -0500)]
Include post-parenthesis tokens when tokenizing type string
Fixed regression caused by the new "type comparison" logic introduced in
1.4 as part of :ticket:`605` where comparisons of MySQL "unsigned integer"
datatypes would produce false positives, as the regular expression logic
was not correctly parsing the "unsigned" token when MySQL's default display
width would be returned by the database. Pull request courtesy Paul
Becotte.
Mike Bayer [Mon, 24 Feb 2020 14:25:41 +0000 (09:25 -0500)]
Add missing util.raise_from_cause
the re-vendoring of exclusions.py done by Mike
in 3ea190f843c7f246f73f91a looks for this function in util;
add it to the exported names from alembic.util.
Mike Bayer [Fri, 7 Feb 2020 22:58:17 +0000 (17:58 -0500)]
Vendor inspect.formatannotation
Vendored the ``inspect.formatannotation`` function inside of
``alembic.util.compat``, which is needed for the vendored version of
``inspect.formatargspec``. The function is not documented in cPython and
is not guaranteed to be available in future Python versions.
Mike Bayer [Thu, 6 Feb 2020 15:38:57 +0000 (10:38 -0500)]
Repair de-quoting logic used for pre-1.4 SQLAlchemy versions
Fixed regression in 1.4.0 due to :ticket:`647` where unique constraint
comparison with mixed case constraint names while not using a naming
convention would produce false positives during autogenerate.
Mike Bayer [Thu, 6 Feb 2020 15:56:17 +0000 (10:56 -0500)]
Render inline constraints for add_column
Fixed long-standing bug where an inline column CHECK constraint would not
be rendered within an "ADD COLUMN" operation. The DDL compiler is now
consulted for inline constraints within the :meth:`.Operations.add_column`
method as is done for regular CREATE TABLE operations.
Marcin Szymanski [Fri, 31 Jan 2020 01:36:15 +0000 (20:36 -0500)]
Support explicit column ordering in batch mode
Added new parameters :paramref:`.BatchOperations.add_column.insert_before`,
:paramref:`.BatchOperations.add_column.insert_after` which provide for
establishing the specific position in which a new column should be placed.
Also added :paramref:`.Operations.batch_alter_table.partial_reordering`
which allows the complete set of columns to be reordered when the new table
is created. Both operations apply only to when batch mode is recreating
the whole table using ``recreate="always"``. Thanks to Marcin Szymanski
for assistance with the implementation.
Paul Becotte [Fri, 24 Jan 2020 00:36:33 +0000 (19:36 -0500)]
Update the type comparison code used for schema autogeneration. Compare
A major rework of the "type comparison" logic is in place which changes the
entire approach by which column datatypes are compared. Types are now
compared based on the DDL string generated by the metadata type vs. the
datatype reflected from the database. This means we compare types based on
what would actually render and additionally if elements of the types change
like string length, those changes are detected as well. False positives
like those generated between SQLAlchemy Boolean and MySQL TINYINT should
also be resolved. Thanks very much to Paul Becotte for lots of hard work
and patience on this one.
Mike Bayer [Mon, 3 Feb 2020 17:20:10 +0000 (12:20 -0500)]
Use inspect(), not Inspector.from_engine()
The internal inspection routines no longer use SQLAlchemy's
``Inspector.from_engine()`` method, which is expected to be deprecated in
1.4. The ``inspect()`` function is now used.
layday [Mon, 3 Feb 2020 14:40:49 +0000 (09:40 -0500)]
Move use of ``__file__`` to be local to template access
Moved the use of the ``__file__`` attribute at the base of the Alembic
package into the one place that it is specifically needed, which is when
the config attempts to locate the template directory. This helps to allow
Alembic to be fully importable in environments that are using Python
memory-only import schemes. Pull request courtesy layday.
Mike Bayer [Thu, 30 Jan 2020 00:36:11 +0000 (19:36 -0500)]
Adjust unique constraint names based on dialect truncation rules
Adjusted the unique constraint comparison logic in a similar manner as that
of :ticket:`421` did for indexes in order to take into account SQLAlchemy's
own truncation of long constraint names when a naming convention is in use.
Without this step, a name that is truncated by SQLAlchemy based on a unique
constraint naming convention or hardcoded name will not compare properly.
Also remove unused MySQL _legacy_correct_for_dupe_uq_uix which is no
longer used.
CaselIT [Fri, 27 Dec 2019 22:26:38 +0000 (17:26 -0500)]
Add support for computed columns
Added support for rendering of "computed" elements on :class:`.Column`
objects, supported in SQLAlchemy via the new :class:`.Computed` element
introduced in version 1.3.11. Pull request courtesy Federico Caselli.
Note that there is currently no support for ALTER COLUMN to add, remove, or
modify the "GENERATED ALWAYS AS" element from a column; at least for
PostgreSQL, it does not seem to be supported by the database. Additionally,
SQLAlchemy does not currently reliably reflect the "GENERATED ALWAYS AS"
phrase from an existing column, so there is also no autogenerate support
for addition or removal of the :class:`.Computed` element to or from an
existing column, there is only support for adding new columns that include
the :class:`.Computed` element. In the case that the :class:`.Computed`
element is removed from the :class:`.Column` object in the table metadata,
PostgreSQL and Oracle currently reflect the "GENERATED ALWAYS AS"
expression as the "server default" which will produce an op that tries to
drop the element as a default.
In order to facilitate using testing combinations with elements that
are not necessarily present, the support for lambda combinations
from SQLAlchemy Ia63a510f9c1d08b055eef62cf047f1f427f0450c is also
ported here, as well as a vendoring in of the current
sqlalchemy.testing.exclusions module where we need the additional
combinations support added in I15d2839954d77a252bab5aaf6e3fd9f388c99dd5.
CaselIT [Fri, 27 Dec 2019 17:06:39 +0000 (12:06 -0500)]
Fix tests on windows
<!-- Provide a general summary of your proposed changes in the Title field above -->
Update the tests to make them run on windows
### Description
<!-- Describe your changes in detail -->
The main changes are:
- Correctly manage the paths on windows vs *nix like system.
- Manage the new lines \r\n vs \n
- Windows cannot remove open files, namely the sqlite db, so it keeps track of the connections and closes them before removing the files.
I've tested with sqlite, postgres and mysql and all pass (on windows 10)
This fixes #632
### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)
-->
This pull request is:
- [ ] A documentation / typographical error fix
- Good to go, no issue or tests are needed
- [x] A short code fix
- please include the issue number, and create an issue if none exists, which
must include a complete example of the issue. one line code fixes without an
issue and demonstration will not be accepted.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests. one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
- please include the issue number, and create an issue if none exists, which must
include a complete example of how the feature would look.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests.
Matthew Sills [Thu, 19 Dec 2019 15:03:12 +0000 (10:03 -0500)]
render table name with schema
Fixed issue where COMMENT directives for PostgreSQL failed to correctly
include an explicit schema name, as well as correct quoting rules for
schema, table, and column names. Pull request courtesy Matthew Sills.
Mike Bayer [Fri, 13 Dec 2019 15:05:55 +0000 (10:05 -0500)]
Provide a context for render_python_code
Fixed regression introduced by :ticket:`579` where server default rendering
functions began to require a dialect implementation, however the
:func:`.render_python_code` convenience function did not include one, thus
causing the function to fail when used in a server default context. The
function now accepts a migration context argument and also creates one
against the default dialect if one is not provided.
Mike Bayer [Thu, 28 Nov 2019 00:30:08 +0000 (19:30 -0500)]
Re-port bootstrap /plugin_base to get combinatoric functions
The py.test combinatoric functions are available in
SQLAlchemy's testing fixtures for version 1.3 and 1.4 only,
not 1.1 or 1.2.
This also needs to port the py.test test collection
function which was improved in SQLAlchemy 1.3 and also
made to accommodate for pytest.combinations, so we must
still vendor a minimum set of the "bootstrap" mechanism
for now.
Mike Bayer [Sat, 16 Nov 2019 00:13:11 +0000 (19:13 -0500)]
Restate installation and tutorial in terms of a virtualenv
Since we have things like "cd myproject" in the documentation,
we are assuming some knowledge of how the project is set up.
As the vast majority of projects will have import statements
in their env.py, restate this documentation in terms of a
virtual environment where the local project is installed
in editable mode.
Mike Bayer [Tue, 12 Nov 2019 15:01:42 +0000 (10:01 -0500)]
Support schemas for MSSQL drop server default + FK constraint
Fixed bug in MSSQL dialect where the drop constraint execution steps used
to remove server default or implicit foreign key constraint failed to take
into account the schema name of the target table.
Mike Bayer [Mon, 14 Oct 2019 04:07:55 +0000 (00:07 -0400)]
Accommodate for SQLAlchemy 1.4 deferral of index/unique names
Some internal modifications have been made to how the names of indexes and
unique constraints work to make use of new functions added in SQLAlchemy
1.4, so that SQLAlchemy has more flexibility over how naming conventions
may be applied to these objects.
Thomas Bechtold [Tue, 24 Sep 2019 14:27:03 +0000 (10:27 -0400)]
Revert alembic.stamp "revisions" to "revision"
Reverted the name change of the "revisions" argument to
:func:`.command.stamp` to "revision" as apparently applications are
calling upon this argument as a keyword name. Pull request courtesy
Thomas Bechtold. Special translations are also added to the command
line interface so that it is still known as "revisions" in the CLI.
Mike Bayer [Thu, 19 Sep 2019 20:59:27 +0000 (16:59 -0400)]
Add --package flag to write __init__.py files
Added new flag ``--package`` to ``alembic init``. For environments where
the Alembic migration files and such are within the package tree and
importable as modules, this flag can be specified which will add the
additional ``__init__.py`` files in the version location and the
environment location.
Mike Bayer [Thu, 19 Sep 2019 03:16:56 +0000 (23:16 -0400)]
Add multiple revision support to stamp, support purge
Added new ``--purge`` flag to the ``alembic stamp`` command, which will
unconditionally erase the version table before stamping anything. This is
useful for development where non-existent version identifiers might be left
within the table. Additionally, ``alembic.stamp`` now supports a list of
revision identifiers, which are intended to allow setting up muliple heads
at once. Overall handling of version identifiers within the
``alembic.stamp`` command has been improved with many new tests and
use cases added.
Mike Waites [Sun, 30 Dec 2018 16:09:27 +0000 (16:09 +0000)]
Provide revision post-write hooks
Added "post write hooks" to revision generation. The primary rationale is
to provide for code formatting tools to automatically format new revisions,
however any arbitrary script or Python function may be invoked as a hook.
The hooks are enabled by providing a ``[post_write_hooks]`` section in the
alembic.ini file. The provided hook is a command-line runner which
includes configuration examples for running Black or autopep8 on newly
generated revision scripts.
The documentation also illustrates a custom hook that converts Python
source spaces to tabs, as requested in #577.
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #307 Fixes: #577
Change-Id: I9d2092d20ec23f62ed3b33d979c16b979a450b48
Mike Bayer [Thu, 19 Sep 2019 01:47:27 +0000 (21:47 -0400)]
Memoize elements in rewriter; use correct iteration
Modified the logic of the :class:`.Rewriter` object such that it keeps a
memoization of which directives it has processed, so that it can ensure it
processes a particular directive only once, and additionally fixed
:class:`.Rewriter` so that it functions correctly for multiple-pass
autogenerate schemes, such as the one illustrated in the "multidb"
template. By tracking which directives have been processed, a
multiple-pass scheme which calls upon the :class:`.Rewriter` multiple times
for the same structure as elements are added can work without running
duplicate operations on the same elements more than once.
Mike Bayer [Tue, 17 Sep 2019 23:00:50 +0000 (19:00 -0400)]
Support autogenerate for add_column kwargs
Added autogenerate support for :class:`.Column` objects that have
dialect-specific ``**kwargs``, support first added in SQLAlchemy 1.3.
This includes SQLite "on conflict" as well as options used by some
third party dialects.
Mike Bayer [Tue, 17 Sep 2019 22:25:41 +0000 (18:25 -0400)]
Only allow partial revision match for > 3 characters
Made the command interface revision lookup behavior more strict in that an
Alembic revision number is only resolved based on a partial match rules if
it has at least four characters, to prevent simple typographical issues
from inadvertently running migrations.