Skip to main content

csrd-migration

Versioned, idempotent schema migrations for csrd.repository database adapters.

Quick start

from csrd.migration import Migration, MigrationRunner
from csrd.repository import SQLiteAdapter

MIGRATIONS = [
    Migration(
        version="001",
        description="create users table",
        up="CREATE TABLE users (id INTEGER PRIMARY KEY, username TEXT NOT NULL)",
        down="DROP TABLE users",
    ),
]

async def setup_db():
    adapter = SQLiteAdapter("app.db")
    await adapter.connect()
    runner = MigrationRunner()
    await runner.apply_all(adapter, MIGRATIONS)

API

Migration

Frozen dataclass representing a single schema change.

Field Type Description
version str Unique version identifier (e.g. "001", "002")
description str Human-readable description
up str SQL to apply the migration
down str SQL to revert the migration

MigrationRunner

Applies and tracks migrations against any ABCDatabaseAdapter.

Method Description
apply_all(adapter, migrations) Apply all pending migrations in order
rollback(adapter, migrations, *, to_version=None) Roll back applied migrations in reverse order. Pass to_version to stop at a specific version, or None to roll back all
reapply_all(adapter, migrations) Roll back all then re-apply — clean schema reset without dropping the database
current_version(adapter) Return the latest applied version, or None
pending(adapter, migrations) Return migrations not yet applied

The runner creates a _csrd_migrations table automatically to track applied versions. Re-running is idempotent — already-applied migrations are skipped.

Design

  • Adapter-agnostic — works with SQLiteAdapter, PGAdapter, MariaAdapter
  • Idempotent — safe to call on every startup
  • Ordered — migrations are applied in list order
  • Future-ready — the Migration dataclass is the stable interface for a future model→SQL translation layer (see docs/AUGMENT_PLAN.md)

Metadata

Release files for csrd-migration 0.5.29

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for csrd-migration 0.5.29
File Size Uploaded
csrd_migration-0.5.29.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for csrd-migration 0.5.29
File Interpreter ABI Platform
csrd_migration-0.5.29-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / csrd_migration-0.5.29.tar.gz

Download URL csrd_migration-0.5.29.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b6378f9b5aeaf5cbda47b92c15b127a65378200b5e1e5f15e7d73f844832e636
BLAKE2b-256 checksum
How to use checksums
60d108220748430ebbc2a829056aa13182df62dfb429f7c49c669f1ccadb9626
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / csrd_migration-0.5.29-py3-none-any.whl

Download URL csrd_migration-0.5.29-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56c59bd9ca571886d6c6d38d322ff21ef0ce94d737ab5094d5cd8955c1892ee9
BLAKE2b-256 checksum
How to use checksums
3af46d59810cfdad4b2b7505c5a3e655c4ab4d456f736133a6e6845ab31ea2ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release history Release notifications | RSS feed

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.30

2 release files

This release

0.5.29 This release

2 release files

0.5.28

2 release files

0.5.27

2 release files

0.5.26

2 release files

0.5.25

2 release files

0.5.24

2 release files

0.5.23

2 release files

0.5.22

2 release files

0.5.21

2 release files

0.5.9

2 release files

0.5.8

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page