database: Add migration support Fairly minor change codewise; add support for creating migrations and run them at the start of the runtime. In this case not a lot of changes happen, only the migrations tracking table is added. The sqlx command line tool is used to manage migrations; invoke `cargo sqlx --help` for more info.

zj
Jul 20, 2021, 7:12 PM
IWM4EE63YXP2B6KHE2UL3CORFZGXMUKLWB43TXYCYABKAFSTA6FQC

Dependencies

  • [2] EIIUUAKG nix: Install and initialize a Postgres DB For a persistance layer, this change introduces postgresql as dependency. The daemon is started when `nix-shell` is invoked. `pg_ctl stop` is not invoked, and this has to be done by a developer. Data is persisted in a tmp directory, which is added to the ignore file.
  • [3] K4JNAJOF database: Connect to postgres on Rocket boot As database I've chosen PostgreSQL, as my personal experience has been good with it. This change allows Rocket to connect to the database on booting the server. It depends on the DATABASE_URL being set, and for now circumvents the Rocket config helpers as it seemed faster to be up and running this way.
  • [4] W3M3C7CC Initial commit This change includes a very small hello world application server written in Rust using Rocket.rs. Managing dependencies is done with Nix as that works well between Linux and Mac for me.

Change contents

  • edit in src/sqlx/mod.rs at line 19
    [3.541]
    [3.541]
    if let Err(e) = sqlx::migrate!("./migrations").run(&pool).await {
    error!("Failed to migrate PG database: {}", e);
    return Err(rocket);
    }
  • edit in shell.nix at line 16
    [2.57]
    [2.57]
    pkgs.sqlx-cli
  • file addition: migrations (d--r------)
    [1.0]
  • file addition: 20210720185911_test_migration.sql (----------)
    [0.199]
    -- Add migration script here
  • replacement in Cargo.toml at line 15
    [3.1853][3.1853:1914]()
    features = [ "runtime-tokio-rustls", "postgres", "migrate" ]
    [3.1853]
    features = [ "runtime-tokio-rustls", "postgres", "macros", "migrate" ]