# Database revision 6

The original revision-5 schema remains the foundation. Revision 6 adds:

- `digimon_instances.abi`, `cam`, `intelligence_stat`, `training_json`.
- `digivolution_log.abi_gained`, `direction` (`up`, `down`, `mode`).
- `digimon_learned_moves` for inherited moves tied to instance identity.
- `digimon_battle_state` for per-owner durable turns, enemy state and statuses.
- `digimon_action_receipts` for committed item request tokens/results.

There are **32 tables**. Species are synchronized by slug, preserving the existing 48 species IDs. The catalog has 1,000 rows. The detailed curves, learnsets, mechanics, variant metadata and routes are versioned JSON; SQL contains the indexed species projection used by existing systems.

An account row lock serializes battle turns, conversion, evolution, training, party edits, recovery, shop purchases, arena settlement and exchange changes. Purchases spanning two accounts lock owners in ascending ID order. Battle tokens rotate on committed turns. Inventory spending, vitals, money, scan and reward updates share transactions.

The upgrade recalculates pre-revision-6 partner stats with proportional HP/SP and level progress. A transaction marker prevents reapplying the conversion if installation is interrupted later. It preserves KO status, IDs, nicknames, personality, party links and stored scan percentages. Existing partners start with the new ABI/CAM fields at zero and learn the inherited moves due at their current level.

The three packaged SQL files match byte-for-byte and are **fresh-install seeds only**. Upgrade existing saves through `_setup.php` so the data migration also runs. `tools/build_sql.php` creates those SQL copies from the same actual migration code in a new temporary database; it includes no user accounts or test battle data.
