15 releases (stable)

2.2.0 May 31, 2024
2.1.0 May 26, 2023
2.0.0 Aug 29, 2022
2.0.0-rc.1 Jul 22, 2022
0.99.0 Nov 28, 2017

#362 in Database interfaces

Download history 64154/week @ 2024-08-02 63328/week @ 2024-08-09 63023/week @ 2024-08-16 64960/week @ 2024-08-23 63070/week @ 2024-08-30 69737/week @ 2024-09-06 69253/week @ 2024-09-13 75414/week @ 2024-09-20 79728/week @ 2024-09-27 78548/week @ 2024-10-04 71505/week @ 2024-10-11 82557/week @ 2024-10-18 83716/week @ 2024-10-25 75445/week @ 2024-11-01 69176/week @ 2024-11-08 76495/week @ 2024-11-15

319,483 downloads per month
Used in 184 crates (130 directly)

MIT/Apache

2MB
36K SLoC

Provides functions for maintaining database schema.

A database migration always provides procedures to update the schema, as well as to revert itself. Diesel's migrations are versioned, and run in order. Diesel also takes care of tracking which migrations have already been run automatically. Your migrations don't need to be idempotent, as Diesel will ensure no migration is run twice unless it has been reverted.

Migrations should be placed in a /migrations directory at the root of your project (the same directory as Cargo.toml). When any of these functions are run, Diesel will search for the migrations directory in the current directory and its parents, stopping when it finds the directory containing Cargo.toml.

Individual migrations should be a folder containing two files, up.sql and down.sql. up.sql will be used to run the migration, while down.sql will be used for reverting it. The folder itself should have the structure {version}_{migration_name}. It is recommended that you use the timestamp of creation for the version.

Migrations can either be run with the CLI or embedded into the compiled application and executed with code, for example right after establishing a database connection. For more information, consult the embed_migrations! macro.

Dependencies

~1–1.6MB
~36K SLoC