Alembic Versions Save

A database migrations tool for SQLAlchemy.

rel_1_13_1

4 months ago

1.13.1

Released: December 20, 2023

bug

  • [bug] [autogenerate] Fixed Rewriter so that more than two instances could be chained together correctly, also allowing multiple process_revision_directives callables to be chained. Pull request courtesy zrotceh.

    References: #1337

  • [bug] [environment] Fixed issue where the method EnvironmentContext.get_x_argument() using the EnvironmentContext.get_x_argument.as_dictionary parameter would fail if an argument key were passed on the command line as a name alone, that is, 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.

    References: #1369

  • [bug] [autogenerate] Fixed issue where the "unique" flag of an Index would not be maintained when generating downgrade migrations. Pull request courtesy Iuri de Silvio.

    References: #1370

  • [bug] [versioning] 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.

    References: #1373

  • [bug] [typing] 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.

    References: #1377

rel_1_13_0

5 months ago

1.13.0

Released: December 1, 2023

changed

  • [changed] [installation] Alembic 1.13 now supports Python 3.8 and above.

    References: #1359

usecase

  • [usecase] [operations] Updated logic introduced in #151 to allow if_exists and if_not_exists on index operations also on SQLAlchemy 1.4 series. Previously this feature was mistakenly requiring the 2.0 series.

    References: #1323

  • [usecase] Replaced python-dateutil with the standard library 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.

    References: #1339

bug

  • [bug] [commands] 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.

    References: #1234

  • [bug] [autogenerate] 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.

    References: #1361

  • [bug] [postgresql] 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.

    References: #1321, #1327, #1356

rel_1_12_1

6 months ago

1.12.1

Released: October 26, 2023

usecase

  • [usecase] Alembic now accommodates for Sequence and Identity that support dialect kwargs. This is a change that will be added to SQLAlchemy v2.1.

    References: #1304

bug

  • [bug] [autogenerate] [regression] Fixed regression caused by #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.

    References: #1329

  • [bug] [typing] Improved typing in the EnvironmentContext.configure.process_revision_directives callable to better indicate that the passed-in type is MigrationScript, not the MigrationOperation base class, and added typing to the example at cookbook_no_empty_migrations to illustrate.

    References: #1325

  • [bug] [operations] Repaired 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.

    References: #1335

  • [bug] [typing] Improved the op.execute() method to correctly accept the Executable type that is the same which is used in SQLAlchemy Connection.execute(). Pull request courtesy Mihail Milushev.

    References: #1058, #1277

  • [bug] [typing] Improve typing of the revision parameter in various command functions.

    References: #930

  • [bug] [typing] Properly type the Operations.create_check_constraint.condition parameter of Operations.create_check_constraint() to accept boolean expressions.

    References: #1266

  • [bug] [postgresql] 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.

    References: #1322

rel_1_12_0

8 months ago

1.12.0

Released: August 31, 2023

feature

  • [feature] [autogenerate] 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.

    References: #1275

usecase

  • [usecase] [autogenerate] Change the default value of EnvironmentContext.configure.compare_type to True. As Alembic's autogenerate for types was dramatically improved in version 1.4 released in 2020, the type comparison feature is now much more reliable so is now enabled by default.

    References: #1248

bug

  • [bug] [operations] 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.

    References: #1300

  • [bug] [commmands] 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.

    References: #1299

  • [bug] [autogenerate] Fixed issue where the ForeignKeyConstraint.match parameter would not be rendered in autogenerated migrations. Pull request courtesy Asib Kamalsada.

    References: #1302

rel_1_11_3

9 months ago

1.11.3

Released: August 16, 2023

bug

  • [bug] [autogenerate] [postgresql] Improved autogenerate compare of expression based indexes on PostgreSQL to produce fewer wrong detections.

    References: #1270

  • [bug] [autogenerate] Fixed issue with NULLS NOT DISTINCT detection in postgresql that would keep detecting changes in the index or unique constraint.

    References: #1291

  • [bug] [commands] 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.

    References: #1273

rel_1_11_2

9 months ago

1.11.2

Released: August 4, 2023

feature

  • [feature] [operations] Added parameters if_exists and if_not_exists for index operations. Pull request courtesy of Max Adrian.

    References: #151

usecase

  • [usecase] [typing] Added typing to the default script mako templates.

    References: #1253

  • [usecase] [autogenerate] Added support in autogenerate for NULLS NOT DISTINCT in the PostgreSQL dialect.

    References: #1248

bug

  • [bug] Fixed format string logged when running a post write hook Pull request curtesy of Mathieu Défosse.

    References: #1261

