# OTB Billing Database Reset / Rebuild Reference This is the current clean rebuild process for the otb_billing database. Important notes: - Base schema is loaded from sql/schema_v0.0.2.sql - Some tables are auto-created by the app at runtime - Aging report does NOT require its own table Runtime-created tables: - app_settings - subscriptions - email_log ------------------------------------------------------------ Step 1 — Optional SQL backup cd /home/def/otb_billing || exit 1 mysqldump -u otb_billing -p'!2Eas678' otb_billing > test-backup-before-reset.sql ------------------------------------------------------------ Step 2 — Drop and recreate the database cd /home/def/otb_billing || exit 1 sudo mysql <<'SQL' DROP DATABASE IF EXISTS otb_billing; CREATE DATABASE otb_billing CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER IF NOT EXISTS 'otb_billing'@'localhost' IDENTIFIED BY '!2Eas678'; ALTER USER 'otb_billing'@'localhost' IDENTIFIED BY '!2Eas678'; GRANT ALL PRIVILEGES ON otb_billing.* TO 'otb_billing'@'localhost'; FLUSH PRIVILEGES; SQL ------------------------------------------------------------ Step 3 — Reload base schema cd /home/def/otb_billing || exit 1 mysql -u otb_billing -p'!2Eas678' otb_billing < sql/schema_v0.0.2.sql ------------------------------------------------------------ Step 4 — Start the app cd /home/def/otb_billing || exit 1 ./run_dev.sh ------------------------------------------------------------ Step 5 — Trigger runtime-created tables Open these pages once: /settings /subscriptions To create email_log send one test email. ------------------------------------------------------------ Step 6 — Verify rebuild worked cd /home/def/otb_billing || exit 1 mysql -u otb_billing -p'!2Eas678' -D otb_billing -e " SHOW TABLES; SELECT COUNT(*) AS clients FROM clients; SELECT COUNT(*) AS invoices FROM invoices; SELECT COUNT(*) AS payments FROM payments; SELECT COUNT(*) AS services FROM services; SELECT COUNT(*) AS credit_ledger FROM credit_ledger; " ------------------------------------------------------------ Expected key tables clients services invoices payments credit_ledger app_settings subscriptions email_log