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
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.