---
description: "FbExpert system database: tables, versioned migrations, pre-migration backup and diagnostics."
---

# System schema

FbExpert keeps its configuration in a dedicated Firebird database, the **system database**. It holds no business data: only users and permissions, the database registry, backups, imports, projects and audit.

<figure>
  <img src="/images/diagrams/architecture.svg" alt="System database and user databases" />
  <figcaption>The system database is opened by the embedded engine; user databases are opened by their own kit.</figcaption>
</figure>

## Files

| Item | Purpose |
|---|---|
| `DataDirectory/FBEXPERT.FB5` | system database |
| `DataDirectory/system/FBEXPERT.template.fb5` | template used to create a new system database |
| `DataDirectory/runtime/firebird/5.0/` | clean Firebird 5 runtime (without UDR/UDF) |
| `DataDirectory/keys/backup.key` | key for the backup vault |
| `DataDirectory/keys/data-protection/` | keys for cookies and anti-forgery tokens |
| `DataDirectory/system-schema.version` | schema version for which the pre-migration backup was taken |

The embedded runtime is rebuilt automatically if the Firebird kit is replaced (the client fingerprint is recorded in the manifest).

## Main content

| Table | Content |
|---|---|
| `FBEXPERT_USERS` | accounts, role, status, OTP, preferences (language, tab) |
| `FBEXPERT_ACCESS_AUDIT` | log of logins, denials and changes |
| `FBEXPERT_SCHEMA_MIGRATIONS` | history of system schema migrations |
| `FBEXPERT_BACKUPS` | backup catalog (scope, path, status, SHA-256, encryption) |
| `FBEXPERT_IMPORT_JOBS` | persisted import jobs |
| `FBEXPERT_TRANSFORM_TASKS` | transformation tasks (projects) |
| `FBEXPERT_HOME_LAYOUT` | per-user home page layout |
| `FBEXPERT_PROJECT_HOME` | layout shared per project |

The security, project and backup tables are created by their repository (`EnsureSchemaAsync`) if they are missing: this is the safety net for an old database.

## Versioned migrations

Since schema `8.0`, changes go through numbered steps, applied **one transaction per step**:

| Step | Description |
|---|---|
| 1 | system schema foundation |
| 2 | `FBEXPERT_IMPORT_JOBS.PROJECT_ID` + index |
| 3 | `FBEXPERT_TRANSFORM_TASKS.PROJECT_ID` nullable |
| 4 | `FBEXPERT_HOME_LAYOUT` table |
| 5 | `FBEXPERT_PROJECT_HOME` table |

Rules:

- a published step is **never** modified; a new one is added instead;
- additive only: table, column, index, `DROP NOT NULL`; never `DROP COLUMN`;
- each step is idempotent (it checks before acting);
- if a step fails, it is rolled back and the application starts in a **degraded state** with the `/startup-error` page.

Inspect the state:

```sql
SELECT VERSION, DESCRIPTION, APPLIED_AT
  FROM FBEXPERT_SCHEMA_MIGRATIONS
 ORDER BY VERSION;
```

## Pre-migration backup

The embedded engine allows only a single process: `gbak` cannot read the database while the service is running. The backup therefore runs **at startup, before the database is opened**:

- if `system-schema.version` differs from the current version → pre-migration backup;
- otherwise, if there is no recent `.fbk` file (interval `Firebird:BackupIntervalHours`) → periodic backup.

On demand, with the service stopped:

```bash
sudo systemctl stop fbexpert
sudo runuser -u fbexpert -- \
  env HOME=/var/lib/fbexpert XDG_DATA_HOME=/var/lib/fbexpert/.local/share \
  /opt/fbexpert/FbExpert.Blazor --backup-system
sudo systemctl start fbexpert
```

Files produced outside a session are imported into the catalog and encrypted at the next startup.

## Diagnostics

| Message | Cause |
|---|---|
| `FBEXPERT_… : schéma non vérifiable` | table missing or migration interrupted |
| `Install incomplete…` | the kit's security database is not initialized |
| `Database already opened with engine instance` | a second process on the embedded database (service still running) |
| detailed `/startup-error` | runtime or kit missing, permissions denied |

Tools: `FbExpert.Blazor --check-password <user>`, `--backup-system`, `--version`, and the `/startup-error` page.
