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.
Mike Bayer [Tue, 17 Sep 2019 21:55:44 +0000 (17:55 -0400)]
Render a single "pass" only for UpgradeOps, DowngradeOps
Improved the Python rendering of a series of migration operations such that
a single "pass" is rendered for a :class:`.UpgradeOps` or
:class:`.DowngradeOps` based on if no lines of Python code actually
rendered under the operation, rather than whether or not sub-directives
exist. Removed extra "pass" lines that would generate from the
:class:`.ModifyTableOps` directive so that these aren't duplicated under
operation rewriting scenarios.
Mike Bayer [Tue, 17 Sep 2019 21:43:47 +0000 (17:43 -0400)]
Use repr for table comment in create_table_comment / drop_table_comment
Fixed bug where rendering of comment text for table-level comments within
:meth:`.Operations.create_table_comment` and
:meth:`.Operations.drop_table_comment` was not properly quote-escaped
within rendered Python code for autogenerate.
Mike Bayer [Tue, 17 Sep 2019 19:26:32 +0000 (15:26 -0400)]
Add autocommit_block
Added new feature :meth:`.MigrationContext.autocommit_block`, a special
directive which will provide for a non-transactional block inside of a
migration script. The feature requres that: the database driver
(e.g. DBAPI) supports the AUTOCOMMIT isolation mode. The directive
also necessarily needs to COMMIT the existing transaction in progress
in order to enter autocommit mode.
Mike Bayer [Fri, 30 Aug 2019 17:51:44 +0000 (13:51 -0400)]
Drop python 3.4 support
mysqlclient is no longer working in Python 3.4, and as pip is also
emitting warnings for dropped support, in order to maintain CI
we need to drop Python 3.4. Also include 3.7, 3.8 in classifiers.
Mike Bayer [Mon, 26 Aug 2019 23:41:58 +0000 (19:41 -0400)]
change dist-html to use cp
for unknown reasons sphinx is suddenly having a problem with the
_static directory being moved a directory upwards, so change how
dist-html works to just build normally then move files
Mike Bayer [Mon, 26 Aug 2019 22:46:29 +0000 (18:46 -0400)]
remove python setup.py test
Removed the "python setup.py test" feature in favor of a straight run of
"tox". Per Pypa / pytest developers, "setup.py" commands are in general
headed towards deprecation in favor of tox. The tox.ini script has been
updated such that running "tox" with no arguments will perform a single run
of the test suite against the default installed Python interpreter.
Mike Bayer [Sun, 21 Jul 2019 16:56:20 +0000 (12:56 -0400)]
Bump to Alembic 1.1, bump requirements
Alembic 1.1 bumps the minimum version of SQLAlchemy to 1.1. As was the
case before, Python requirements remain at Python 2.7, or in the 3.x series
Python 3.4.
Mike Bayer [Sat, 20 Jul 2019 16:54:37 +0000 (12:54 -0400)]
Add dialect_options to environment; set paramstyle=named for offline
Fixed bug where the double-percent logic applied to some dialects such as
psycopg2 would be rendered in ``--sql`` mode, by allowing dialect options
to be passed through to the dialect used to generate SQL and then providing
``paramstyle="named"`` so that percent signs need not be doubled. For
users having this issue, existing env.py scripts need to add
``dialect_opts={"paramstyle": "named"}`` to their offline
context.configure(). See the ``alembic/templates/generic/env.py`` template
for an example.
The "alembic init" command will now proceed if the target directory exists
as long as it's still empty. Previously, it would not proceed if the
directory existed. The new behavior is modeled from what git does, to
accommodate for container or other deployments where an Alembic target
directory may need to be already mounted instead of being created with
alembic init. Pull request courtesy Aviskar KC.
Mike Bayer [Thu, 18 Jul 2019 15:59:59 +0000 (11:59 -0400)]
Fix imp warning
Fixed use of the deprecated "imp" module, which is used to detect pep3147
availability as well as to locate .pyc files, which started emitting
deprecation warnings during the test suite. The warnings were not being
emitted earlier during the test suite, the change is possibly due to
changes in py.test itself but this is not clear. The check for pep3147 is
set to True for any Python version 3.5 or greater now and importlib is used
when available. Note that some dependencies such as distutils may still be
emitting this warning. Tests are adjusted to accommodate for dependencies
that emit the warning as well.
Mike Bayer [Wed, 3 Jul 2019 17:38:48 +0000 (13:38 -0400)]
Add cookbook recipe for non-ascii migration files under python 2
Unicode-related directives can be added to ``script.py.mako``
and as this issue has never been reported for many years as well
as that Python 2 is deprecated, resolve this as a cookbook recipe
that illustrates where unicode related directives and conversions
need to occur under Python 2.
Mike Bayer [Tue, 25 Jun 2019 15:40:56 +0000 (11:40 -0400)]
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.
Report warnings from caller's file/line number, not utils.py
Warnings emitted by Alembic now include a default stack level of 2, and in
some cases it's set to 3, in order to help warnings indicate more closely
where they are originating from. Pull request courtesy Ash Berlin-Taylor.
Mike Bayer [Mon, 3 Jun 2019 16:52:12 +0000 (12:52 -0400)]
Add "usecase" changelog tag
"usecase" indicates the library now supports something a user
was trying to do. It's not quite a "feature" since it's something
that seems like it should have worked, it's not a "bug" because
no mistake was made, it's just something that wasn't considered before.
The advantage of "usecase" is that it inherently suggests a different
style of prioritization vs. something that is preventing the library
from working as designed.
This change also adds docs/build/conf.py under the pep8 formatting
test coverage, and additionally moves release / release_date to
be present within; the release scripts will be altered to include
this.
Mike Bayer [Wed, 29 May 2019 21:32:57 +0000 (17:32 -0400)]
Use vendored getargspec()
Replaced the Python compatbility routines for ``getargspec()`` with a fully
vendored version based on ``getfullargspec()`` from Python 3.3.
Originally, Python was emitting deprecation warnings for this function in
Python 3.8 alphas. While this change was reverted, it was observed that
Python 3 implementations for ``getfullargspec()`` are an order of magnitude
slower as of the 3.4 series where it was rewritten against ``Signature``.
While Python plans to improve upon this situation, SQLAlchemy projects for
now are using a simple replacement to avoid any future issues.
Mike Bayer [Mon, 20 May 2019 17:29:55 +0000 (13:29 -0400)]
Use CHANGE COLUMN for MySQL / MariaDB DateTime server default change
Fixed issue where MySQL databases need to use CHANGE COLUMN when altering a
server default of CURRENT_TIMESTAMP, NOW() and probably other functions
that are only usable with DATETIME/TIMESTAMP columns. While MariaDB
supports both CHANGE and ALTER COLUMN in this case, MySQL databases only
support CHANGE. So the new logic is that if the server default change is
against a DateTime-oriented column, the CHANGE format is used
unconditionally, as in the vast majority of cases the server default is to
be CURRENT_TIMESTAMP which may also be potentially bundled with an "ON
UPDATE CURRENT_TIMESTAMP" directive, which SQLAlchemy does not currently
support as a distinct field.
Mike Bayer [Sun, 19 May 2019 22:33:39 +0000 (18:33 -0400)]
Create alter column backend test fixture
For more expedient confirmation of op functionality,
start building generalized backend fixtures for ops.
Add basic round trip tests for alter column, obviously
disabled on SQLite. Ensure this passes for the full
span of MySQL, Oracle, SQL Server on CI (PG is fine).
Next we can begin adding tests for all the MySQL issues
that are coming up such as #564, where regular ALTER COLUMN
is not consistently implemented based on datatypes etc.