summaryrefslogtreecommitdiff
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* restore drop_index.table_name, drop_constraint.type_ as positionalMike Bayer2023-05-164-0/+47
| | | | | | | | | | | | | 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. Change-Id: I33dc5a8d058bcce77591bb037ae964e626a3387f Fixes: #1243 Fixes: #1245
* Merge "dont compare unique constraint and index sigs to each other" into mainmike bayer2023-05-121-0/+74
|\
| * dont compare unique constraint and index sigs to each otherMike Bayer2023-05-121-0/+74
| | | | | | | | | | | | | | | | | | | | 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. Change-Id: I5687dde95281f237fd73367d145b9c62e2576a3a Fixes: #1240
* | Merge "add user_module_prefix param for render_python_code" into mainmike bayer2023-05-121-0/+28
|\ \
| * | add user_module_prefix param for render_python_codetangkikodo2023-05-121-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. Fixes #1235 Closes: #1233 Pull-request: https://github.com/sqlalchemy/alembic/pull/1233 Pull-request-sha: 6fa3bc1ce4f2130bf7a28282a84e3bb9a3223304 Change-Id: Ic21eec87f373a9518513a6a308f16e5d2b5ebf81
* | | Merge "Added ``op.run_async``." into mainmike bayer2023-05-121-0/+44
|\ \ \ | |_|/ |/| |
| * | Added ``op.run_async``.Federico Caselli2023-05-121-0/+44
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Fixes: #1231 Change-Id: I3c3237d570be3c9bd9834e4c61bb3231bfb82765
* | Merge "keyword only arguments in ops" into mainmike bayer2023-05-125-14/+22
|\ \
| * | keyword only arguments in opsMike Bayer2023-05-115-14/+22
| |/ | | | | | | | | | | | | | | | | | | 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. Change-Id: I91b453c8848dc5d24d63840bfd7ce4d22dd0e693 Fixes: #1130
* | Removed server default quoting from compareFederico Caselli2023-05-111-2/+2
|/ | | | | | | | | | | 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``. Fixes: #1178 Change-Id: Ib429efcf9077337f768ad5aad91659867e89391a
* Add Operations and BatchOperations stub methodsCaselIT2023-05-041-1/+10
| | | | | | | | | | | | | 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. Fixes: #1093 Change-Id: I98d38dd5a1e719b4dbbc1003746ec28f26c27808
* Merge "Added quiet option to command line" into mainFederico Caselli2023-05-042-14/+12
|\
| * Added quiet option to command lineCaselIT2023-04-282-14/+12
| | | | | | | | | | | | | | | | | | Added quiet option to the command line, using the ``-q/--quiet`` option. This flag will prevent alembic from logging anything to stdout. Fixes: #1109 Change-Id: I7d9fac05d93e07efaefd87a582a7e785891798ef
* | Fix ExcludeConstraint with func.Federico Caselli2023-04-281-8/+33
|/ | | | | | | | | 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()``. Fixes: #1230 Change-Id: I0d59e04d5a64132ed86f92a27e4247ac9703f3e0
* Improve typing.Federico Caselli2023-04-131-1/+1
| | | | | | | | Correctly pass previously ignored arguments ``insert_before`` and ``insert_after`` in ``batch_alter_column`` Fixes: #1221 Change-Id: I79c9144f3e521fca00a0c32462ae2a69f9f7a032
* Merge "Use column sort in index compare on postgresql" into mainmike bayer2023-04-102-77/+217
|\
| * Use column sort in index compare on postgresqlCaselIT2023-04-102-77/+217
| | | | | | | | | | | | | | | | Added support for autogenerate comparison of indexes on PostgreSQL which include SQL sort option, such as ``ASC`` or ``NULLS FIRST``. Fixes: #1213 Change-Id: I3ddcb647928d948e41462b1c889b1cbb515ace4f
* | uniquify cols for FK table objectMike Bayer2023-04-071-0/+15
|/ | | | | | | | | | | 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. Change-Id: I2a8f5d8def2714792bffcdfb8bf88a5080ec8ce7 Fixes: #1215
* Fix issues in autogenerate of function index removalCaselIT2023-04-043-169/+96
| | | | | | | | Fixed error raised by alembic when running autogenerate after removing a function based index. Fixes: #1212 Change-Id: Idc565d661229afda89d44e36786bb0357323e604
* Merge "improve autogen rendering for PG ExcludeConstraint" into mainmike bayer2023-03-071-0/+59
|\
| * improve autogen rendering for PG ExcludeConstraintJan Katins2023-03-061-0/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. Fixes: #1184 Closes: #1185 Pull-request: https://github.com/sqlalchemy/alembic/pull/1185 Pull-request-sha: 68360ce9aa746a85407c5e1e04b8021123d98504 Change-Id: I302f3f4007a186ffac13b344ff6769dd302f28f5
* | distinguish between string contraint name and definedMike Bayer2023-03-061-0/+26
|/ | | | | | | | | | | | | | 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. Change-Id: If4a7191a00848b19cb124bc6da362f3bc6ce1472 Fixes: #1195
* Fixes test in older sqliteCaselIT2023-03-011-4/+0
| | | | Change-Id: I2f816a37abf7fa3203879e1d03b55307bd957ee4
* Merge "Improved support for expression indexes" into mainmike bayer2023-03-014-62/+374
|\
| * Improved support for expression indexesCaselIT2023-02-264-62/+374
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. Fixes: #1165 Fixes: #1166 Change-Id: I226408eed855b923172e5df0bdab005ed2cc9f53
* | Merge "add recursive_version_locations option for searching revision files" ↵mike bayer2023-03-012-1/+334
|\ \ | | | | | | | | | into main
| * | add recursive_version_locations option for searching revision filesostr000002023-02-282-1/+334
| |/ | | | | | | | | | | | | | | | | | | | | | | | | 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. Fixes: #760 Closes: #1182 Pull-request: https://github.com/sqlalchemy/alembic/pull/1182 Pull-request-sha: ecb0da48b459abd3f5e95390ec7030a7e3fcbc6d Change-Id: I711ca2dbd35fb9a2acdbfd374bcac13043b0d129
* | Escape sql server constriant namesCaselIT2023-02-281-8/+65
| | | | | | | | | | | | | | | | | | 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``. Fixes: #1187 Change-Id: I060442bc63c4e53f64724985e20e6e15e4335b6b
* | ensure single import per lineMike Bayer2023-02-284-11/+9
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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). Change-Id: Icea894e43bad9c0b5d4feb5f49c6c666d6ea6aa1
* collapse all chars for mssql defaults, move quotingMike Bayer2023-02-151-0/+32
| | | | | | | | | | | | | | | | | 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. Change-Id: Icd861f62653fc7b3900164c0d047821125e1305e Fixes: #1177
* add variant render step for user-defined typesMike Bayer2023-02-071-4/+23
| | | | | | | | | | | | | 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. Change-Id: I3c6f14325d6dffb2ddc1bf955753ee5a2de2cedd Fixes: #1167
* repair regression in SQL Server server default comapre logicMike Bayer2023-01-101-0/+6
| | | | | | | | | 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. Change-Id: I9c611edd70765487746f652c9eb09e54d935da28 Fixes: #1152
* add overload stubs for proxied classesVincent Fazio2023-01-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | <!-- 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. Closes: #1148 Pull-request: https://github.com/sqlalchemy/alembic/pull/1148 Pull-request-sha: ed3c28cc78e57314b7a4e533d77108efc6751949 Change-Id: I7c0ee9d333015174ee6ab754909748f745af2ff9
* dont use repr to quote string in compare_server_defaultMike Bayer2022-12-231-0/+73
| | | | | | | | | | | | | | | | | | | | | 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. Change-Id: If5a69eec4b22d243a564d2c89e78ae33ba5be88f Fixes: #1145
* add check command for upgrade diffsNathan Louie2022-12-151-0/+59
| | | | | | | | | | | | | | | | | 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. As this is a new feature we will call this 1.9.0 Fixes: #724 Closes: #1101 Pull-request: https://github.com/sqlalchemy/alembic/pull/1101 Pull-request-sha: 807ed545df70e7a10b913e2951a1b636f138a4ff Change-Id: I03b146eaf762be464a0ff0858ff5730cc9366c84
* run pyupgradeMike Bayer2022-11-2613-204/+161
| | | | | | | | | | | | | | | | | | command is: find alembic -name "*.py" | xargs pyupgrade --py37-plus --keep-runtime-typing --keep-percent-format 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. Change-Id: I9175905d3b4325e03a97d6752356b70be20e9fad
* use SQLAlchemy built-in password obfuscationMike Bayer2022-09-231-1/+1
| | | | | | | | As str(url) will be changing to obfuscate the PW, use SQLA 1.3 / 1.4 / 2.0 functionality directly. Change-Id: I4694cc6d2ed7f0463fe0fae8a93ee9ec5df74760 References: https://github.com/sqlalchemy/sqlalchemy/issues/8567
* add docs for naming convention bypass caseMike Bayer2022-07-191-0/+20
| | | | | Change-Id: I8d604eaab7865466b8a7008693621c00f954397d References: #453
* Merge "Ignore reflected expression based indexes" into mainFederico Caselli2022-07-141-8/+5
|\
| * Ignore reflected expression based indexesCaselIT2022-07-141-8/+5
| | | | | | | | | | | | | | | | this establishes forwads-compatibility for PostgreSQL expression-based index reflection being added in I3e36d557235286c0f7f6d8276272ff9225058d48 Change-Id: I81d7832f254f50dc3417dd3437c2b49ec3a549e2
* | build fixesMike Bayer2022-07-131-5/+6
| | | | | | | | | | | | | | | | | | | | * 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 Change-Id: I31a0f2cbf40c794204c1e7dbc68bfcf43992c65f
* | implement SQLite RENAME TABLE w schema syntaxMike Bayer2022-07-121-0/+5
|/ | | | | | | | | | | | | 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). Change-Id: I02d8163b39cd33568c7528158218828ff0813695 Fixes: #1065
* fail gracefully for batch_alter_table() called in --sql modeMike Bayer2022-07-011-0/+171
| | | | | | | | | | | | | | | 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. Change-Id: I2d040e7e5771eefabba1649d71ed451567c25283 Fixes: #1021
* Make alembic compatible with comments on constraintsCaselIT2022-06-251-0/+2
| | | | | | | Make alembic test compatible with comments on constraint change added in Ia60f578595afdbd6089541c9a00e37997ef78ad3 Change-Id: I9ad803df1d3ccf2a5111266b781061936717b8c8
* Trigger events before and after drop table statementsAdrien Berchet2022-05-311-0/+53
| | | | | | | | | | | | | | | | | The ``op.drop_table()`` operation directive will now trigger the ``before_drop()`` and ``after_drop()`` DDL event hooks at the table level, which is similar to how the ``before_create()`` and ``after_create()`` hooks are triggered by the ``op.create_table()`` directive. Note that as ``op.drop_table()`` accepts only a table name and optional schema name, the ``Table`` object received by the event will not have any information within it other than the table name and schema name. Fixes: #1037 Closes: #1036 Pull-request: https://github.com/sqlalchemy/alembic/pull/1036 Pull-request-sha: ea44e7f3398aa5001e86e6a7e30f61f6a86d9674 Change-Id: I20a1702e17ed88054206d964152ce05b81d0f89e
* implement full copy for indexes in batchMike Bayer2022-05-101-7/+25
| | | | | | | | | | | | | Fixed issue in batch mode where CREATE INDEX would not use a new column name in the case of a column rename. Indexes were previously being moved to the new table without any steps to rewrite columns. We now vendor the copy approach from table.to_metadata so that there's a new index expressed in terms of the new columns. Change-Id: Ied84232037aee0b2bf2094b3d3474013d7b41b34 Fixes: #1034
* Add epoch as an option for file_templateCaio Carvalho2022-05-062-0/+29
| | | | | | | | | | | | | Added new token ``epoch`` to the ``file_template`` option, which will populate the integer epoch as determined by ``int(create_date.timestamp())``. Pull request courtesy Caio Carvalho. Fixes: #1027 Closes: #1028 Pull-request: https://github.com/sqlalchemy/alembic/pull/1028 Pull-request-sha: 27970cd5d4e047cb7aabd161c68b757b2ee3e4c4 Change-Id: I73e13009bae91e64681a605b3f0b62ea1e5fc464
* Fix downgrade with effective headCaselIT2022-05-031-4/+40
| | | | | | | | | Fixed issue where downgrade using a relative revision would fail in case of multiple branches with a single effectively head due to interdependencies between revisions. Fixes: #1026 Change-Id: I79f5595fb9d03124db8039345055571a9134eecd
* Various typing related updatesCaselIT2022-04-231-1/+6
| | | | Change-Id: I778b63b1c438f31964d841576f0dd54ae1a5fadc
* Use `-> None` in script templates by defaultNikita Sobolev2022-04-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | <!-- Provide a general summary of your proposed changes in the Title field above --> ### Description When working together with `mypy` we have a problem with the default template. `mypy` raises errors on all migrations when used with https://mypy.readthedocs.io/en/stable/config_file.html#confval-disallow_untyped_defs So, there are several options: 1. Remove this flag for `[mypy-db.alembic.*]` in `mypy.ini`. This is not a very good idea, because custom code that might get written in this directory might be not fully typed. 2. Edit our own template. This is what we end up doing right now, but this requires some manual work and many users might miss it 3. Update the source! I think that this is harmless (because only python3.6+ is supported), but allows better type-checking ### Checklist Openning this as a draft for now. Will fix tests after I can see what is failing in the CI. Issue is also on its way! 🙂 <!-- 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. Fixes https://github.com/sqlalchemy/alembic/issues/764 **Have a nice day!** Closes: #1012 Pull-request: https://github.com/sqlalchemy/alembic/pull/1012 Pull-request-sha: c1d17b202f414a97e6215cc2a513509462a9db09 Change-Id: Ib077157b5ebd697bf648644a954ed5a9a3b33080