# Stage 10 - Tenant Schema and Seed

## Goal

This stage prepares the first tenant database after the tenant record is created in the master database.

## Files

Created:

- `installer-package/install/src/TenantDatabaseStep.php`
- `installer-package/install/database/tenant/001_tenant_schema.sql`
- `installer-package/install/database/tenant/077_menu_mega_foundation.sql`

Changed:

- `installer-package/install/bootstrap.php`
- `installer-package/install/install.php`
- `installer-package/install/src/InstallerState.php`
- `installer-package/install/src/RequirementStep.php`
- `installer-package/install/views/partials/main-form.php`

## Installer Action

New action:

- `install_tenant_schema`

Button label:

- `Tenant Schema ve Demo Seed Kur`

## Behavior

The installer:

1. Connects to the MySQL server with the DB credentials entered in the form.
2. Checks if the tenant database exists.
3. Creates the tenant database if it does not exist and the DB user has permission.
4. Connects to the tenant database.
5. Applies active tenant migrations.
6. Ensures tenant user access columns exist.
7. Seeds the default demo site skeleton.

## Active Tenant Migrations

- `001_tenant_schema.sql`
- `077_menu_mega_foundation.sql`

The tenant user access proposal is handled in PHP as safe column checks:

- `users.phone`
- `users.must_change_password`

## Seed Data

The first seed creates or updates:

- Site settings
- Default language
- Default theme
- Home, about and contact pages
- Main menu and menu items
- Demo blocks
- Home page block placements

## Idempotent Rules

The action can be run more than once.

- Tables use `CREATE TABLE IF NOT EXISTS`.
- Settings, pages, blocks, language and theme use upsert logic.
- Menu and page block records are checked before insert.
- Existing data is not deleted.

## Hosting Note

On some hosting accounts the DB user may not have `CREATE DATABASE` permission. In that case the user should create the tenant DB in cPanel first, then run this step again.

## Next Stage

Stage 11 will copy/apply richer full-site demo content and template structure into the tenant database.