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.
Fix autogenerate issue with PostgreSQL :class:`.ExcludeConstraint`
that included sqlalchemy functions. The function text was previously
rendered as a plain string without surrounding with ``text()``.
James Addison [Wed, 26 Apr 2023 20:29:53 +0000 (16:29 -0400)]
Followup / fixup: apply 'black' code formatting to a couple of missed docstrings
### Description
Follow-up / completion of #1220. That change updated a number of docstrings within the codebase to use standardised `black` code formatting, but a couple of locations had been missed.
### Checklist
This pull request is:
- [x] A documentation / typographical error fix
- Good to go, no issue or tests are needed
James Addison [Thu, 13 Apr 2023 19:11:01 +0000 (15:11 -0400)]
Consistency: apply codestyle formatting to docstring code snippets
### Description
This is a pedantic/consistency follow-up from #1219: that change applied some `black` formatting to two code snippets, and this change applies that formatting to the remaining snippets in the codebase.
For each snippet, I extracted the code and applied formatting using `black` v23.1.0, then placed the results back into the source.
In one case there was an associated 'output' block, and in that case I re-ran the snippet code to update the results of that output too (this included a [change-in-output](https://github.com/sqlalchemy/alembic/compare/main...openculinary:alembic:docstrings/snippet-format-consistency?expand=1#diff-bf4756660cdb31ee8566a2cff72526671356c38a725195723ce0e65e6c11e6cfR124) thanks to a [bugfix since the snippet was written](https://github.com/sqlalchemy/alembic/commit/bc6971aa4abdafb7e1a1123c26a373cc25a34ca9), by the looks of it).
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`.