# Design a QBCore data migration script

A safe script is specific to a documented source schema and an exact target commit. Generate it only after comparing your database with SQL shipped by the target repositories.

## Requirements

- Idempotent or guarded operations
- Explicit transaction boundaries where supported
- Row counts and rejected-row reporting
- No destructive drop until rollback retention expires
- Dry-run mode for transformations
- Backup identifier and source/target commit recorded in the log

## Execution sequence

1. Restore a production-shaped backup into staging.
2. Run precondition queries and capture row counts.
3. Apply schema additions before data transformation.
4. Transform a bounded batch and validate application behavior.
5. Complete the migration, then compare counts and constraints.
6. Run the first-boot and domain smoke tests.
7. Prove rollback using the backup, not an untested reverse script.

The current baseline schema is visible in [qb-core/qbcore.sql](https://github.com/qbcore-fivem/qb-core/blob/main/qbcore.sql); other resources can ship their own SQL.
