Skip to content

Making changes

A few rules keep the codebase consistent. For where new code belongs, see Architecture.

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.

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.

Wyrm supports Postgres for the server and SQLite for the desktop app, so every schema change needs two migrations:

  • migrations/ for Postgres
  • migrations_sqlite/ for SQLite

Create them with the diesel CLI, built with both backends:

Terminal window
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:

Terminal window
diesel migration generate <description>
diesel migration run --database-url postgres://wyrm:wyrm@localhost/wyrm

Use the same database URL as in config/wyrm.toml.

Generate the SQLite migration, write its SQL, then regenerate crates/database/src/schema_sqlite.rs:

Terminal window
diesel migration generate <description> --config-file diesel-sqlite.toml
./scripts/gen-sqlite-schema.sh

Commit both migrations and both schema files. Don’t edit the schema files by hand.

Run cargo test and ./scripts/lint.sh, see Development.