Making changes
A few rules keep the codebase consistent. For where new code belongs, see Architecture.
Generated TypeScript types
Section titled “Generated TypeScript types”The frontend types in web/src/types/ are generated from Rust structs.
Any struct that derives ts_rs::TS with #[ts(export)] writes its TypeScript
file when you run cargo test.
If you add or change any of those structs, run cargo test and commit the
regenerated files with your change. Don’t edit files in web/src/types/ by
hand, the next cargo test overwrites them.
Errors
Section titled “Errors”Fallible backend code returns WyrmResult<T>, defined in crates/utils, which
wraps WyrmError. Each error maps to an HTTP status and a message in
response_parts() in crates/utils/src/error.rs:
- Errors not listed there become a 500 with a generic “internal server error” body, and the full error is logged.
- Client errors (400, 404, 409 and so on) return the message you write there.
Database and connection pool error text must never reach a response. If a
client needs to see an error, add a WyrmError variant with its own message.
Database migrations
Section titled “Database migrations”Wyrm supports Postgres for the server and SQLite for the desktop app, so every schema change needs two migrations:
migrations/for Postgresmigrations_sqlite/for SQLite
Create them with the diesel CLI, built with both backends:
cargo install diesel_cli --no-default-features --features "postgres sqlite-bundled"Generate the Postgres migration, write up.sql and down.sql, then run it to
regenerate crates/database/src/schema.rs:
diesel migration generate <description>diesel migration run --database-url postgres://wyrm:wyrm@localhost/wyrmUse the same database URL as in config/wyrm.toml.
Generate the SQLite migration, write its SQL, then regenerate
crates/database/src/schema_sqlite.rs:
diesel migration generate <description> --config-file diesel-sqlite.toml./scripts/gen-sqlite-schema.shCommit both migrations and both schema files. Don’t edit the schema files by hand.
Before you push
Section titled “Before you push”Run cargo test and ./scripts/lint.sh, see Development.