# Phase 5 — Real Database Reconciliation

Source: `anode_battery (6).sql`, generated 2026-08-13.

## Inventory

- 111 `CREATE TABLE` definitions in the dump; 8 are phpMyAdmin view stand-ins.
- 103 base tables after excluding those view stand-ins.
- 8 views.
- 4 triggers:
  - `trg_bar_duplicate_guard`
  - `trg_coupon_usage_after_delete`
  - `trg_coupon_usage_after_insert`
  - `trg_orders_status_change`
- 5 procedures:
  - `sp_calculate_used_battery_credit`
  - `sp_database_health_check`
  - `sp_generate_order_number`
  - `sp_generate_warranty_number`
  - `_add_fk_if_not_exists`
- 4 events:
  - `evt_cleanup_expired_otps`
  - `evt_cleanup_expired_tokens`
  - `evt_cancel_expired_orders`
  - `evt_cleanup_idempotency`

## Migration history finding

The legacy SQL directory contains 68 files and three historical suffix variants (`08b`, `32b`, `56b`). They are immutable historical artifacts and must not be silently renumbered. Phase 5 therefore archives them and establishes a Phinx baseline as the new schema lifecycle boundary.

## Important consequence

The supplied database snapshot is now the canonical schema reference. The previous partial `schema_dump.sql` must not be used as the Phase 5 source of truth.

## Safety

No `FOREIGN_KEY_CHECKS=0` is introduced. The baseline creates the complete schema in the order recorded by the real dump, including tables, foreign keys, views, triggers, procedures and events. On an existing database, the baseline is a no-op only after the expected table inventory is already present.
