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.
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.
tangkikodo [Thu, 11 May 2023 20:43:05 +0000 (16:43 -0400)]
add user_module_prefix param for render_python_code
Fixed issue where :func:`.autogenerate.render_python_code` function did not
provide a default value for the ``user_module_prefix`` variable, leading to
``NoneType`` errors when autogenerate structures included user-defined
types. Added new parameter
:paramref:`.autogenerate.render_python_code.user_module_prefix` to allow
this to be set as well as to default to ``None``. Pull request courtesy
tangkikodo.
Added :meth:`.Operations.run_async` to the operation module to allow
running async functions in the ``upgrade`` or ``downgrade`` migration
function when running alembic using an async dialect.
This function will receive as first argument an
class:`~sqlalchemy.ext.asyncio.AsyncConnection` sharing the transaction
used in the migration context.
also restore the .execute() method to BatchOperations
Federico Caselli [Thu, 11 May 2023 19:49:14 +0000 (21:49 +0200)]
Removed server default quoting from compare
Don't modify the metadata server default when comparing it in the
autogenerate process.
This impacts the value passes to user provided functions passed in
:paramref:`.EnvironmentContext.configure.compare_server_default`
and third party dialect that implement a custom ``compare_server_default``.
Mike Bayer [Fri, 25 Nov 2022 15:31:20 +0000 (10:31 -0500)]
keyword only arguments in ops
Argument signatures of Alembic operations now enforce keyword-only
arguments as passed as keyword and not positionally, such as
:paramref:`.Operations.create_table.schema`,
:paramref:`.Operations.add_column.type_`, etc.
Added placeholder classes for ``Computed`` and ``Identity`` when older 1.x
SQLAlchemy versions are in use, namely prior to SQLAlchemy 1.3.11 when the
``Computed`` construct was introduced. Previously these were set to None,
however this could cause issues with certain codepaths that were using
``isinstance()`` such as one within "batch mode".
CaselIT [Thu, 16 Mar 2023 23:50:53 +0000 (00:50 +0100)]
Add Operations and BatchOperations stub methods
Updated stub generator script to also add stubs method definitions
for the :class:`.Operations` class and the :class:`.BatchOperations`
class obtained from :meth:`.Operations.batch_alter_table`.
Repaired the return signatures for :class:`.Operations` that mostly
return ``None``, and were erroneously referring to ``Optional[Table]``
in many cases.