SurrealDB Migrator
Migrator library for SurrealDB.
Example
Using code for migration scripts
use ;
let db = connect.unwrap;
db.use_ns.use_db.await.unwrap;
let migrations = new;
// Go to the latest version
migrations.to_latest.unwrap;
// Go to a specific version
migrations.to_version.unwrap;
Using files for migration script
The migrations are loaded and stored in the binary. from-directory
feature flags needs to be enabled.
The migration directory pointed to by include_dir!()
must contain
subdirectories in accordance with the given pattern:
{usize id indicating the order}-{convenient migration name}
Those directories must contain at least an up.surql
file containing a valid upward
migration. They can also contain a down.surql
file containing a downward migration.
Example structure
migrations
├── 01-friend_car
│ └── up.surql
├── 02-add_birthday_column
│ └── up.surql
└── 03-add_animal_table
├── down.surql
└── up.surql
use ; // cargo add include_dir
static MIGRATION_DIR: Dir = include_dir!;
let migrations = from_directory.unwrap;
migrations.to_latest.await?;
Surrealdb Compatiblitiy
surrealdb-migrator version | surrealdb version |
---|---|
0.1.8 |
>= 1.5.0 && < 2.x |
0.2.x |
>= 2.0.0 && < 3.x |
LICENSE
Apache License
Acknowledgments
Thanks to rusqlite_migration where the code for surrealdb-migrator is inspired from.