alembic-migrations

alembic-migrations is a cursor rule for Cursor from iloveitaly/llm-ide-rules. It costs 0 tokens per session (375 once invoked), scanned A, original, MIT.

Database migration guidance for Alembic, a tool that applies database structure changes over time. It shows how to add a required column, fill existing records, and run data updates safely.

In plain words
What is it for?
Use it when writing Alembic migrations that add non-nullable columns or change existing data. It also shows how to run backfill code through a database session.
Why use it?
Adding a required column to a table with existing records can fail because old records have no value for it. These patterns avoid that problem without leaving an unwanted permanent default.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when writing Alembic migrations that add non-nullable columns or change existing data. It also shows how to run backfill code through a database session.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/iloveitaly/llm-ide-rules/alembic-migrations
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/iloveitaly/llm-ide-rules

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for alembic-migrations

README.md
[![agentmods](https://agentmods.dev/badge/rules/iloveitaly/llm-ide-rules/alembic-migrations/github.svg)](https://agentmods.dev/rules/iloveitaly/llm-ide-rules/alembic-migrations)
Your own site
<a href="https://agentmods.dev/rules/iloveitaly/llm-ide-rules/alembic-migrations"><img src="https://agentmods.dev/badge/rules/iloveitaly/llm-ide-rules/alembic-migrations/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for alembic-migrations

Your own site · 80×15
<a href="https://agentmods.dev/rules/iloveitaly/llm-ide-rules/alembic-migrations"><img src="https://agentmods.dev/badge/rules/iloveitaly/llm-ide-rules/alembic-migrations.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 375 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00375
Opus 5 $0.00000 $0.00187
Sonnet 5 $0.00000 $0.00075
Haiku 4.5 $0.00000 $0.00038

Measured 9d ago against content hash 1a44cf2a6d0d, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

alembic-migrations scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/alembic-migrations.mdc · 63 lines

What it actually says

Alembic Migrations

Default Content for New Non-Nullable Columns

To add a non-nullable column and set a specific value for all existing rows without a persistent server default:

# 1. Add the column as nullable (no default needed):
op.add_column(
    "distribution",
    sa.Column(
        "default_campaign_ending_date", sa.DateTime(timezone=True), nullable=True
    ),
)
# 2. Update existing rows with your desired value (e.g., a specific datetime)
op.execute(
    "UPDATE distribution SET default_campaign_ending_date = %s", [datetime.utcnow()]
)
# 3. Alter the column to non-nullable:
op.alter_column("distribution", "default_campaign_ending_date", nullable=False)

Record Backfill Operations

For migrations that include data mutation, and not only schema modifications, use this pattern to setup a session:

from alembic import op
from sqlmodel import Session
from activemodel.session_manager import global_session
from app import log


def run_migration_helper():
    pass


def upgrade() -> None:
    session = Session(bind=op.get_bind())

    with global_session(session):
        run_migration_helper()
        flip_point_coordinates()
        backfill_screening_host_data()

    # flush before running any other operations, otherwise not all changes will persist to the transaction
    session.flush()

However, if you don't need the business logic attached to the models, you can execute a query using op.execute:

op.execute(
    TheModel.__table__.update().values({"a_field": "a_value"})  # type: ignore
)
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 63 lines · 0 tokens per session scan A 1a44cf2a6d0d

Subscribe to this mod's changes

alembic-migrations is a cursor rule published in the GitHub repository iloveitaly/llm-ide-rules (13 stars, last pushed yesterday), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 375 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.