Skip to content
Back to skills

Alembic Knowledge Patch

ASecurity

Alembic

  • 25 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added September 5, 2026
developmentpythonsqlexpressapidatabasebackend

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add Nevaberry/nevaberry-plugins --skill alembic-knowledge-patch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Alembic Knowledge Patch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Alembic Knowledge Patch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nevaberry-alembic-knowledge-patch/badge)](https://www.skillsdirectory.com/skills/nevaberry-alembic-knowledge-patch)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: alembic-knowledge-patch
description: Alembic
version: "1.20.1"
license: MIT
metadata:
  author: Nevaberry
---


# Alembic migration compatibility

Load this skill when updating Alembic migration environments, reviewing
autogenerated revisions, changing migration operations, or extending the CLI.
It covers configuration, schema comparison and rendering, backend DDL,
revision graphs, and extension APIs.

## Reference index

| Reference | Topics |
| --- | --- |
| [Compatibility and configuration](references/compatibility-and-configuration.md) | Runtime requirements, yanked packages, TOML and INI, paths, revision templates, post-write hooks |
| [Autogenerate and rendering](references/autogenerate-and-rendering.md) | Comparison callbacks, CHECKs, naming conventions, reflection, indexes, types, defaults, rewriters |
| [Operations and DDL](references/operations-and-ddl.md) | Removed aliases, conditional DDL, inline keys, batch recreation, backend operations, transactions, offline SQL |
| [Revisions, CLI, and extensions](references/revisions-cli-and-extensions.md) | Heads, branches, revision IDs, history, callbacks, version tables, CLI commands, plugins |

## Breaking changes and deprecations

### Runtime and installation

Alembic 1.17.0 requires Python 3.10 or later. Alembic 1.20.0 requires
SQLAlchemy 2.0.0 or later.

The yanked 1.15.0 wheel omitted migration templates; use 1.15.1 or later
within the 1.15 series. For a pin in the 1.5 series, use 1.5.1 or a later
1.5.x release because 1.5.0 failed to install its templates directory.

### Removed operation keyword aliases

Alembic 1.5.0 removes legacy aliases. Update keyword calls in existing revisions:

| Operation | Old keyword | Replacement |
| --- | --- | --- |
| Constraint operations | `name` | `constraint_name` |
| `drop_constraint()` | `type` | `type_` |
| `create_primary_key()` | `cols` | `columns` |
| `create_unique_constraint()` | `source`, `local_cols` | `table_name`, `columns` |
| `create_check_constraint()` | `source` | `table_name` |
| `create_foreign_key()` | `source`, `referent` | `source_table`, `referent_table` |
| Index operations | `name` | `index_name` |
| `drop_index()` | `tablename` | `table_name` |
| `create_table()`, `drop_table()` | `name` | `table_name` |
| `alter_column()` rename | `name` | `new_column_name` |

The `referent_table` replacement also applies in batch mode.

### Comparison callbacks and plugin entry points

Alembic 1.4.0 switches type comparison to generated DDL and stops calling
the type-level `compare_against_backend` hook. Move custom comparisons to
`context.configure(compare_type=compare_custom_types)` in `env.py`.

Starting in 1.11.0, the rendered metadata default passed to a custom
`compare_server_default` comparator arrives without Alembic's extra SQL
quoting. Adjust callbacks and third-party dialect implementations that
depended on those added quotes.

Point each `alembic.plugins` entry at a single plugin module. Alembic 1.20.1
loads this form and warns about entries pointing to a collection of modules:

```toml
[project.entry-points."alembic.plugins"]
my_plugin = "my_package.alembic_plugin"
```

### INI path parsing

Set `path_separator = os` in `[alembic]` to split `version_locations` and
`prepend_sys_path` on `os.pathsep`, preserving Windows drive-letter colons.
Omitting it triggers deprecated fallback parsing: `version_locations` uses
`version_path_separator` when present, while `prepend_sys_path` splits on
spaces, commas, and colons.

## CHECK constraints and naming conventions

In 1.19.2, name-based CHECK comparison became opt-in under
`alembic.ext.checkconstraint_byname`. The old
`alembic.autogenerate.checkconstraint_byname` name remains accepted for
explicit inclusion or `~` exclusion. Use a client-side naming convention
that names all constraints, including type-bound checks from `Boolean` and
`Enum` with `create_constraint=True`.

```python
context.configure(
    connection=connection,
    target_metadata=target_metadata,
    autogenerate_plugins=[
        "alembic.autogenerate.*",
        "alembic.ext.checkconstraint_byname",
    ],
)
```

In 1.20.0, autogenerate warns and inserts a comment above each generated
`op.drop_constraint(None, ...)`. The drop requires a concrete constraint name;
name the constraint in the model before generation or resolve it in the migration.

Batch recreation carries over named CHECKs and skips unnamed ones. Explicitly
drop a named check before dropping or renaming the column it references.
In 1.20.0, recreation warns when it omits an unnamed reflected CHECK. Supply
the checks to keep in `table_args`; including any `CheckConstraint` there
suppresses the warning.

In 1.20.0, batch recreation emits each type-generated CHECK once and resolves
naming conventions against the original table name. If the convention uses
`%(constraint_name)s`, give the type a name, such as
`sa.Boolean(create_constraint=True, name="active_bool")`.
`batch_alter_table(naming_convention=...)` applies the convention only to
constraints reflected without a name; existing names stay intact.

For autogenerated `op.create_table()` calls, preserving dialect options such
as `postgresql_not_valid` on foreign keys and CHECKs also requires SQLAlchemy
2.0.55 or later in the 2.0 series, or 2.1.5 or later in the 2.1 series.
See the rendering reference for standalone CHECK operations and type-generated checks.

## TOML configuration and revision files

Use `alembic init -t pyproject migrations` for TOML migration paths and
post-write hooks. `%(here)s` expands to the directory containing `pyproject.toml`.
Keep database and logging settings in `alembic.ini`, or supply both in
`env.py` to use TOML alone.

```toml
[tool.alembic]
script_location = "%(here)s/migrations"
version_locations = ["%(here)s/migrations/versions"]
prepend_sys_path = ["%(here)s"]
```

Starting in 1.16.3, `alembic init -t pyproject_async migrations` scaffolds an
async environment with TOML source configuration. Use 1.16.4 or later for
TOML booleans `recursive_version_locations` and `sourceless`; the integer
`truncate_slug_length` setting requires 1.16.5 or later.

Alembic creates subdirectories named in `file_template` when generating a
revision. Enable recursive discovery so later migration commands find the files:

```ini
[alembic]
file_template = %%(year)d/%%(month).2d/%%(day).2d_%%(rev)s_%%(slug)s
recursive_version_locations = true
```

A `module` post-write hook runs a tool with `python -m` using Alembic's
interpreter. For a `console_scripts` hook needing configuration in a
particular directory, set `<hook>.cwd`.

## Column DDL and batch operations

On supporting backends, `add_column(if_not_exists=True)`,
`drop_column(if_exists=True)`, and `drop_constraint(if_exists=True)` emit
conditional DDL. Autogenerate renders these flags when a `Rewriter` sets them
on the corresponding operation.

Starting in 1.18.2, `op.add_column(..., inline_references=True)` emits the
foreign key reference within `ADD COLUMN` on PostgreSQL, Oracle, MySQL 5.7+,
and MariaDB 10.5+. Starting in 1.18.5, it includes foreign key options such as
`ON DELETE` and `ON UPDATE`.

Starting in 1.18.4, pass `inline_primary_key=True` as well as
`Column(primary_key=True)` to emit an inline `PRIMARY KEY` in `add_column()`,
subject to the backend's rules for adding primary keys.

Batch `alter_column()` honors `insert_before` and `insert_after`; use table
recreation to apply the order change. A rename-only `op.alter_column()` call
uses SQLite's native `ALTER TABLE … RENAME COLUMN` where that DDL is supported.

With `transactional_ddl=False`, Alembic raises `CommandError` if a revision
opens a transaction and leaves it open. Close each transaction the migration
opens before returning.

## Checking heads and working with branches

Starting in 1.17.1, `alembic current --check-heads` exits nonzero if the database
is missing any head revision. The Python call
`alembic.command.current(config, check_heads=True)` raises `DatabaseNotAtHead`
in that case.

Starting in 1.18.5, `ScriptDirectory.get_heads(consider_depends_on=True)` excludes
heads referenced by another revision's `depends_on`, matching the revisions
expected in `alembic_version` after all upgrades.

Use `alembic merge --splice -m "merge branches" a1b2c3 d4e5f6` to merge when
one or more inputs are non-head revisions, starting in 1.18.5. A downgrade
can unwind a single branch to a shared branch point; an unqualified relative
target such as `alembic downgrade -1` warns when multiple heads make it ambiguous.

Custom revision IDs reject `-`, `@`, `+`, and `:`. An abbreviated ID must be
an unambiguous prefix of at least four characters; pass a shorter custom ID in full.
The revisions reference gives the introduction versions and relative-target examples.

## Autogenerate review and rewriters

Autogenerate skips SQLite expression indexes and warns; write their changes
explicitly. When a reflected `Computed` expression differs, autogenerate warns
on backends with computed column reflection and SQLAlchemy 1.3.16 or later;
write the column recreation explicitly.

Starting in 1.20.1, empty table or column comments compare as equivalent to
`None`, while generated `op.create_table()` and `op.add_column()` preserve
explicit `comment=""` values.

`Rewriter.chain()` supports more than two rewriters and ordinary
`process_revision_directives` callbacks. Register the chain in `env.py` to run
processors in order. A rewriter can set `AlterColumnOp.modified_name` to render
a column rename, starting in 1.15.2.

Autogenerate renders custom `ExecuteSQLOp` objects containing plain SQL strings.
Passing a SQLAlchemy expression such as `sa.text(...)` raises
`NotImplementedError` during rendering. For SQL execution inserted by a rewriter,
`alembic_module_prefix="migration_op."` renders `migration_op.execute(...)`.

Files in this skill

  • SKILL.md7.9 KB
  • coverage.json719 B
  • references/autogenerate-and-rendering.md4.4 KB
  • references/compatibility-and-configuration.md3.2 KB
  • references/operations-and-ddl.md3.1 KB
  • references/revisions-cli-and-extensions.md3.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.