diesel/migration/
mod.rs

1//! Representation of migrations
2
3mod errors;
4pub use self::errors::{MigrationError, RunMigrationsError};
5
6use connection::SimpleConnection;
7use std::path::Path;
8
9/// Represents a migration that interacts with diesel
10pub trait Migration {
11    /// Get the migration version
12    fn version(&self) -> &str;
13    /// Apply this migration
14    fn run(&self, conn: &dyn SimpleConnection) -> Result<(), RunMigrationsError>;
15    /// Revert this migration
16    fn revert(&self, conn: &dyn SimpleConnection) -> Result<(), RunMigrationsError>;
17    /// Get the migration file path
18    fn file_path(&self) -> Option<&Path> {
19        None
20    }
21}
22
23impl Migration for Box<dyn Migration> {
24    fn version(&self) -> &str {
25        (&**self).version()
26    }
27
28    fn run(&self, conn: &dyn SimpleConnection) -> Result<(), RunMigrationsError> {
29        (&**self).run(conn)
30    }
31
32    fn revert(&self, conn: &dyn SimpleConnection) -> Result<(), RunMigrationsError> {
33        (&**self).revert(conn)
34    }
35    fn file_path(&self) -> Option<&Path> {
36        (&**self).file_path()
37    }
38}
39
40impl<'a> Migration for &'a dyn Migration {
41    fn version(&self) -> &str {
42        (&**self).version()
43    }
44
45    fn run(&self, conn: &dyn SimpleConnection) -> Result<(), RunMigrationsError> {
46        (&**self).run(conn)
47    }
48
49    fn revert(&self, conn: &dyn SimpleConnection) -> Result<(), RunMigrationsError> {
50        (&**self).revert(conn)
51    }
52    fn file_path(&self) -> Option<&Path> {
53        (&**self).file_path()
54    }
55}