Skip to main content

new

Function new 

Source
pub fn new<DB: Database>() -> Result<Migrator<DB>, Error>
Expand description

Creates a new Migrator instance with all Evento migrations registered.

The migrator is generic over the database type and works with SQLite, MySQL, and PostgreSQL when the corresponding feature is enabled.

§Example

use sqlx_migrator::{Migrate, Plan};

// For SQLite
let migrator = evento_sql_migrator::new::<sqlx::Sqlite>()?;

// For PostgreSQL
let migrator = evento_sql_migrator::new::<sqlx::Postgres>()?;

// For MySQL
let migrator = evento_sql_migrator::new::<sqlx::MySql>()?;

// Run migrations
migrator.run(&mut *conn, &Plan::apply_all()).await?;

§Errors

Returns an error if migration registration fails.