Skip to content

Multi Database Behavior

Ngan Pham edited this page May 6, 2026 · 2 revisions

Multi-Database Behavior

FixtureKit stores restore SQL keyed by model class name and replays per model connection pool.

Why This Works for Multi-DB

At replay time, FixtureKit:

  1. Constantizes cached model names.
  2. Groups statements by each model's connection_pool (the stable identity for a database, role-aware).
  3. Checks out a connection via pool.with_connection for the duration of the replay on that pool.
  4. Replays table clears + inserts inside that connection.

This routes writes to the same database handlers used by those models (for example, primary, analytics, etc.).

Change Tracking Input

During generation, FixtureKit subscribes to sql.active_record and tracks models for names matching write operations (Insert/Upsert/Create/Update/Delete/Destroy and supported bulk variants).

Practical Guidance

  • Ensure your fixture generation touches the same models your tests need.
  • If a model's data is expected but missing, verify that model had a write during generation.

Clone this wiki locally