Writing Fixtures¶
Reference schemas are the main way to add repeatable database behavior. A schema is data plus a model source file, not a test that knows dbwarden internals.
ReferenceSchema contract¶
schemas/base.py defines:
name: stable schema name used in database configurationmodels_py: model source pathexpected_tables: tables required after migrationexpected_indexes: indexes required after migrationbackend: default backend family
The registry discovers directories containing models.py and schema.json.
Model source rules¶
- Import only public dbwarden APIs.
- Keep model source deterministic.
- Use metadata types that represent the intended backend behavior.
- Keep the fixture small enough to run across the version matrix.
- Put backend-specific declarations in the model metadata, not in the test.
- Add expected tables and indexes to the schema manifest.
Integration test rules¶
An integration test should:
- Obtain a provider from
provider_for. - Start it inside a
tryand stop it infinally. - Use
MigrationPlayerandSchemaRunnerfor public CLI flows. - Capture semantic state after applying changes.
- Assert a user-visible property, not a private function call.
- Leave enough output for a failed run to be investigated.
New provider behavior¶
Add a provider only when it can implement startup, readiness, reset, version, diagnostics, and teardown. Add lifecycle tests before adding migration tests. That prevents an unavailable container from appearing as a migration defect.