Skip to main content

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
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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csrd_migration-0.3.95.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csrd_migration-0.3.95-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file csrd_migration-0.3.95.tar.gz.

File metadata

  • Download URL: csrd_migration-0.3.95.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for csrd_migration-0.3.95.tar.gz
Algorithm Hash digest
SHA256 78015ddf848b21064651f8f468235ef0a829ba1c2cc98c5c57ecb85153d375eb
MD5 1faa0616ff1976777a83847bc3135bd1
BLAKE2b-256 1cbc37c29c7b44b0d20fd57a522586d5f91f420c2e0c5fc634937b7fc2d58756

See more details on using hashes here.

Provenance

The following attestation bundles were made for csrd_migration-0.3.95.tar.gz:

Publisher: release.yml on csrd-api/fastapi-common

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file csrd_migration-0.3.95-py3-none-any.whl.

File metadata

File hashes

Hashes for csrd_migration-0.3.95-py3-none-any.whl
Algorithm Hash digest
SHA256 caf29de166596c618c5f5851a6ffd5762b4d1ec266234535a8251cc95759580c
MD5 ae78cae501af3cfe3ed2ccaba8d9f9c9
BLAKE2b-256 c6a468f4e417571fa9396bb8ff13332e88e111cd6e2ec93854f66e84a9245583

See more details on using hashes here.

Provenance

The following attestation bundles were made for csrd_migration-0.3.95-py3-none-any.whl:

Publisher: release.yml on csrd-api/fastapi-common

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page