# Clean tenant database template

The canonical template database contains the current application schema without
student, staff, class, tuition, CRM lead, notification, attendance, salary, or
other operational records.

System seed data is controlled by `config/tenant-template.php`. The template
also contains:

- one neutral `config_tb` row;
- one default branch;
- one disabled bootstrap administrator;
- `tenant_schema_meta_tb`, which records the template schema version.

Create an empty database and grant the application database user access, then
run:

```bash
php bin/tenant-create-template.php \
  --source=webdemoo_diemdanh \
  --target=webdemoo_tenant_template

php bin/tenant-verify-template.php \
  --database=webdemoo_tenant_template
```

The command refuses to write to a non-empty target. When no admin password is
provided, the generated bootstrap administrator is disabled and cannot be used
to sign in. Tenant provisioning must replace it with unique credentials before
activation.

## Provision a new tenant database

Create an empty target database in cPanel and grant the application database
user access. Store the tenant's initial password in a temporary file readable
only by the provisioning process, then run:

```bash
php bin/tenant-provision-database.php \
  --template=webdemoo_tenant_template \
  --target=webdemoo_new_center \
  --center-name='New Center' \
  --branch-name='Main Branch' \
  --admin-name='Center Administrator' \
  --admin-email='admin@example.com' \
  --admin-password-file=/secure/path/admin-password.txt
```

The target must be empty. The command verifies the template before cloning,
activates exactly one administrator with `force_reset = 1`, updates the center
and branch names, and checks that personal and operational tables remain empty.
It never prints the supplied password. If provisioning fails after it starts,
the command removes the objects it created so the empty target can be retried.

To validate the canonical template without creating a tenant:

```bash
php bin/tenant-provision-database.php \
  --template=webdemoo_tenant_template \
  --check-template
```
