Mike Bayer [Tue, 24 Dec 2024 15:30:10 +0000 (10:30 -0500)]
check for variants (recursion branch) first in all cases
Fixed bug where autogen render of a "variant" type would fail to catch the
variants if the leading type were a dialect-specific type, rather than a
generic type.
Mike Bayer [Fri, 29 Nov 2024 16:58:53 +0000 (11:58 -0500)]
ensure rename_column works on SQLite
Modified SQLite's dialect to render "ALTER TABLE <t> RENAME COLUMN" when
:meth:`.Operations.alter_column` is used with a straight rename, supporting
SQLite's recently added column rename feature.
Mike Bayer [Mon, 25 Nov 2024 18:57:58 +0000 (13:57 -0500)]
support separation of Numeric/Float
in [1] we are considering separating Numeric and Float.
For Alembic PostgreSQL backend we need this isinstance therefore
to check for both Numeric and Float.
By keeping it to these two types, rather than targeting the
NumericCommon type being added in [1], the patch can work with
SQLAlchemy without the separation change as well.
Peter Cock [Thu, 7 Nov 2024 14:51:22 +0000 (09:51 -0500)]
Clarify what autogenerate compares
### Description
<!-- Describe your changes in detail -->
I was struggling with empty upgrade/downgrade functions because both my database and my ORM were up to date. I wrongly assumed the comparison was against the previous database scheme as per the prior revision script(s).
### 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.
Michael Bayer [Wed, 6 Nov 2024 23:43:43 +0000 (18:43 -0500)]
Fix `alembic.ini` templates to match `configparser` file format.
In the `alembic.ini` templates, I moved the inline comment about `version_path_separator` to their own lines as required by `configparser`.
### Description
In a recent project, I included the following configuration values in my `alembic.ini`. Note that the last line is the default line from the current generic `alembic.ini` template.
```
# version location specification; This defaults
# to migrations/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator" below.
version_locations = %(here)s/migrations/versions
# version path separator; As mentioned above, this is the character used to split
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for version_path_separator are:
#
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
```
When running `alembic check`, I encountered:
```
ValueError: 'os # Use os.pathsep. Default configuration used for new projects.' is not a valid value for version_path_separator; expected 'space', 'os', ':', ';'
```
It seemed that the comment in the last line was being included as part of the parsed config value, which should be `os`.
Alembic currently [uses `configparser.ConfigParser` from the standard libary](https://github.com/sqlalchemy/alembic/blob/2d60c77c81a72a78b575b96aef511e658073dec5/alembic/util/compat.py#L82-L89) to parse `alembic.ini` files. The [default `configparser` file format](https://docs.python.org/3/library/configparser.html#supported-ini-file-structure) requires that comments be on their own lines, although this can be customized. I changed the three copies of this line in Alembic's `alembic.ini` templates to remove the inline comments. In my case, this change fixed the `ValueError`.
This issue could also be fixed by changing [the default instance of `ConfigParser`](https://github.com/sqlalchemy/alembic/blob/2d60c77c81a72a78b575b96aef511e658073dec5/alembic/config.py#L202), using `inline_comment_prefixes=("#",)`. I imagine, however, that it might be better to use the default file format.
### 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.
Aaron Griffin [Wed, 6 Nov 2024 20:40:56 +0000 (15:40 -0500)]
Improve write_pyi usage
Fixes #1524
### Description
Due to some problems when running write_pyi, this includes the following changes:
1. move the sys.path.append up before alembic is imported - this is using global imports otherwise
2. use tox to run write_pyi in order to avoid globally installed dependencies
### 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.
DanCardin [Wed, 6 Nov 2024 17:10:12 +0000 (12:10 -0500)]
fix: Correct the AutogenContext.metadata typing to include Sequence[MetaData].
### Description
The type annotation for AutogenContext.metadata is currently `Optional[MetaData]`, but `target_metadata` is `Union[MetaData, Sequence[MetaData], None]`. Seems like setting `target_metadata` to `[]` directly translates into the list that `AutogenContext` receives, and that the code is already coercing the potential single/sequence to always be a list.
My alembic plugin wasn't aware that this **could** be a list, and as such wasn't handling the possibility properly.
### 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.
Maciek Bryński [Thu, 31 Oct 2024 21:29:40 +0000 (17:29 -0400)]
Add ability to configure alembic_version table in DialectImpl
Added a new hook to the :class:`.DefaultImpl`
:meth:`.DefaultImpl.version_table_impl`. This allows third party dialects
to define the exact structure of the alembic_version table, to include use
cases where the table requires special directives and/or additional columns
so that it may function correctly on a particular backend. This is not
intended as a user-expansion hook, only a dialect implementation hook to
produce a working alembic_version table. Pull request courtesy Maciek
Bryński.
Maciek Bryński [Thu, 31 Oct 2024 16:47:35 +0000 (12:47 -0400)]
Fix mypy linting issues
### Description
Fixing mypy linting issues for new mypy version.
### 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.
The `WARN` constant is an undocumented alias for `WARNING`. Whilst it’s not deprecated, it’s not mentioned at all in the documentation. This references one of `flake8-logging` plugins [rule](https://github.com/adamchainz/flake8-logging?tab=readme-ov-file#log009-warn-is-undocumented-use-warning-instead).
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
Changed all uses of `logging.WARN` to `logging.WARNING`.
### 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.
Render `if_not_exists` option for CreateTableOp, CreateIndexOp, DropTableOp and DropIndexOp
Render ``if_exists`` and ``if_not_exists`` parameters in
:class:`.CreateTableOp`, :class:`.CreateIndexOp`, :class:`.DropTableOp` and
:class:`.DropIndexOp` in an autogenerate context. While Alembic does not
set these parameters during an autogenerate run, they can be enabled using
a custom :class:`.Rewriter` in the ``env.py`` file, where they will now be
part of the rendered Python code in revision files. Pull request courtesy
of Louis-Amaury Chaib (@lachaib).
Support if_exists and if_not_exists on create/drop table commands
Added support for :paramref:`.Operations.create_table.if_not_exists` and
:paramref:`.Operations.drop_table.if_exists`, adding similar functionality
to render IF [NOT] EXISTS for table operations in a similar way as with
indexes. Pull request courtesy Aaron Griffin.
Mike Bayer [Mon, 2 Sep 2024 15:33:26 +0000 (11:33 -0400)]
unpin setuptools
The pin for ``setuptools<69.3`` in ``pyproject.toml`` has been removed.
This pin was to prevent a sudden change to :pep:`625` in setuptools from
taking place which changes the file name of SQLAlchemy's source
distribution on pypi to be an all lower case name, and the change was
extended to all SQLAlchemy projects to prevent any further surprises.
However, the presence of this pin is now holding back environments that
otherwise want to use a newer setuptools, so we've decided to move forward
with this change, with the assumption that build environments will have
largely accommodated the setuptools change by now.
Enhance version_path_separator behaviour by adding a newline option
### Description
version_path_separator now consists a new option "newline" which allows you to specify multiple version locations across multiple lines like this:
```
version_locations =
/foo/versions
/bar/versions
/baz/versions
version_path_separator = newline
```
### Checklist
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.
zhouyizhen [Wed, 5 Jun 2024 19:28:53 +0000 (15:28 -0400)]
Fix postgres detect serial in autogenerate (#1479)
<!-- Provide a general summary of your proposed changes in the Title field above --> Fixes: https://github.com/sqlalchemy/alembic/issues/1479
### Description
<!-- Describe your changes in detail -->
In https://github.com/sqlalchemy/alembic/issues/73, it tries to detact postgresql serial in autogenerate, so it won't take `nextval('seq'::regclass)` as server default for that column.
But it takes not effect for tables not in search path. This PR fixed 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
- [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.
The constraint name in create_primary_key should be optional, but for batch operations is is required according to the type annotations
### Description
Changed the type annotation to `Optional[str]`
### 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 [Mon, 4 Mar 2024 04:11:50 +0000 (23:11 -0500)]
use SQLAlchemy's xdist methods
Fixes to support pytest 8.1 for the test suite.
the use of teardown() was based on pytest's nose
compat, which is removed. their xdist style tests use the name
"setup_method()" and "teardown_method()" now.
We have SQLAlchemy's pytestplugin in use which uses pytest fixtures
to invoke our own xdist style setUp and tearDown methods, which we
are already using here, so use those for this one test.
Mike Bayer [Mon, 4 Mar 2024 03:40:53 +0000 (22:40 -0500)]
block pytest 8
something has changed and teardown() is no longer called.
SQLAlchemy seems to also be pinned below pytest 8 (which we need to fix)
so this is likely related
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.