quaestor
In ancient Rome, a quaestor was the official in charge of the treasury — here, it manages your MongoDB schema and data, your real treasure.
Lightweight MongoDB migration module with named migrations and dependency resolution.
Install
pip install mongo-quaestor
Quick Start
import asyncio
from motor.motor_asyncio import AsyncIOMotorClient
from quaestor import MigrationRegistry
registry = MigrationRegistry()
@registry.register("create_users_index")
async def create_users_index(db):
await db.users.create_index("email", unique=True)
@registry.register("add_status_field", depends_on=["create_users_index"])
async def add_status_field(db):
await db.users.update_many(
{"status": {"$exists": False}},
{"$set": {"status": "active"}},
)
async def main():
client = AsyncIOMotorClient("mongodb://localhost:27017")
db = client["myapp"]
applied = await registry.run(db, "myapp")
print(f"Applied migrations: {applied}")
asyncio.run(main())
API Reference
| Symbol | Signature | Description |
|---|---|---|
MigrationRegistry() |
MigrationRegistry() |
Create a new registry. No arguments. |
.register() |
register(name: str, depends_on: list[str] | None = None) -> Callable |
Decorator. Registers an async migration function. |
.run() |
async run(db: AsyncIOMotorDatabase, prefix: str) -> list[str] |
Execute all unapplied migrations. Returns names of applied migrations. |
.migrations |
migrations -> dict[str, MigrationDefinition] |
Read-only property. All registered migrations. |
How It Works
- Applied migrations are tracked in a MongoDB collection named
{prefix}_migrations. - Each record stores
name(str) andappliedAt(UTC datetime). - Dependencies are resolved via topological sort (Kahn's algorithm). Circular or missing dependencies raise
ValueError. - Failed migrations are not recorded, so they retry automatically on the next
run()call. - Independent migrations (no dependency relationship between them) execute in alphabetical order for deterministic behavior.
- Multiple registries can safely share one database by using different prefixes.
- Progress and errors are logged to the
quaestorlogger.
Metadata
Release files for mongo-quaestor 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mongo_quaestor-0.1.0.tar.gz | 9.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mongo_quaestor-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.9 kB
Release files / mongo_quaestor-0.1.0.tar.gz
| Download URL | mongo_quaestor-0.1.0.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3514d52e0c198e1fee2c7a61bbdb16ca0dc80f1dd1792285b07a20154e7272a4
|
|
BLAKE2b-256 checksum How to use checksums |
b31c05019520c1a4efa8a91bcb26490a97c4243ae7ff28936211a518f28ff508
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / mongo_quaestor-0.1.0-py3-none-any.whl
| Download URL | mongo_quaestor-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be15a4bda0ce2ead642a6c22127ce9ecfe49ed894074d8bc2f26a83637281c61
|
|
BLAKE2b-256 checksum How to use checksums |
9a8c94f1cdb64b2725eb9929649ec8ae913bcbbeecba8e118942945f5989440a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|