#rusqlite #sqlite #database #migration #user-version


Simple schema migration library for rusqlite using user_version instead of an SQL table to maintain the current schema version

13 releases (3 stable)

1.1.0-alpha.1 Feb 13, 2023
1.0.1 Oct 30, 2022
1.0.0 Mar 27, 2022
0.5.1 Dec 3, 2021
0.2.0 Nov 15, 2020

#50 in Database interfaces

Download history 599/week @ 2023-02-07 630/week @ 2023-02-14 567/week @ 2023-02-21 549/week @ 2023-02-28 670/week @ 2023-03-07 775/week @ 2023-03-14 570/week @ 2023-03-21 663/week @ 2023-03-28 642/week @ 2023-04-04 590/week @ 2023-04-11 832/week @ 2023-04-18 411/week @ 2023-04-25 580/week @ 2023-05-02 798/week @ 2023-05-09 524/week @ 2023-05-16 654/week @ 2023-05-23

2,655 downloads per month
Used in 17 crates (15 directly)


693 lines

Rusqlite Migration

docs.rs Crates.io unsafe forbidden dependency status

Rusqlite Migration is a simple and performant schema migration library for rusqlite.

  • Performance:
    • Fast database opening: to keep track of the current migration state, most tools create one or more tables in the database. These tables require parsing by SQLite and are queried with SQL statements. This library uses the user_version value instead. It’s much lighter as it is just an integer at a fixed offset in the SQLite file.
    • Fast compilation: this crate is very small and does not use macros to define the migrations.
  • Simplicity: this crate strives for simplicity. Just define a set of SQL statements as strings in your Rust code. Add more SQL statements over time as needed. No external CLI required. Additionally, rusqlite_migration works especially well with other small libraries complementing rusqlite, like serde_rusqlite.


Here, we define SQL statements to run with Migrations::new and run these (if necessary) with .to_latest().

use rusqlite::{params, Connection};
use rusqlite_migration::{Migrations, M};

// 1️⃣ Define migrations
let migrations = Migrations::new(vec![
    M::up("CREATE TABLE friend(name TEXT NOT NULL);"),
    // In the future, add more migrations here:
    //M::up("ALTER TABLE friend ADD COLUMN email TEXT;"),

let mut conn = Connection::open_in_memory().unwrap();

// Apply some PRAGMA, often better to do it outside of migrations
conn.pragma_update(None, "journal_mode", &"WAL").unwrap();

// 2️⃣ Update the database schema, atomically
migrations.to_latest(&mut conn).unwrap();

// 3️⃣ Use the database 🥳
conn.execute("INSERT INTO friend (name) VALUES (?1)", params!["John"])

Please see the examples folder for more, in particular:

  • migrations with multiple SQL statements (using for instance r#"…" or include_str!())
  • use of lazy_static
  • migrations to previous versions (downward migrations)

I’ve also made a cheatsheet of SQLite pragma for improved performance and consistency.

Built-in tests

To test that the migrations are working, you can add this in your test module:

fn migrations_test() {


Contributions (documentation or code improvements in particular) are welcome, see contributing!


I would like to thank all the contributors, as well as the authors of the dependencies this crate uses.


~373K SLoC