# Database Install Handoff

Use this for a clean local or staging MVP database install when handing the project to the human architect.

## Command

From the project root:

```powershell
C:\xampp\php\php.exe bin\install-database --fresh --yes
```

Or, if PHP is on `PATH`:

```bash
php bin/install-database --fresh --yes
```

## What It Does

- Reads `.env`, falling back to `.env.example`.
- Uses `DB_DSN`, `DB_USERNAME` or `DB_USER`, and `DB_PASSWORD`.
- Creates the MySQL database from the `dbname` value in `DB_DSN`.
- Imports `docs/schema.sql`.
- Seeds local/staging demo data:
  - platform super admin
  - platform admin
  - organiser owner
  - organiser admin
  - event manager
  - cashier
  - ticket scanner
  - customer
  - approved organiser
  - published demo event
  - venue and reserved seat map
  - adult and child ticket types
  - VAT/tax and platform fee rules
  - merchandise, promo code, and donation settings
- Runs the MVP runtime schema/default hook so operational tables, feature gates, branding defaults, and skin/theme defaults are present.

## Demo Credentials

Use only for local or staging review:

- Platform super admin: `admin@zavvion.test` / `ChangeMe123!`
- Platform admin: `platform.admin@zavvion.test` / `ChangeMe123!`
- Organiser owner: `organiser@zavvion.test` / `ChangeMe123!`
- Organiser admin: `organiser.admin@zavvion.test` / `ChangeMe123!`
- Event manager: `event.manager@zavvion.test` / `ChangeMe123!`
- Cashier: `cashier@zavvion.test` / `ChangeMe123!`
- Ticket scanner: `scanner@zavvion.test` / `ChangeMe123!`
- Customer: `customer@zavvion.test` / `ChangeMe123!`

Change or remove these accounts before any public production deployment.

## Safe Options

```bash
php bin/install-database --dry-run
php bin/install-database --no-seed
php bin/install-database --database=zavvion_events_staging
php bin/install-database --schema=docs/schema.sql
```

`--fresh` drops the target database first, so it also requires `--yes`. The command refuses `--fresh` when `APP_ENV=prod` or `APP_ENV=production`.

## After Install

Run:

```powershell
C:\xampp\php\php.exe bin\check-mvp-smoke --base-url=http://localhost/zavvion-events/public
C:\xampp\php\php.exe bin\check-local-live-run --base-url=http://localhost/zavvion-events/public
```

## Finance Integrity Repair

If the database already contains older MVP test orders, run the finance-integrity repair in dry-run mode before handoff:

```powershell
C:\xampp\php\php.exe bin\repair-finance-integrity
```

If the dry run reports only deterministic repairs and no unresolved records, apply it:

```powershell
C:\xampp\php\php.exe bin\repair-finance-integrity --apply
```

This command backfills missing paid-order ledger/payment/ticket rows only when the values can be derived safely from existing checkout/order records. It does not hide ambiguous reconciliation issues; unresolved rows must be reviewed by the human architect.

For Stripe testing, configure Stripe test keys and a connected organiser account before running paid checkout tests.
