summaryrefslogtreecommitdiff
path: root/tests/test_script_production.py
Commit message (Collapse)AuthorAgeFilesLines
* Added quiet option to command lineCaselIT2023-04-281-12/+8
| | | | | | | | | 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
* Merge "add recursive_version_locations option for searching revision files" ↵mike bayer2023-03-011-1/+1
|\ | | | | | | into main
| * add recursive_version_locations option for searching revision filesostr000002023-02-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | ensure single import per lineMike Bayer2023-02-281-1/+3
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* run pyupgradeMike Bayer2022-11-261-8/+5
| | | | | | | | | | | | | | | | | | 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
* Add epoch as an option for file_templateCaio Carvalho2022-05-061-0/+28
| | | | | | | | | | | | | 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
* 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
* Revendor editor and make dateutil optionalCaselIT2021-06-151-0/+16
| | | | | | | | | | | | | | | | | Re-implemented the ``python-editor`` dependency as a small internal function to avoid the need for external dependencies. The implementation is based on the original version in 7b91b325ff43a0e9235e0f15b57391fa92352626. Make the ``python-dateutil`` library an optional dependency. This library is only required if the ``timezone`` option is used in the Alembic configuration. An extra require named ``tz`` is available with ``pip install alembic[tz]`` to install it. Fixes: #674 Fixes: #856 Change-Id: I07f17b2fea01e3a3d677ce95333fe3e8d8d438fd
* New downgrade algorithm to fix branch behaviourSimon Bowly2021-04-261-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The algorithm used for calculating downgrades/upgrades/iterating revisions has been rewritten, to resolve ongoing issues of branches not being handled consistently particularly within downgrade operations, as well as for overall clarity and maintainability. This change includes that a deprecation warning is emitted if an ambiguous command such as "downgrade -1" when multiple heads are present is given. In particular, the change implements a long-requested use case of allowing downgrades of a single branch to a branchpoint. Huge thanks to Simon Bowly for their impressive efforts in successfully tackling this very difficult problem. Topological algorithm written by Mike which retains the behavior of walking along a single branch as long as possible before switching to another branch due to cross-dependencies. Fixes: #765 Fixes: #464 Fixes: #603 Fixes: #660 Closes: #790 Pull-request: https://github.com/sqlalchemy/alembic/pull/790 Pull-request-sha: 60752399336b883d26f38d61a8337dd6fdd48087 Change-Id: I8ab81d241df52a6bf0a474ccee35b16aecd706ac
* Use inspect(), not Inspector.from_engine()Mike Bayer2020-02-031-10/+4
| | | | | | | | The internal inspection routines no longer use SQLAlchemy's ``Inspector.from_engine()`` method, which is expected to be deprecated in 1.4. The ``inspect()`` function is now used. Change-Id: I81ea16e5d750d8c48d8db1a5098815988ea60f6c
* Fix tests on windowsCaselIT2019-12-271-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | <!-- Provide a general summary of your proposed changes in the Title field above --> Update the tests to make them run on windows ### Description <!-- Describe your changes in detail --> The main changes are: - Correctly manage the paths on windows vs *nix like system. - Manage the new lines \r\n vs \n - Windows cannot remove open files, namely the sqlite db, so it keeps track of the connections and closes them before removing the files. I've tested with sqlite, postgres and mysql and all pass (on windows 10) This fixes #632 ### 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. **Have a nice day!** Closes: #639 Pull-request: https://github.com/sqlalchemy/alembic/pull/639 Pull-request-sha: c6b7794510b5179f6ea574019df79a040e3c5f42 Change-Id: Ibbf7e1da941196d98d6a2e60d5f1bb3a253cca2b
* Assert scratch directory is cleaned up after class teardownMike Bayer2019-11-301-0/+3
| | | | | | | | Some race conditions are occurring due to the NormPath test and overall there should be no scratch directories remaining when tests are complete. Change-Id: I848b39c4ca473f424a76247abfa4071074808e9d
* Fix NormPathTest again....to not have my workstation paths in it :)Mike Bayer2019-09-191-14/+20
| | | | Change-Id: I743f7ec9379a09a4ade4f4e4b03e586c0b06517b
* Fix the NormPathTest to accommodate for multi-process staging directoriesMike Bayer2019-09-191-7/+10
| | | | Change-Id: Ie1659e51f889bca5d1fe30eb52bc1d5a7aef097c
* Add test for normalization of script_dir, version_locationsMike Bayer2019-09-191-0/+53
| | | | | | | Ensure ScriptDirectory normalizes paths. Change-Id: I9feea25e03eb3037321341776502619be413080e References: #590
* Memoize elements in rewriter; use correct iterationMike Bayer2019-09-181-0/+76
| | | | | | | | | | | | | | | Modified the logic of the :class:`.Rewriter` object such that it keeps a memoization of which directives it has processed, so that it can ensure it processes a particular directive only once, and additionally fixed :class:`.Rewriter` so that it functions correctly for multiple-pass autogenerate schemes, such as the one illustrated in the "multidb" template. By tracking which directives have been processed, a multiple-pass scheme which calls upon the :class:`.Rewriter` multiple times for the same structure as elements are added can work without running duplicate operations on the same elements more than once. Change-Id: I2cef13d51912f9d86ddd99b60e4d5b96dbf680ff Fixes: #505
* Render a single "pass" only for UpgradeOps, DowngradeOpsMike Bayer2019-09-171-0/+55
| | | | | | | | | | | | | Improved the Python rendering of a series of migration operations such that a single "pass" is rendered for a :class:`.UpgradeOps` or :class:`.DowngradeOps` based on if no lines of Python code actually rendered under the operation, rather than whether or not sub-directives exist. Removed extra "pass" lines that would generate from the :class:`.ModifyTableOps` directive so that these aren't duplicated under operation rewriting scenarios. Change-Id: Ia2547811565ac24ee0f56ce470f96ec567912de3 Fixes: #550
* zimports runMike Bayer2019-01-061-27/+31
| | | | | | | after black is applied, rewrite imports and fix remaining whitespace / identifier issues. Change-Id: I49474c085b5f4a4b52e4cf90c9705d6a896d4003
* pure black run + flake8Mike Bayer2019-01-061-257/+315
| | | | | | | run black -l 79 against source code, set up for full flake8 testing. Change-Id: I4108e1274d49894b9898ec5bd3a1147933a473d7
* Replace union_update with updateMike Bayer2018-10-171-4/+14
| | | | | | | | | Fixed issue where removed method ``union_update()`` was used when a customized :class:`.MigrationScript` instance included entries in the ``.imports`` data member, raising an AttributeError. Change-Id: Ia141db106bc3d57238e2fa6a546041fd573c0ea4 Fixes: #512
* Clean up all Python 3.6 warningsMike Bayer2017-10-111-2/+4
| | | | | | | | | | | | Fixed a few Python3.6 deprecation warnings by replacing ``StopIteration`` with ``return``, as well as using ``getfullargspec()`` instead of ``getargspec()`` under Python 3. Additionally fixed docstrings with backslashes needing r'', filehandles not explicitly closed, accommodate for .pyc files not necessarily present. Change-Id: Id9791c5fa8b4b1f3e4e36f237a8a8ebcef4aaaba Fixes: #458
* Add + to illegal revision characters listMike Bayer2017-09-151-0/+8
| | | | | | | | | An addition to :ticket:`441` fixed in 0.9.5, we forgot to also filter for the ``+`` sign in migration names which also breaks due to the relative migrations feature. Change-Id: I94d3882e84ba13e7569b47230dc9422a8ac6408c Fixes: #445
* fix using tzdata-compliant time zone namesNils Philippsen2017-08-091-0/+8
| | | | | | | | | | Previously, time zone names were capitalized indiscriminately, making it impossible to use names containing lowercase characters with Alembic. https://en.wikipedia.org/wiki/Tz_database#Names_of_time_zones Change-Id: I89288447f91e98dc106d82a1ee233f2f3de30c78 Pull-request: https://bitbucket.org/zzzeek/alembic/pull-requests/69
* Raise if manual revision id contains dashes or at signsMike Bayer2017-08-041-0/+29
| | | | | | | | | A :class:`.CommandError` is raised if the "--rev-id" passed to the :func:`.revision` command contains dashes or at-signs, as this interferes with the command notation used to locate revisions. Change-Id: I60a794a5c80bf47b149998b8c5cb04ecbfd05bfa Fixes: #441
* Add timezone option to configMike Bayer2017-04-061-0/+67
| | | | | | | | | Using dateutil.tz to link string names to tzinfo objects, the create_date can now generate using a named timezone rather than datetime.now(). Change-Id: I9f151cb9e11da3d68be63d7141f60e7eccb9812c Fixes: #425
* Add process_revision_directives param to command.revision()Mike Bayer2017-02-221-3/+40
| | | | | | | | | | This allows programmatic use of command.revision() to specify an ad-hoc process_revision_directives callable, rather than having it placed via the env.py script. Co-authored-by: Tyson Holub Change-Id: Ief1c11fd2a6f10e712851145d6d190a3b167817c Pull-request: https://github.com/zzzeek/alembic/pull/35
* Merge "Add single pound to generated comments"mike bayer2016-11-281-2/+2
|\
| * Add single pound to generated commentsMaico Timmerman2016-11-151-2/+2
| | | | | | | | | | | | | | | | | | | | Adjustment to the "please adjust!" comment in the script.py.mako template so that the generated comment starts with a single pound sign, appeasing flake8. Change-Id: I4b425d2fa8701cabf8352d046b3342a73f78c70d Pull-request: https://bitbucket.org/zzzeek/alembic/pull-requests/65 Partially-fixes: #393
* | file generated by alembic revison is now pep8 compliantMarkus Mattes2016-11-211-1/+5
| | | | | | | | | | Change-Id: I233d2ba2cbbe6a363d9118182f1d855a6a12b00c Pull-request: https://github.com/zzzeek/alembic/pull/31
* | Detect and ignore duplicate revision files on readJiri Kuncar2016-11-181-1/+61
|/ | | | | | | | | | | Added an additional check when reading in revision files to detect if the same file is being read twice; this can occur if the same directory or a symlink equivalent is present more than once in version_locations. A warning is now emitted and the file is skipped. Pull request courtesy Jiri Kuncar. Change-Id: I10ffc8eff420d18c55d3533afb9d5935bbadfe32 Pull-request: https://github.com/zzzeek/alembic/pull/30
* - Errors which occur within the Mako render step are now interceptedMike Bayer2016-04-081-0/+25
| | | | | | | and raised as CommandErrors like other failure cases; the Mako exception itself is written using template-line formatting to a temporary file which is named in the exception message. fixes #367
* - add a test and changelog notes for the fact that a non-autogenerateMike Bayer2015-08-211-0/+20
| | | | | run can render Python code in upgradeops/downgradeops via the process_revision_directives hook.
* - Fixed a regression 0.8 whereby the "multidb" environment templateMike Bayer2015-08-201-3/+166
| | | | | | | | | | | | | | failed to produce independent migration script segments for the output template. This was due to the reorganization of the script rendering system for 0.8. To accommodate this change, the :class:`.MigrationScript` structure will in the case of multiple calls to :meth:`.MigrationContext.run_migrations` produce lists for the :attr:`.MigrationScript.upgrade_ops` and :attr:`.MigrationScript.downgrade_ops` attributes; each :class:`.UpgradeOps` and :class:`.DowngradeOps` instance keeps track of its own ``upgrade_token`` and ``downgrade_token``, and each are rendered individually. fixes #318
* - add a helper object for autogen rewriting called Rewriter.Mike Bayer2015-08-071-1/+146
| | | | | this provides for operation-specific handler functions. docs are based on the example requested in references #313.
* - squash merge of ticket_302 branchMike Bayer2015-07-031-2/+175
| | | | | | | | | | | - The internal system for Alembic operations has been reworked to now build upon an extensible system of operation objects. New operations can be added to the ``op.`` namespace, including that they are available in custom autogenerate schemes. fixes #302 - The internal system for autogenerate been reworked to build upon the extensible system of operation objects present in #302. A new customization hook process_revision_directives is added to allow manipulation of the autogen stream. Fixes #301
* - In conjunction with support for multiple independent bases, theMike Bayer2014-11-221-16/+63
| | | | | | | | | | specific version directories are now also configurable to include multiple, user-defined directories. When multiple directories exist, the creation of a revision file with no down revision requires that the starting directory is indicated; the creation of subsequent revisions along that lineage will then automatically use that directory for new files. fixes #124
* - The "multiple heads / branches" feature has now landed. This isMike Bayer2014-11-201-6/+75
| | | | | | | | | | | | | | by far the most significant change Alembic has seen since its inception; while the workflow of most commands hasn't changed, and the format of version files and the ``alembic_version`` table are unchanged as well, a new suite of features opens up in the case where multiple version files refer to the same parent, or to the "base". Merging of branches, operating across distinct named heads, and multiple independent bases are now all supported. The feature incurs radical changes to the internals of versioning and traversal, and should be treated as "beta mode" for the next several subsequent releases within 0.7. fixes #167
* - reorganize tests that deal with running scriptsMike Bayer2014-11-101-0/+197
and reading scripts; try to put tests against common themes together, improve names