macro_rules! include {
() => { ... };
}
Expand description
Includes all migration files discovered by the list
function at compile time.
This macro expands to a static slice of Migration
structs containing
all SQL files found in the migrations directory. The migrations are ordered
alphabetically by filename, so it’s recommended to prefix them with numbers
(e.g., 001_initial.sql
, 002_add_users.sql
).
§Prerequisites
You must call ic_sql_migrate::list()
in your build.rs
file to generate
the migration data that this macro includes.
§Example in ICP Canister
ⓘ
// In your canister lib.rs
use ic_cdk::{init, post_upgrade};
use ic_rusqlite::{with_connection, Connection};
static MIGRATIONS: &[ic_sql_migrate::Migration] = ic_sql_migrate::include!();
fn run_migrations() {
with_connection(|mut conn| {
let conn: &mut Connection = &mut conn;
ic_sql_migrate::sqlite::up(conn, MIGRATIONS).unwrap();
});
}
#[init]
fn init() {
run_migrations();
}
#[post_upgrade]
fn post_upgrade() {
run_migrations();
}