Files
RustBox/migrations/README.md
T
Mateusz Gruszczyński e3e844ef4f
RustBox CI / rustbox (push) Canceled after 0s
v0.1.2
2026-10-31 09:22:42 +01:00

52 lines
2.1 KiB
Markdown

# Database schemas and migrations
RustBox 0.1.2 has one database backend for the whole application:
```text
database_backend = sqlite | mysql | pgsql
session_backend = database | redis
```
When `session_backend = "database"`, sessions live in the same configured SQL database as the application data. `session_backend = "redis"` moves only session persistence to Redis; Redis Sentinel is a Redis discovery option and has no SQL schema.
## Layout
```text
migrations/
├── sqlite/
│ └── schema.sql
├── mysql/
│ └── schema.sql
└── pgsql/
└── schema.sql
```
Every `schema.sql` is the complete schema for that engine. It contains:
- global tables (`sessions`, `rustbox_accounts`), and
- the full account-data baseline at schema version 46.
Account data is isolated inside the selected physical database with a deterministic, collision-checked table prefix derived from the account hash. The `{{p}}` marker in the tenant part of each schema is replaced by RustBox at provisioning time. Sessions are global and therefore are not prefixed.
## Future migrations
The next application schema change is **V047**. A schema-changing release must add the same logical migration for every supported SQL engine, for example:
```text
migrations/sqlite/V047__description.sql
migrations/mysql/V047__description.sql
migrations/pgsql/V047__description.sql
```
Tenant migration SQL uses `{{p}}` for account tables. Register each new migration in the corresponding migration array in `src/db/pool.rs` and keep the version numbers aligned across all three engines. Do not edit `schema.sql` alone for an upgrade that must work on existing installations; update both the baseline and the versioned migration.
Redis and Redis Sentinel do not use SQL migrations.
## Engine notes
- SQLite uses `data_dir/rustbox.sqlite` by default; `database_url` may point to another persistent SQLite file.
- MySQL requires `database_url` and targets MySQL 8.0.13 or newer.
- PostgreSQL requires `database_url`.
- MySQL/PostgreSQL are full application backends, not session-only databases.