Trait Migration

Source
pub trait Migration
where Self: Sync + Send,
{ // Required methods fn version() -> &'static str where Self: Sized; fn create_query() -> &'static str where Self: Sized; fn database(&self) -> &Database; // Provided methods fn upgrade_query() -> &'static str where Self: Sized { ... } fn rollback_query() -> &'static str where Self: Sized { ... } fn previous() -> Option<Box<dyn Migration>> where Self: Sized { ... } async fn validate_database<'a, C>( &self, connection: &'a C, database: &Database, ) -> Result<MigrationState, Error> where Self: Sized, C: GeekConnection<Connection = C> + 'a { ... } fn validate( migrations: &mut Vec<Box<dyn Migration>>, migration_database: &Database, live_database: &Vec<(String, Vec<TableInfo>)>, ) -> Result<MigrationState, Error> where Self: Sized { ... } async fn create<'a, C>(connection: &'a C) -> Result<(), Error> where Self: Sized, C: GeekConnection<Connection = C> + 'a { ... } async fn upgrade<'a, C>(connection: &'a C) -> Result<(), Error> where Self: Sized, C: GeekConnection<Connection = C> + 'a { ... } async fn rollback<'a, C>(connection: &'a C) -> Result<(), Error> where Self: Sized, C: GeekConnection<Connection = C> + 'a { ... } async fn migrate<'a, C>(connection: &'a C) -> Result<(), Error> where Self: Sized, C: GeekConnection<Connection = C> + 'a { ... } }
Expand description

Migration trait

Required Methods§

Source

fn version() -> &'static str
where Self: Sized,

Get the version of the migration

Source

fn create_query() -> &'static str
where Self: Sized,

Get the create query

Source

fn database(&self) -> &Database

Get the database schema

Provided Methods§

Source

fn upgrade_query() -> &'static str
where Self: Sized,

Get the upgrade query

Source

fn rollback_query() -> &'static str
where Self: Sized,

Get the rollback query

Source

fn previous() -> Option<Box<dyn Migration>>
where Self: Sized,

Get the previous database if it exists

Source

async fn validate_database<'a, C>( &self, connection: &'a C, database: &Database, ) -> Result<MigrationState, Error>
where Self: Sized, C: GeekConnection<Connection = C> + 'a,

This function is called to validate the database schema by comparing the live database to the migration database

Source

fn validate( migrations: &mut Vec<Box<dyn Migration>>, migration_database: &Database, live_database: &Vec<(String, Vec<TableInfo>)>, ) -> Result<MigrationState, Error>
where Self: Sized,

Validate the database schema is correct

Source

async fn create<'a, C>(connection: &'a C) -> Result<(), Error>
where Self: Sized, C: GeekConnection<Connection = C> + 'a,

Create the database if it does not exist

Assumes the database is already created but the tables are not

Source

async fn upgrade<'a, C>(connection: &'a C) -> Result<(), Error>
where Self: Sized, C: GeekConnection<Connection = C> + 'a,

Migrate the previos database to the current version

Source

async fn rollback<'a, C>(connection: &'a C) -> Result<(), Error>
where Self: Sized, C: GeekConnection<Connection = C> + 'a,

Downgrade the database to the previous version

Source

async fn migrate<'a, C>(connection: &'a C) -> Result<(), Error>
where Self: Sized, C: GeekConnection<Connection = C> + 'a,

Migrating data from one version to another

Implementors§