Struct MigrationManager

Source
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

Source

pub fn new(db: Database) -> Self

Create a new migration manager

Source

pub async fn init(&self) -> Result<(), Error>

Initialize the migration table

Source

pub fn create_migration(name: &str, sql: &str) -> Migration

Create a new migration

Source

pub async fn get_migrations(&self) -> Result<Vec<Migration>, Error>

Get all migrations from the database

Source

pub async fn execute_migration( &self, migration: &Migration, ) -> Result<(), Error>

Execute a migration

Source

pub async fn rollback_migration(&self, migration_id: &str) -> Result<(), Error>

Rollback a migration

Source

pub async fn get_pending_migrations(&self) -> Result<Vec<Migration>, Error>

Get pending migrations (not yet executed)

Source

pub async fn get_executed_migrations(&self) -> Result<Vec<Migration>, Error>

Get executed migrations

Source

pub async fn run_migrations( &self, migrations: Vec<Migration>, ) -> Result<(), Error>

Run all pending migrations

Source

pub async fn create_migration_from_file( name: &str, file_path: &str, ) -> Result<Migration, Error>

Create a migration from a file

Source

pub fn generate_migration_name(description: &str) -> String

Generate a migration name from a description

Source

pub fn database(&self) -> &Database

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,