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 directroy 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 nessesary SQL to revert the migration.
Additionaly each folder can contain a metadata.toml
file controling 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
-- 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
# specifices 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 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
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 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
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 RefUnwindSafe for FileBasedMigrations
impl Send for FileBasedMigrations
impl Sync for FileBasedMigrations
impl Unpin for FileBasedMigrations
impl UnwindSafe for FileBasedMigrations
Blanket Implementations§
source§impl<T> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
T: SqlType + TypedExpressionType,
fn into_sql<T>(self) -> Self::Expressionwhere Self: AsExpression<T> + Sized, T: SqlType + TypedExpressionType,
self
to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
T: SqlType + TypedExpressionType,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,
&self
to an expression for Diesel’s query builder. Read more