pub fn list(migrations_dir_name: Option<&str>) -> Result<()>Expand description
Discovers and lists all SQL migration files for inclusion at compile time.
This function should be called in build.rs to generate code that embeds
all migration files into the binary. It scans the specified directory for
.sql files and generates Rust code to include them.
The function will:
- Look for SQL files in the specified directory (relative to
Cargo.toml) - Sort them alphabetically by filename
- Generate code that includes their content at compile time
- Set up cargo to rebuild when migration files change
§Arguments
migrations_dir_name- Optional custom directory name (defaults to “migrations”)
§Example in build.rs
// In your canister's build.rs file
fn main() {
// Use default "migrations" directory
ic_sql_migrate::list(None).unwrap();
// Or specify a custom directory relative to Cargo.toml
ic_sql_migrate::list(Some("migrations")).unwrap();
}§File Naming Convention
Migration files should be named with a sortable prefix to ensure correct execution order:
001_initial_schema.sql002_add_users_table.sql003_add_indexes.sql
§Errors
Returns an I/O error if:
- The output directory (
OUT_DIR) cannot be written to - File system operations fail
- Environment variables
CARGO_MANIFEST_DIRorOUT_DIRare not set