1.6 KiB
1.6 KiB
paths
| paths | ||
|---|---|---|
|
Database rules
- PostgreSQL. Schema changes are plain SQL files in
migrations/, namedNN_short_name.sqlwith the next two-digit number. They are embedded withsqlx::migrate!()and applied automatically at server start. - Never edit or rename a migration that has been committed — sqlx stores a checksum per version and existing installations will refuse to start. Fix things with a new migration.
- Migrations must work on a database that already holds production data: add columns as nullable or with a
DEFAULT, backfill in the same file if needed. migrate!()reads the directory at compile time and there is nobuild.rs, so cargo may not notice a new.sqlfile. If a new migration doesn't run, touchsrc/main.rsand rebuild.- Default rows (admin user, company, message templates, appearance) are seeded in Rust at startup (
create_admin,check_*), not in migrations. A new singleton table ormessage_typevalue needs the matching seeding code. - Keep the schema and
src/backend/data.rsin sync in the same change: column names = struct field names (SELECT *+FromRow), Postgres enum labels = Rust variant names. A new enum value needsALTER TYPE ... ADD VALUEplus the Rust variant, itsDisplayarm and, formessage_type, the list incheck_messages. - Naming: singular snake_case tables (
reservation_sum,closing_time),id SERIAL PRIMARY KEY,"user"always quoted, money asNUMERIC(9, 2)↔rust_decimal::Decimal, dates/times asDATE/TIME↔chrono::NaiveDate/NaiveTime.