-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding barrel
feature
#1573
Adding barrel
feature
#1573
Changes from 25 commits
7f841e5
5739101
f258e56
439620e
4cd7b79
25267f9
9b95920
b4bacf4
67fd97e
4f64f21
e46570d
7f4b65b
487404d
a4cb6dd
f0b153f
1f74f90
c4cee3d
c62e6ea
1aa7232
5f4b402
7da5525
1887333
bac30c0
1aaaf5c
a3275f9
6f374e3
e0e97d6
ed2b8a1
b650a55
bc1607c
a27d1d4
4fdfb3d
8c025b6
feed83f
df26c2b
4e2668b
3c992c4
8468bc2
9a9b01b
56234c8
daa998d
a14287b
3101a99
d5330d2
a7cd615
9dd24cf
8960d05
cfc453d
2fc3637
6b902d4
051661f
b4a2b3b
5029b64
4eebacf
03e0248
b7bd404
3bb1233
a5d375d
e8bd6f5
6693e87
13e8caa
0dc23b8
8595def
f84f394
c1a217f
5168672
2086b99
ed20737
ef98ddc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
use diesel::result; | ||
//! Error types that represent migration errors. | ||
//! These are split into multiple segments, depending on | ||
//! where in the migration process an error occurs. | ||
|
||
use std::convert::From; | ||
use std::{fmt, io}; | ||
use std::path::PathBuf; | ||
use std::error::Error; | ||
|
||
use result; | ||
|
||
/// Errors that occur while preparing to run migrations | ||
#[derive(Debug)] | ||
pub enum MigrationError { | ||
/// The migration directory wasn't found | ||
MigrationDirectoryNotFound, | ||
/// Provided migration was in an unknown format | ||
UnknownMigrationFormat(PathBuf), | ||
/// General system IO error | ||
IoError(io::Error), | ||
/// Provided migration had an incompatible version number | ||
UnknownMigrationVersion(String), | ||
/// No migrations had to be/ could be run | ||
NoMigrationRun, | ||
} | ||
|
||
|
@@ -63,11 +73,15 @@ impl From<io::Error> for MigrationError { | |
} | ||
} | ||
|
||
/// Errors that occur while running migrations | ||
#[derive(Debug, PartialEq)] | ||
#[cfg_attr(feature = "clippy", allow(enum_variant_names))] | ||
pub enum RunMigrationsError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably make this non-exhaustive now that it's public, right? |
||
/// A general migration error occured | ||
MigrationError(MigrationError), | ||
/// The provided migration included an invalid query | ||
QueryError(result::Error), | ||
/// The provided migration was empty | ||
EmptyMigration, | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! Representation of migrations | ||
|
||
pub mod errors; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be public or is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be public, it's re-exported from diesel_migrations |
||
pub use self::errors::*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks super dangerous adds a hard to see amount of items to our public API! I does in fact only expose |
||
|
||
use connection::SimpleConnection; | ||
use std::path::Path; | ||
|
||
/// Represents a migration that interacts with diesel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noticed that's it's super hard to see what's up with SimpleConnection – it's not public and the only way aside from reading the code where you can find it is in the docs for Connection (which it's a supertrait of). Not something for this PR to fix but seemed worth commenting on. |
||
pub trait Migration { | ||
/// Get the migration version | ||
fn version(&self) -> &str; | ||
/// Apply this migration | ||
fn run(&self, conn: &SimpleConnection) -> Result<(), RunMigrationsError>; | ||
/// Revert this migration | ||
fn revert(&self, conn: &SimpleConnection) -> Result<(), RunMigrationsError>; | ||
/// Get the migration file path | ||
fn file_path(&self) -> Option<&Path> { | ||
None | ||
} | ||
} | ||
|
||
impl Migration for Box<Migration> { | ||
fn version(&self) -> &str { | ||
(&**self).version() | ||
} | ||
|
||
fn run(&self, conn: &SimpleConnection) -> Result<(), RunMigrationsError> { | ||
(&**self).run(conn) | ||
} | ||
|
||
fn revert(&self, conn: &SimpleConnection) -> Result<(), RunMigrationsError> { | ||
(&**self).revert(conn) | ||
} | ||
fn file_path(&self) -> Option<&Path> { | ||
(&**self).file_path() | ||
} | ||
} | ||
|
||
impl<'a> Migration for &'a Migration { | ||
fn version(&self) -> &str { | ||
(&**self).version() | ||
} | ||
|
||
fn run(&self, conn: &SimpleConnection) -> Result<(), RunMigrationsError> { | ||
(&**self).run(conn) | ||
} | ||
|
||
fn revert(&self, conn: &SimpleConnection) -> Result<(), RunMigrationsError> { | ||
(&**self).revert(conn) | ||
} | ||
fn file_path(&self) -> Option<&Path> { | ||
(&**self).file_path() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,15 @@ pub fn build_cli() -> App<'static, 'static> { | |
for most use cases.", | ||
) | ||
.takes_value(true), | ||
) | ||
.arg( | ||
Arg::with_name("TYPE") | ||
.long("type") | ||
.short("t") | ||
.possible_values(&["sql", "barrel"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd either go with "raw" + "barrel", or "sql" + "rust". |
||
.default_value("sql") | ||
.takes_value(true) | ||
.help("Specify the migration type."), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add |
||
), | ||
) | ||
.setting(AppSettings::SubcommandRequiredElseHelp); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably make this non-exhaustive now that it's public, right?