Colin Adams [Thu, 13 Apr 2023 19:24:41 +0000 (15:24 -0400)]
Fix type annotation in `op.create_table_comment`
### Description
The `existing_comment` parameter had type `None`, but it should be `Optional[str]`.
Fixes #903
### 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.
James Addison [Mon, 10 Apr 2023 19:40:38 +0000 (15:40 -0400)]
tooling: write_pyi.py: filter usage of raw-strings (rstrings)
### Description
While reading the diff between [`rel_1_10_2...rel_1_10_3`](https://github.com/sqlalchemy/alembic/compare/rel_1_10_2...rel_1_10_3), the introduction of r-strings drew my attention, and that resulted in some [discussion on the relevant commit](https://github.com/sqlalchemy/alembic/commit/bc0c305b7c2cc0401e250fcd6a725aacecdd6e33).
This changeset filters the production of r-strings during stub-generation to cases where docstrings contain escape (backslash, `\`) characters.
I'll admit that I didn't realize until today that these stubs are primarily for typechecking. Since that's the case, I have doubts about whether the change is worthwhile (consistency and simplicity -- using r-strings for all docstrings in the stubs -- even if it's redundant, seems fine to me).
### Checklist
This pull request is:
- [x] A documentation / typographical error fix
- [x] A short code fix
- Relates to discussion at https://github.com/sqlalchemy/alembic/commit/bc0c305b7c2cc0401e250fcd6a725aacecdd6e33
Mike Bayer [Fri, 7 Apr 2023 15:05:20 +0000 (11:05 -0400)]
uniquify cols for FK table object
Fixed issue where using a directive such as ``op.create_foreign_key()`` to
create a self-referential constraint on a single table where the same
column were present on both sides (e.g. within a composite foreign key)
would produce an error under SQLAlchemy 2.0 and a warning under SQLAlchemy
1.4 indicating that a duplicate column were being added to a table.
Viicos [Sun, 26 Mar 2023 02:02:22 +0000 (22:02 -0400)]
Fix type annotation for `url`
<!-- Provide a general summary of your proposed changes in the Title field above -->
Left the `pyi` generated file untouched.
### 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:
- [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.
Vlastimil Zíma [Sat, 4 Jun 2022 14:28:36 +0000 (10:28 -0400)]
Add docs for data migrations
### Description
I added a small docs regarding data migrations, based on #972.
### 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
CaselIT [Mon, 6 Mar 2023 21:15:15 +0000 (22:15 +0100)]
Fix unknown types reported by pyright
Fixed various typing issues observed with pyright, including issues
involving the combination of :class:`.Function` and
:meth:`.MigrationContext.begin_transaction`.
Mike Bayer [Tue, 7 Mar 2023 16:07:33 +0000 (11:07 -0500)]
mock _NONE_NAME for < 1.3.24
Fixed regression where Alembic would not run with older SQLAlchemy 1.3
versions prior to 1.3.24 due to a missing symbol. Workarounds have been
applied for older 1.3 versions.
Jan Katins [Mon, 6 Mar 2023 21:18:17 +0000 (16:18 -0500)]
improve autogen rendering for PG ExcludeConstraint
Fixed issue regarding PostgreSQL :class:`.ExcludeConstraint`, where
constraint elements which made use of :func:`.literal_column` could not be
rendered for autogenerate. Additionally, using SQLAlchemy 2.0.5 or greater,
:func:`.text()` constructs are also supported within PostgreSQL
:class:`.ExcludeConstraint` objects for autogenerate render. Pull request
courtesy Jan Katins.
Mike Bayer [Mon, 6 Mar 2023 18:34:40 +0000 (13:34 -0500)]
distinguish between string contraint name and defined
Take _NONE_NAME into account as a valid constraint name
and don't skip these constraints or consider them to be unnamed.
Thanks to typing this also revealed that previous batch versions
were also keying "_NONE_NAME" constraints as though they were named.
Fixed regression for 1.10.0 where :class:`.Constraint` objects were
suddenly required to have non-None name fields when using batch mode, which
was not previously a requirement.
ostr00000 [Mon, 27 Feb 2023 23:18:19 +0000 (18:18 -0500)]
add recursive_version_locations option for searching revision files
Recursive traversal of revision files in a particular revision directory is
now supported, by indicating ``recursive_version_locations = true`` in
alembic.ini. Pull request courtesy ostr00000.
CaselIT [Thu, 23 Feb 2023 20:45:11 +0000 (21:45 +0100)]
Escape sql server constriant names
Properly escape constraint name on SQL Server when dropping
a column while specifying ``mssql_drop_default=True`` or
``mssql_drop_check=True`` or ``mssql_drop_foreign_key=True``.
Mike Bayer [Tue, 28 Feb 2023 15:58:22 +0000 (10:58 -0500)]
ensure single import per line
This adds the very small plugin flake8-import-single which
will prevent us from having an import with more than one symbol
on a line.
Flake8 by itself prevents this pattern with E401:
import collections, os, sys
However does not do anything with this:
from sqlalchemy import Column, text
Both statements have the same issues generating merge artifacts
as well as presenting a manual decision to be made. While
zimports generally cleans up such imports at the top level, we
don't enforce zimports / pre-commit use.
the plugin finds the same issue for imports that are inside of
test methods. We shouldn't usually have imports in test methods
so most of them here are moved to be top level.
The version is pinned at 0.1.5; the project seems to have no
activity since 2019, however there are three 0.1.6dev releases
on pypi which stopped in September 2019, they seem to be
experiments with packaging. The source for 0.1.5
is extremely simple and only reveals one method to flake8
(the run() method).
CaselIT [Sat, 4 Feb 2023 12:28:42 +0000 (13:28 +0100)]
Improved support for expression indexes
Added support for autogenerate comparison of indexes on PostgreSQL which
include SQL expressions; the previous warning that such indexes were
skipped is now removed. This functionality requires SQLAlchemy 2.0.
For older SQLAlchemy versions, these indexes are still skipped.
Fixed issue where indexes on SQLite which include SQL expressions would not
compare against themselves correctly, generating false positives.
SQLAlchemy as of version 2 has no support for reflecting expression based
indexes on SQLite; so for now, the behavior is that SQLite expression-based
indexes are ignored for autogenerate compare, in the same way that
PostgreSQL expression-based indexes were ignored for the time that
SQLAlchemy did not support reflection of such indexes (which is now
supported in SQLAlchemy 2.0 as well as this release of Alembic).
Fixed issue in index detection where autogenerate change detection would
consider indexes with the same columns but with different order as equal,
while in general they are not equivalent in how a database will use them.
Mike Bayer [Sun, 26 Feb 2023 01:06:42 +0000 (20:06 -0500)]
set next version at 1.10.0
Will rebase current 1.10 gerrits to this one until we are
very close to 1.10 issues being very close to ready for release.
In the interim, I'd rather not have an 0.9 branch for emergency
bugfixes.
We are mostly here waiting on I226408eed855b923172e5df0bdab005ed2cc9f53
for 1.10 to be close to release.
Tim Penhey [Thu, 23 Feb 2023 21:17:57 +0000 (10:17 +1300)]
Update docstring to suggest raw string (#1186)
* Update docstring to suggest raw string
When escaping the `:` for `op.execute` if a normal string is used, you need to escape the backslash, eg. `'\\:colon_value'` or using a raw string.
For the docs I feel it is nicer to show the raw string.
Mike Bayer [Thu, 16 Feb 2023 02:34:30 +0000 (21:34 -0500)]
dont use server_default render_item for SQL compare
Removed a mis-use of the
:paramref:`.EnvironmentContext.configure.render_item` callable where the
"server_default" renderer would be erroneously used within the server
default comparison process, which is working against SQL expressions, not
Python code.
Mike Bayer [Tue, 14 Feb 2023 17:45:24 +0000 (12:45 -0500)]
collapse all chars for mssql defaults, move quoting
Ongoing fixes for SQL Server server default comparisons under autogenerate,
adjusting for SQL Server's collapsing of whitespace between SQL function
arguments when reporting on a function-based server default, as well as its
arbitrary addition of parenthesis within arguments; the approach has now
been made more aggressive by stripping the two default strings to compare
of all whitespace, parenthesis, and quoting characters.
Fixed PostgreSQL server default comparison to handle SQL expressions
sent as ``text()`` constructs, such as ``text("substring('name', 1, 3)")``,
which previously would raise errors when attempting to run a server-based
comparison.
Brendan Gann [Tue, 14 Feb 2023 16:03:09 +0000 (11:03 -0500)]
restore config object to merge command
Fixed regression introduced in 1.7.0 where the "config" object passed to
the template context when running the :func:`.merge` command
programmatically failed to be correctly populated. Pull request courtesy
Brendan Gann.
Sam Bull [Mon, 13 Feb 2023 20:36:06 +0000 (15:36 -0500)]
Include missing part of env.py
This part is missing from the example, and if a user started with the async template, then they would have an `asyncio.run()` call in here, which breaks the script.
Mike Bayer [Tue, 7 Feb 2023 04:30:58 +0000 (23:30 -0500)]
add variant render step for user-defined types
due to SQLA 2.0's variant being integrated into types,
the variant rendering conditional would no longer take effect
as the type was not under the "sqlalchemy" module namespace.
Fixed issue where rendering of user-defined types that then went onto use
the ``.with_variant()`` method would fail to render, if using SQLAlchemy
2.0's version of variants.
Mike Bayer [Tue, 10 Jan 2023 21:51:49 +0000 (16:51 -0500)]
repair regression in SQL Server server default comapre logic
Fixed regression caused by :ticket:`1145` where the string transformations
applied to server defaults caused expressions such as ``(getdate())`` to no
longer compare as equivalent on SQL Server, others.
Vincent Fazio [Tue, 3 Jan 2023 17:39:13 +0000 (12:39 -0500)]
add overload stubs for proxied classes
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
Closes #1146
Closes #1147
<!-- Describe your changes in detail -->
Overloaded functions would not have type stubs generated by the stub generator for proxied classes. Now they will.
### 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 [Thu, 22 Dec 2022 23:41:20 +0000 (18:41 -0500)]
dont use repr to quote string in compare_server_default
Fixed issue where server default compare would not work for string defaults
that contained backslashes, due to mis-rendering of these values when
comparing their contents.
The server default comparison still has a lot of not-robust behaviors,
however at least get in place a parameterized test suite so that we
can add new scenarios quickly.
Made a slight adjustment to SQLite's compare server default implementation
to better handle defaults with or without parens around them, from both
the reflected and the local metadata side.
Implemented basic server default comparison for the Oracle backend;
previously, Oracle's formatting of reflected defaults prevented any
matches from occurring.
Nathan Louie [Tue, 13 Dec 2022 17:58:09 +0000 (12:58 -0500)]
add check command for upgrade diffs
Added new Alembic command ``alembic check``. This performs the widely
requested feature of running an "autogenerate" comparison between the
current database and the :class:`.MetaData` that's currently set up for
autogenerate, returning an error code if the two do not match, based on
current autogenerate settings. Pull request courtesy Nathan Louie.
Mike Bayer [Sun, 11 Dec 2022 20:25:34 +0000 (15:25 -0500)]
try to restore color to pytest
the problem here is that the color codes will come out in
jenkins runs. see if jenkins maybe does something with that
(filters or maybe even gives us color)
Mike Bayer [Sun, 11 Dec 2022 16:31:10 +0000 (11:31 -0500)]
adjust for tox changes to passenv
Fixed issue in tox.ini file where changes in the tox 4.0 series to the
format of "passenv" caused tox to not function correctly, in particular
raising an error as of tox 4.0.6.
I'm having some weird fighting with the tools/write_pyi, where
in different runtime contexts it keeps losing "MigrationContext"
and also Callable drops the args, but it's not consisistent.
For whatever reason, under py311 things *do* work every time.
im working w/ clean tox environments so not really sure what the
change is. anyway, let's at least fix the quoting up
around the types.
This is towards getting the "*" in the op signatures for #1130.
Mike Bayer [Mon, 7 Nov 2022 18:05:08 +0000 (13:05 -0500)]
add typing parameters
Fixed typing issue where :paramref:`.revision.process_revision_directives`
was not fully typed; additionally ensured all ``Callable`` and ``Dict``
arguments to :meth:`.EnvironmentContext.configure` include parameters in
the typing declaration.
Simple change to fix (some) type checking with Pyright and friends.
Add missing types to **kw
Simple update to types, consistent with other similar instances already in place.
<!-- 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: somewhere between the first and second options. I don't think it merits an issue or test coverage.
- [ ] 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 [Wed, 13 Jul 2022 14:02:53 +0000 (10:02 -0400)]
build fixes
* hardcode rev ids in test that's sensitive to overlapping
substrings
* turn off nitpicky mode
* fix a few rst keywords
* ensure unreleased files not considered as indexable
Mike Bayer [Tue, 12 Jul 2022 23:36:57 +0000 (19:36 -0400)]
implement SQLite RENAME TABLE w schema syntax
Fixed bug where the SQLite implementation of
:meth:`.Operations.rename_table` would render an explicit schema name for
both the old and new table name, which while is the standard ALTER syntax,
is not accepted by SQLite's syntax which doesn't support a rename across
schemas. In particular, the syntax issue would prevent batch mode from
working for SQLite databases that made use of attached databases (which are
treated as "schemas" in SQLAlchemy).
Mike Bayer [Fri, 1 Jul 2022 13:56:10 +0000 (09:56 -0400)]
fail gracefully for batch_alter_table() called in --sql mode
Added an error raise for the condition where
:meth:`.Operations.batch_alter_table` is used in ``--sql`` mode, where the
operation requires table reflection, as is the case when running against
SQLite without giving it a fixed ``Table`` object. Previously the operation
would fail with an internal error. To get a "move and copy" batch
operation as a SQL script without connecting to a database,
a ``Table`` object should be passed to the
:paramref:`.Operations.batch_alter_table.copy_from` parameter so that
reflection may be skipped.