Skip to main content

sea_orm_migration/
lib.rs

1#[cfg(feature = "cli")]
2pub mod cli;
3pub mod connection;
4pub mod manager;
5pub mod migrator;
6pub mod prelude;
7pub mod schema;
8pub mod seaql_migrations;
9pub mod util;
10
11pub use connection::*;
12pub use manager::*;
13pub use migrator::*;
14
15pub use async_trait;
16pub use sea_orm;
17pub use sea_orm::DbErr;
18pub use sea_orm::sea_query;
19
20pub trait MigrationName {
21    fn name(&self) -> &str;
22}
23
24/// The migration definition
25#[async_trait::async_trait]
26pub trait MigrationTrait: MigrationName + Send + Sync {
27    /// Define actions to perform when applying the migration
28    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr>;
29
30    /// Define actions to perform when rolling back the migration
31    async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
32        Err(DbErr::Migration("We Don't Do That Here".to_owned()))
33    }
34
35    /// Control whether this migration runs inside a transaction.
36    ///
37    /// - `None` (default): follow backend convention (Postgres = transaction, MySQL/SQLite = no transaction)
38    /// - `Some(true)`: force wrapping in a transaction on any backend
39    /// - `Some(false)`: disable automatic transaction wrapping (use `manager.begin()` for manual control)
40    fn use_transaction(&self) -> Option<bool> {
41        None
42    }
43}