# Install the clean BookingSystem database

Use [`BookingSystem-clean-install-20260927.sql`](./BookingSystem-clean-install-20260927.sql) only with a newly created, empty database. It is the baseline schema and reference data through migration `202609280042`; it is not the current final schema. The current migration manifest continues through `202610020087`, so a fresh install must run the migrations after importing this file. The snapshot body defines 208 base tables plus one view and records 42 migration-history rows. Its generated header comments claiming 127 tables and migration `202609280030` are stale; do not hand-edit the generated SQL to correct them. It contains no application users, passwords, Provinces, units, meetings, bookings or other operational records.

The installer now defines 208 base tables plus one view and records 42 migrations while retaining the built-in role defaults and zero operational users or units. The exact combined installer was imported successfully into a temporary empty MariaDB 10.4.32 database during this stage, then the temporary database was removed. It contains no stored procedures or `CALL` statements, avoiding phpMyAdmin's pending-result `#2014` error. Its SHA-256 checksum is `77c23917e409210cbbb7d4c63086f9bab907d6fffc05cdf5da977dd6a0efaa1a`.

## Before importing

MariaDB must start normally. If XAMPP still reports an Aria or `mysql.plugin` error, reinstall or repair MariaDB first; an SQL import cannot repair damaged MariaDB system tables. Preserve any copy of the old `C:\xampp\mysql\data` directory before reinstalling XAMPP in case data recovery is later possible.

## phpMyAdmin installation

1. Start Apache and MySQL in XAMPP.
2. Delete the partially imported application database from the failed attempt only if it contains no data you need, then create a new database, for example `booking_system`, with collation `utf8mb4_unicode_ci`. Do not reuse a partially populated database.
3. Select that empty database. Do not select the `mysql`, `performance_schema`, `phpmyadmin` or another system database.
4. Open **Import**, select `BookingSystem-clean-install-20260927.sql`, leave the format as SQL, and run the import once.
5. The final result must say `BookingSystem clean schema installed successfully`, with `user_count` and `unit_count` both zero. An error stating that the database is not empty means a new empty database must be selected; do not rerun the full file over a partial import.
6. Configure the application process to use this local database. Use the protected local configuration or the supported `BOOKING_DB_*` environment variables; never put credentials under `public_html` or point this rehearsal at production.
7. From the repository root, inspect the baseline and apply the remaining canonical migrations:

	```powershell
	C:\xampp\php\php.exe bin\migrate.php --status
	C:\xampp\php\php.exe bin\migrate.php --apply
	C:\xampp\php\php.exe bin\migrate.php --status
	C:\xampp\php\php.exe bin\deployment-readiness.php
	```

	Before applying, `--status` should show the baseline migrations through `202609280042` and later manifest entries as pending. It may exit with readiness status 3 until those entries are applied; inspect the listed states and missing readiness checks. After applying, the latest migration must be `202610020087`, no manifest migration may be pending, and deployment readiness must pass. Do not use `--allow-destructive` for this clean-install sequence.
8. Set a new random `application.setup_key` in the private configuration, then visit `/admin/setup.php` to create the first Global Administrator. The page requires a password of at least 12 characters. Remove or rotate the setup key after the account has been created.
9. Sign in, create the Province and unit through the platform setup screens, then run the application smoke tests.

## Command-line alternative

From Command Prompt, with MySQL running:

```bat
C:\xampp\mysql\bin\mysql.exe --host=127.0.0.1 --port=3306 --user=YOUR_DATABASE_USER --password booking_system < C:\BookingSystem\BookingSystem\database\BookingSystem-clean-install-20260927.sql
```

Enter the password interactively. Do not add it to the command or save it in this repository.

## Verification queries

```sql
SELECT COUNT(*) AS tables_installed
FROM information_schema.tables
WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE';

SELECT version, name, applied_at
FROM migration_history
ORDER BY version;

SELECT COUNT(*) AS users FROM users;
SELECT COUNT(*) AS provinces FROM provinces;
SELECT COUNT(*) AS units FROM units;
```

The clean baseline intentionally returns zero users, Provinces and units. After the migration runner completes, the latest manifest version must be `202610020087`; reference tables such as `unit_types`, `tenant_roles`, `tenant_role_scopes`, `platform_email_templates` and `platform_order_rank_settings` must contain rows. `migration_history` also retains two historical baseline entries that are no longer in the current manifest.

## Rollback

If the import fails, retain the phpMyAdmin error message, drop only the newly created application database, create another empty database and retry after correcting the reported problem. Never drop a system database or overwrite the old MariaDB data directory. Because this is a clean installer, it does not provide an in-place rollback for an existing database.

