Mike Bayer [Wed, 10 Jan 2024 15:13:16 +0000 (10:13 -0500)]
dont pass empty sequences to connection.execute()
Fixed internal issue where Alembic would call ``connection.execute()``
sending an empty tuple to indicate "no params". In SQLAlchemy 2.1 this
case will be deprecated as "empty sequence" is ambiguous as to its intent.
Mike Bayer [Wed, 20 Dec 2023 00:06:11 +0000 (19:06 -0500)]
remove python 3.9 from pep-484 suite on github actions
since the major typing update in f443584f994a7a6426197f9f
just merged, python 3.9 is failing
for some reason, but 3.9 support w/ 100% mypy is not priority,
just remove from gh actions
Mike Bayer [Wed, 13 Dec 2023 16:05:03 +0000 (11:05 -0500)]
finish strict typing for most modules
Updated pep-484 typing to pass mypy "strict" mode, however including
per-module qualifications for specific typing elements not yet complete.
This allows us to catch specific typing issues that have been ongoing
such as import symbols not properly exported.
Saif Hakim [Wed, 13 Dec 2023 05:59:59 +0000 (00:59 -0500)]
Fix downgrade when normalized down revisions have overlap via depends_on
Fixed bug in versioning model where a downgrade across a revision with two
down revisions with one down revision depending on the other, would produce
an erroneous state in the alembic_version table, making upgrades impossible
without manually repairing the table. Thanks much to Saif Hakim for
the great work on this.
<!-- Provide a general summary of your proposed changes in the Title field above -->
When the alembic tree has a migration (a1), with a branched migration (b1) that `depends_on` that migration, followed by a merge migration that merges (a1) and (b1), running the merge migrations downgrade incorrectly updates the heads to [a1, b1], when it should actually just have [b1]. This then prevents a user from running the upgrade again due to the confusing error:
> Requested revision b1 overlaps with other requested revisions a1
The problem occurs in `HeadMaintainer.update_to_step` which will update the value of heads by calling out into a helper method based on the scenario: deleting branches, creating branches, merging branches, unmerging branches, or the typical non-branched migration. As it turns out, all of these methods have logic to determine the canonical set of heads that should be written, _except_ in the case we are unmerging, resulting in the redundant head.
To fix, we simply remove any ancestors of the target heads from the list of target heads when doing an unmerge.
l-hedgehog [Mon, 11 Dec 2023 20:24:56 +0000 (15:24 -0500)]
Improve `Rewriter` implementation
Fixes #1337
### Description
* Fix the chaining of more than two rewriters
* Wrap a callable so that it could be chained
This works in my local test, and I hope it makes sense to use the callable wrapper as the base class.
### Checklist
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.
Iuri de Silvio [Mon, 4 Dec 2023 18:22:22 +0000 (13:22 -0500)]
Keep the unique flag in `DropIndexOp`
Fixed issue where the "unique" flag of an ``Index`` would not be maintained
when generating downgrade migrations. Pull request courtesy Iuri de
Silvio.
Iuri de Silvio [Mon, 4 Dec 2023 16:55:24 +0000 (11:55 -0500)]
Fix `get_x_arguments(as_dictionary=True)` for args without `=`
Fixed issue where ``get_x_arguments(as_dictionary=True)`` would fail if an
argument key were passed without an equal sign ``=`` or a value.
Behavior is repaired where this condition is detected and will return a
blank string for the given key, consistent with the behavior where the
``=`` sign is present and no value. Pull request courtesy Iuri de Silvio.
Neil Williams [Wed, 22 Nov 2023 18:51:48 +0000 (13:51 -0500)]
Fix 'alembic check' with multidb env
Fixed issue where the ``alembic check`` command did not function correctly
with upgrade structures that have multiple, top-level elements, as are
generated from the "multi-env" environment template. Pull request courtesy
Neil Williams.
Merouane Atig [Wed, 22 Nov 2023 17:42:46 +0000 (12:42 -0500)]
Fix typo in alembic.ini templates
### Description
Fix typo in alembic.ini templates: requied => required
### Checklist
This pull request is:
- [x] A documentation / typographical error fix
- Good to go, no issue or tests are needed
- [ ] 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.
Federico Caselli [Sat, 21 Oct 2023 19:06:57 +0000 (21:06 +0200)]
More PostgreSQL expression index compare fixes
Additional fixes to PostgreSQL expression index compare feature.
The compare now correctly accommodates casts and differences in
spacing.
Added detection logic for operation clauses inside the expression,
skipping the compare of these expressions.
To accommodate these changes the logic for the comparison of the
indexes and unique constraints was moved to the dialect
implementation, allowing greater flexibility.
Mike Bayer [Sat, 18 Nov 2023 14:58:13 +0000 (09:58 -0500)]
add batch template for render create_table_comment, drop_table_comment
Fixed autogenerate issue where ``create_table_comment()`` and
``drop_table_comment()`` rendering in a batch table modify would include
the "table" and "schema" arguments, which are not accepted in batch as
these are already part of the top level block.
Federico Caselli [Thu, 26 Oct 2023 22:10:01 +0000 (00:10 +0200)]
Use zoneinfo instead of dateutil.
Replaced ``python-dateutil`` with the standard library module
`zoneinfo <https://docs.python.org/3.11/library/zoneinfo.html#module-zoneinfo>`.
This module was added in Python 3.9, so previous version will been
to install the backport of it, available by installing the ``backports.zoneinfo``
library. The ``alembic[tz]`` option has been updated accordingly.
l-hedgehog [Thu, 16 Nov 2023 14:23:47 +0000 (09:23 -0500)]
Open up `if_(not_)?exists` to SQLAlchemy 1.4+
Fixes #1323
### Description
As the title describes, open up `if_(not_)?exists` support (both implementations and tests) to SQLAlchemy 1.4+
### Checklist
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.
Iuri de Silvio [Wed, 8 Nov 2023 19:06:28 +0000 (14:06 -0500)]
Fixes: #1348 Typings for target_metadata sequence of metadatas
<!-- Provide a general summary of your proposed changes in the Title field above -->
Ref #1348
Add `Sequence[MetaData]` typing to `target_metadata` args.
### Description
<!-- Describe your changes in detail -->
### 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.
Update test to take into consideration the case where greenlet is not
installed. This is to support sqlalchemy 2.1 that removes it as
required dependency
Fix typing of `revision` argument in "Don't Generate Empty Migrations with Autogenerate" recipe
### Description
Type-annotations were added to the "Don't Generate Empty Migrations with Autogenerate" cookbook recipe in commit 3e48ed0. Later, in commit 222e4ba, the type of the `revision` argument to `process_revision_directives()` was changed from `tuple[str, str]` to `str | Iterable[str | None] | Iterable[str]`, but the recipe was not updated. This PR updates the recipe so that it will type-check.
### Checklist
This pull request is:
- [x] A documentation / typographical error fix
- Good to go, no issue or tests are needed
- [ ] 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.
Repaired :class:`.ExecuteSQLOp` so that it can participate in "diff"
operations; while this object is typically not present in a reflected
operation stream, custom hooks may be adding this construct where it needs
to have the correct ``to_diff_tuple()`` method. Pull request courtesy
Sebastian Bayer.
Sebastian Bayer [Wed, 25 Oct 2023 13:26:51 +0000 (09:26 -0400)]
Update of the no-empty-migrations snippet to work with alembic check
### Description
Update of the no-empty-migrations snippet to work with alembic check, see https://github.com/sqlalchemy/alembic/discussions/1332
### 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:
- [ x] A documentation / typographical error fix
- Good to go, no issue or tests are needed
- [ ] 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.
Mike Bayer [Thu, 19 Oct 2023 14:59:39 +0000 (10:59 -0400)]
render .info in create_table
Fixed regression caused by :ticket:`879` released in 1.7.0 where the
".info" dictionary of ``Table`` would not render in autogenerate create
table statements. This can be useful for custom create table DDL rendering
schemes so it is restored.
Additionally upon seeing that Rewriter is failing typing that was
just imporved in the previous commit for #1325 /
Ibfb7a57a081818c290cf0964d12a72b85c2c1983, further correct the typing
of the "revision" argument for process_revision_directives which was
still inconsistent.
Mike Bayer [Tue, 17 Oct 2023 23:18:20 +0000 (19:18 -0400)]
match process_revision_directives typing to API
Improved typing in the
:paramref:`.EnvironmentContext.configure.process_revision_directives`
callable to better indicate that the passed-in type is
:class:`.MigrationScript`, not the :class:`.MigrationOperation` base class,
and added typing to the example at :ref:`cookbook_no_empty_migrations` to
illustrate.
Mike Bayer [Thu, 12 Oct 2023 17:29:58 +0000 (13:29 -0400)]
apply PG ddl paren rules to index expressions
Fixed autogen render issue where expressions inside of indexes for PG need
to be double-parenthesized, meaning a single parens must be present within
the generated ``text()`` construct.
Mihail Milushev [Thu, 31 Aug 2023 20:02:22 +0000 (16:02 -0400)]
Improve typing of `op.execute`
Update type annotation for `sqltext` argument of `op.execute` to support
all the documented acceptable types.
Add unit tests for `str` and `TextClause` use cases for `sqltext` argument.
Small repetition cleanup of documentation.
Federico Caselli [Thu, 31 Aug 2023 21:25:04 +0000 (23:25 +0200)]
Improve typings
Misc changes to improve the typing of alembic:
- Improve typing of the revision parameter in various command functions.
- Properly type the :paramref:`.Operations.create_check_constraint.condition`
parameter of :meth:`.Operations.create_check_constraint` to accept boolean
expressions.
d3 [Tue, 29 Aug 2023 11:27:04 +0000 (07:27 -0400)]
Allow passoing ExcludeConstraint to DropConstraint.from_constraint
Added support for ``op.drop_constraint()`` to support PostrgreSQL
``ExcludeConstraint`` objects, as well as other constraint-like objects
that may be present in third party dialects, by resolving the ``type_``
parameter to be ``None`` for this case. Autogenerate has also been
enhanced to exclude the ``type_`` parameter from rendering within this
command when ``type_`` is ``None``. Pull request courtesy David Hills.
Asib Kamalsada [Fri, 25 Aug 2023 13:13:30 +0000 (09:13 -0400)]
Add `match` keyword argument to rendering of foreign key constraints
Fixed issue where the ``ForeignKeyConstraint.match`` parameter would not be
rendered in autogenerated migrations. Pull request courtesy Asib
Kamalsada.
Mihail Milushev [Tue, 22 Aug 2023 18:07:30 +0000 (14:07 -0400)]
Implement new `exec` write-hook runner that will execute arbitrary binaries
Added new feature to the "code formatter" function which allows standalone
executable tools to be run against code, without going through the Python
interpreter. Known as the ``exec`` runner, it complements the existing
``console_scripts`` runner by allowing non-Python tools such as ``ruff`` to
be used. Pull request courtesy Mihail Milushev.
Mike Bayer [Tue, 22 Aug 2023 19:39:38 +0000 (15:39 -0400)]
implement revision_environment for merge
Fixed issue where the ``revision_environment`` directive in ``alembic.ini``
was ignored by the ``alembic merge`` command, leading to issues when other
configurational elements depend upon ``env.py`` being invoked within the
command.
Kevin Kirsche [Fri, 11 Aug 2023 14:06:36 +0000 (10:06 -0400)]
Specify `"locale"` encoding when reading configuration file
Added ``encoding="locale"`` setting to the use of Python's
``ConfigParser.read()``, so that a warning is not generated when using the
recently added Python feature ``PYTHONWARNDEFAULTENCODING`` specified in
:pep:`597`. The encoding is passed as the ``"locale"`` string under Python
3.10 and greater, which indicates that the system-level locale should be
used, as was the case already here. Pull request courtesy Kevin Kirsche.
Added parameters if_exists and if_not_exists for index operations.
Fixes: #151
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
<!-- Describe your changes in detail -->
As mentioned in #151, IF EXISTS/IF NOT EXISTS syntax was implemented in SQLAlchemy 2.0. This request adds an ability to use them for index operations.
If the issue implies to implement all the possible cases with these directives, I could continue working on it 🙂
### 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
- [ ] 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.
- [x] 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.
Mathieu Défosse [Sat, 17 Jun 2023 17:46:08 +0000 (13:46 -0400)]
Fixed CLI output when running post_write hooks
Fixes: #1261
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
Just fixed badly written Python string interpolation. Used the `%` operator just like the lines above.
### 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.
Mike Bayer [Tue, 16 May 2023 12:55:51 +0000 (08:55 -0400)]
restore drop_index.table_name, drop_constraint.type_ as positional
These two API changes were identified as having legacy
use patterns and should be revisited using a deprecation warning
for removal in either 1.12 or 1.13.
Add documentation re: Alembic not using semver, fix
incorrect calling signature example in batch documentation.
Mike Bayer [Tue, 16 May 2023 14:39:31 +0000 (10:39 -0400)]
restore Dict[str, str] as potential get_section() type
Restored the output type of :meth:`.Config.get_section` to include
``Dict[str, str]`` as a potential return type, which had been changed to
immutable ``Mapping[str, str]``. When a section is returned and the default
is not used, a mutable dictionary is returned.
Mike Bayer [Fri, 12 May 2023 16:40:01 +0000 (12:40 -0400)]
dont compare unique constraint and index sigs to each other
Fixed regression caused by :ticket:`1166` released in version 1.10.0 which
caused MySQL unique constraints with multiple columns to not compare
correctly within autogenerate, due to different sorting rules on unique
constraints vs. indexes, which in MySQL are shared constructs.