Struct diesel_migrations::FileBasedMigrations

source ·
pub struct FileBasedMigrations { /* private fields */ }
Expand description

A migration source based on a migration directory in the file system

A valid migration directory contains a sub folder per migration. Each migration folder contains a up.sql file containing the migration itself and a down.sql file containing the necessary SQL to revert the migration. Additionally each folder can contain a metadata.toml file controlling how the individual migration should be handled by the migration harness.

To embed an existing migration folder into the final binary see embed_migrations!.

§Example

# Directory Structure
- 20151219180527_create_users
    - up.sql
    - down.sql
- 20160107082941_create_posts
    - up.sql
    - down.sql
    - metadata.toml
-- 20151219180527_create_users/up.sql
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  name VARCHAR NOT NULL,
  hair_color VARCHAR
);
-- 20151219180527_create_users/down.sql
DROP TABLE users;
-- 20160107082941_create_posts/up.sql
CREATE TABLE posts (
  id SERIAL PRIMARY KEY,
  user_id INTEGER NOT NULL,
  title VARCHAR NOT NULL,
  body TEXT
);
-- 20160107082941_create_posts/down.sql
DROP TABLE posts;
## 20160107082941_create_posts/metadata.toml

## specifies if a migration is executed inside a
## transaction or not. This configuration is optional
## by default all migrations are run in transactions.
##
## For certain types of migrations, like creating an
## index onto a existing column, it is required
## to set this to false
run_in_transaction = true

Implementations§

source§

impl FileBasedMigrations

source

pub fn from_path(path: impl AsRef<Path>) -> Result<Self, MigrationError>

Create a new file based migration source based on a specific path

This methods fails if the path passed as argument is no valid migration directory

source

pub fn find_migrations_directory() -> Result<Self, MigrationError>

Create a new file based migration source by searching the migration diretcory

This method looks in the current and all parent directories for a folder named migrations

This method fails if no valid migration directory is found

source

pub fn find_migrations_directory_in_path( path: impl AsRef<Path> ) -> Result<Self, MigrationError>

Create a new file based migration source by searching a give path for the migration directory

This method looks in the passed directory and all parent directories for a folder named migrations

This method fails if no valid migration directory is found

Trait Implementations§

source§

impl Clone for FileBasedMigrations

source§

fn clone(&self) -> FileBasedMigrations

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<DB: Backend> MigrationSource<DB> for FileBasedMigrations

source§

fn migrations(&self) -> Result<Vec<Box<dyn Migration<DB>>>>

Get a list of migrations associated with this migration source.

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, 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> IntoSql for T

source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression

Convert &self to an expression for Diesel’s query builder. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V