artcraft/_docs/old/old_docs/cheat_sheet/migrations.md

934 B

Migrations guide

Diesel Migrations

To run pending migrations, execute the following:

diesel migration run

To revert the last 3 migrations:

diesel migration revert -n 3

To reset the entire database (drop, migrate), run:

diesel database reset

Server Query Codegen

We use SQLx instead of Diesel in the production server. It's typesafe SQL instead of an ORM like Diesel.

SQLx connects to a database to derive type information, but obviously cannot do this for builds in CI. In order to cache the types, we build and check in a cache file (necessary for builds):

SQLX_OFFLINE=true cargo sqlx prepare

Now that we have multiple binaries, it's required to include all the queries in the main binary so we can generate the cached queries as a single target. That's then executed with:

SQLX_OFFLINE=true cargo sqlx prepare -- --bin storyteller-web