rel_1_11_1

11 months ago

1.11.1

Released: May 17, 2023

bug

  • [bug] [autogenerate] [regression] As Alembic 1.11.0 is considered a major release (Alembic does not use semver, nor does its parent project SQLAlchemy; this has been clarified <versioning_scheme> in the documentation), change #1130 modified calling signatures for most operations to consider all optional keyword parameters to be keyword-only arguments, to match what was always documented and generated by autogenerate. However, two of these changes were identified as possibly problematic without a more formal deprecation warning being emitted which were the table_name parameter to Operations.drop_index(), which was generated positionally by autogenerate prior to version 0.6.3 released in 2014, and type_ in Operations.drop_constraint() and BatchOperations.drop_constraint(), which was documented positionally in one example in the batch documentation.

    These two signatures have been restored to allow those particular parameters to be passed positionally. A future change will include formal deprecation paths (with warnings) for these arguments where they will again become keyword-only in a future "Significant Minor" release.

    References: #1243, #1245

  • [bug] [typing] Fixed typing use of ~sqlalchemy.schema.Column and other generic SQLAlchemy classes.

    References: #1246

  • [bug] [regression] [typing] Restored the output type of 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.

    References: #1244

rel_1_11_0

1 year ago

1.11.0

Released: May 15, 2023

usecase

  • [usecase] [commands] Added quiet option to the command line, using the -q/--quiet option. This flag will prevent alembic from logging anything to stdout.

    References: #1109

  • [usecase] [asyncio] Added AbstractOperations.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 ~sqlalchemy.ext.asyncio.AsyncConnection sharing the transaction used in the migration context.

    References: #1231

bug

  • [bug] [batch] Added placeholder classes for ~.sqla.Computed and ~.sqla.Identity when older 1.x SQLAlchemy versions are in use, namely prior to SQLAlchemy 1.3.11 when the ~.sqla.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".

    References: #1237

  • [bug] [batch] Correctly pass previously ignored arguments insert_before and insert_after in batch_alter_column

    References: #1221

  • [bug] [postgresql] Fix autogenerate issue with PostgreSQL ExcludeConstraint that included sqlalchemy functions. The function text was previously rendered as a plain string without surrounding with text().

    References: #1230

  • [bug] [mysql] [regression] Fixed regression caused by #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.

    References: #1240

  • [bug] [typing] Updated stub generator script to also add stubs method definitions for the Operations class and the BatchOperations class obtained from Operations.batch_alter_table(). As part of this change, the class hierarchy of Operations and BatchOperations has been rearranged on top of a common base class AbstractOperations in order to type correctly, as BatchOperations uses different method signatures for operations than Operations.

    References: #1093

  • [bug] [typing] Repaired the return signatures for Operations that mostly return None, and were erroneously referring to Optional[Table] in many cases.

  • [bug] [autogenerate] Modified the autogenerate implementation for comparing "server default" values from user-defined metadata to not apply any quoting to the value before comparing it to the server-reported default, except for within dialect-specific routines as needed. This change will affect the format of the server default as passed to the EnvironmentContext.configure.compare_server_default hook, as well as for third party dialects that implement a custom compare_server_default hook in their alembic impl, to be passed "as is" and not including additional quoting. Custom implementations which rely on this quoting should adjust their approach based on observed formatting.

    References: #1178

  • [bug] [api] [autogenerate] Fixed issue where 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 autogenerate.render_python_code.user_module_prefix to allow this to be set as well as to default to None. Pull request courtesy tangkikodo.

    References: #1235

misc

  • [change] [py3k] Argument signatures of Alembic operations now enforce keyword-only arguments as passed as keyword and not positionally, such as Operations.create_table.schema, Operations.add_column.type_, etc.

    References: #1130

  • [misc] Update code snippets within docstrings to use black code formatting. Pull request courtesy of James Addison.

    References: #1220

rel_1_10_4

1 year ago

1.10.4

Released: April 24, 2023

bug

  • [bug] [operations] 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.

    References: #1215

misc

  • [autogenerate] [postgresql] Added support for autogenerate comparison of indexes on PostgreSQL which include SQL sort option, such as ASC or NULLS FIRST.

    References: #1213

rel_1_10_3

1 year ago

1.10.3

Released: April 5, 2023

bug

  • [bug] [typing] Fixed various typing issues observed with pyright, including issues involving the combination of Function and MigrationContext.begin_transaction().

    References: #1191, #1201

  • [bug] [autogenerate] Fixed error raised by alembic when running autogenerate after removing a function based index.

    References: #1212