pub struct MigrationManager { /* private fields */ }
Expand description
Migration manager for handling database schema changes
The central component for managing database migrations. Handles initialization, execution, and tracking of schema changes.
§Examples
use libsql_orm::{MigrationManager, Database};
async fn setup_migrations(db: Database) -> Result<(), Error> {
let manager = MigrationManager::new(db);
// Initialize migration tracking
manager.init().await?;
// Get migration status
let executed = manager.get_executed_migrations().await?;
let pending = manager.get_pending_migrations().await?;
println!("Executed: {}, Pending: {}", executed.len(), pending.len());
Ok(())
}
Implementations§
Source§impl MigrationManager
impl MigrationManager
Sourcepub fn create_migration(name: &str, sql: &str) -> Migration
pub fn create_migration(name: &str, sql: &str) -> Migration
Create a new migration
Sourcepub async fn get_migrations(&self) -> Result<Vec<Migration>, Error>
pub async fn get_migrations(&self) -> Result<Vec<Migration>, Error>
Get all migrations from the database
Sourcepub async fn execute_migration(
&self,
migration: &Migration,
) -> Result<(), Error>
pub async fn execute_migration( &self, migration: &Migration, ) -> Result<(), Error>
Execute a migration
Sourcepub async fn rollback_migration(&self, migration_id: &str) -> Result<(), Error>
pub async fn rollback_migration(&self, migration_id: &str) -> Result<(), Error>
Rollback a migration
Sourcepub async fn get_pending_migrations(&self) -> Result<Vec<Migration>, Error>
pub async fn get_pending_migrations(&self) -> Result<Vec<Migration>, Error>
Get pending migrations (not yet executed)
Sourcepub async fn get_executed_migrations(&self) -> Result<Vec<Migration>, Error>
pub async fn get_executed_migrations(&self) -> Result<Vec<Migration>, Error>
Get executed migrations
Sourcepub async fn run_migrations(
&self,
migrations: Vec<Migration>,
) -> Result<(), Error>
pub async fn run_migrations( &self, migrations: Vec<Migration>, ) -> Result<(), Error>
Run all pending migrations
Sourcepub async fn create_migration_from_file(
name: &str,
file_path: &str,
) -> Result<Migration, Error>
pub async fn create_migration_from_file( name: &str, file_path: &str, ) -> Result<Migration, Error>
Create a migration from a file
Sourcepub fn generate_migration_name(description: &str) -> String
pub fn generate_migration_name(description: &str) -> String
Generate a migration name from a description
pub fn database(&self) -> &Database
Auto Trait Implementations§
impl Freeze for MigrationManager
impl !RefUnwindSafe for MigrationManager
impl Send for MigrationManager
impl Sync for MigrationManager
impl Unpin for MigrationManager
impl !UnwindSafe for MigrationManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more