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
impl FileBasedMigrations
Sourcepub fn from_path(path: impl AsRef<Path>) -> Result<Self, MigrationError>
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
Sourcepub fn find_migrations_directory() -> Result<Self, MigrationError>
pub fn find_migrations_directory() -> Result<Self, MigrationError>
Create a new file based migration source by searching the migration directory
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
Sourcepub fn find_migrations_directory_in_path(
path: impl AsRef<Path>,
) -> Result<Self, MigrationError>
pub fn find_migrations_directory_in_path( path: impl AsRef<Path>, ) -> Result<Self, MigrationError>
Create a new file based migration source by searching a given 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
impl Clone for FileBasedMigrations
Source§fn clone(&self) -> FileBasedMigrations
fn clone(&self) -> FileBasedMigrations
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<DB: Backend> MigrationSource<DB> for FileBasedMigrations
impl<DB: Backend> MigrationSource<DB> for FileBasedMigrations
Auto Trait Implementations§
impl Freeze for FileBasedMigrations
impl RefUnwindSafe for FileBasedMigrations
impl Send for FileBasedMigrations
impl Sync for FileBasedMigrations
impl Unpin for FileBasedMigrations
impl UnwindSafe for FileBasedMigrations
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self
to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self
to an expression for Diesel’s query builder. Read more