Versioned schema migrations for csrd database adapters
Project description
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
Migrationdataclass is the stable interface for a future model→SQL translation layer (seedocs/AUGMENT_PLAN.md)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file csrd_migration-0.3.101.tar.gz.
File metadata
- Download URL: csrd_migration-0.3.101.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7793904f00093aa96125d3083cc943705bdde264beff4ee811bb75e0a4fa319e
|
|
| MD5 |
108429c29ae57607f663ad90d6da72c6
|
|
| BLAKE2b-256 |
82553d9e00f78cf2b2d2af1a30d89ee1676d66b1642db84c33cdd71078761478
|
Provenance
The following attestation bundles were made for csrd_migration-0.3.101.tar.gz:
Publisher:
release.yml on csrd-api/fastapi-common
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
csrd_migration-0.3.101.tar.gz -
Subject digest:
7793904f00093aa96125d3083cc943705bdde264beff4ee811bb75e0a4fa319e - Sigstore transparency entry: 1447263096
- Sigstore integration time:
-
Permalink:
csrd-api/fastapi-common@51c942bffe700b6257b45b4bbe3e36c6e839654f -
Branch / Tag:
refs/tags/v0.3.101 - Owner: https://github.com/csrd-api
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@51c942bffe700b6257b45b4bbe3e36c6e839654f -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file csrd_migration-0.3.101-py3-none-any.whl.
File metadata
- Download URL: csrd_migration-0.3.101-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed5fdf5b67adeb19b24f09ed1e014c4f05a1a5dda5aa514a0161271d806b8fba
|
|
| MD5 |
36e02c8c6ea9ed50efbfb1347b2bc5aa
|
|
| BLAKE2b-256 |
e1f233a8fa2131f2906aa03c7eb6e0f6b901d5487a40ad92165936de438467bc
|
Provenance
The following attestation bundles were made for csrd_migration-0.3.101-py3-none-any.whl:
Publisher:
release.yml on csrd-api/fastapi-common
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
csrd_migration-0.3.101-py3-none-any.whl -
Subject digest:
ed5fdf5b67adeb19b24f09ed1e014c4f05a1a5dda5aa514a0161271d806b8fba - Sigstore transparency entry: 1447264568
- Sigstore integration time:
-
Permalink:
csrd-api/fastapi-common@51c942bffe700b6257b45b4bbe3e36c6e839654f -
Branch / Tag:
refs/tags/v0.3.101 - Owner: https://github.com/csrd-api
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@51c942bffe700b6257b45b4bbe3e36c6e839654f -
Trigger Event:
workflow_dispatch
-
Statement type: