#rocket-web #rocket #sqlx #web #web-framework

rocket_sqlx_migrator

This crate works with the rocket web framework and rocket_db_pools to automatically run migrations on startup using a faring and some generic type magic

1 unstable release

0.2.0 Jun 22, 2024

#2196 in Database interfaces

Custom license

5KB

rocket_sqlx_migrator

Use this crate with the rocket web framework and rocket_db_pools to automatically run migrations on startup using a faring and some generic type magic.

All you have to do is define a db type using rocket_db_pools:

#[derive(Database)]
#[database("times")]
struct MainDB(Pool<Sqlite>);

and then register it to the migrator using:

#[launch]
fn rocket() -> _ {
    rocket::build()
        .attach(MainDB::init())
        .attach(SqlxMigrator::<MainDB>::migrate())
}

Note: You can't currently change the migrations folder away from the default, found at ./migrations.

FWI: I'm looking for some help to create some tests!

Note2myself: use cargo readme to generate readme


lib.rs:

Use this crate with the rocket web framework and rocket_db_pools to automatically run migrations on startup using a faring and some generic type magic.

All you have to do is define a db type using rocket_db_pools:

#[derive(Database)]
#[database("times")]
struct MainDB(Pool<Sqlite>);

and then register it to the migrator using:

#[launch]
fn rocket() -> _ {
    rocket::build()
        .attach(MainDB::init())
        .attach(SqlxMigrator::<MainDB>::migrate())
}

Note: You can't currently change the migrations folder away from the default, found at ./migrations.

FWI: I'm looking for some help to create some tests!

Note2myself: use cargo readme to generate readme

Dependencies

~20–52MB
~1M SLoC