-
Notifications
You must be signed in to change notification settings - Fork 125
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
Improve poor filename filtering feedback to user #252
base: main
Are you sure you want to change the base?
Conversation
2c9a8df
to
f48a87c
Compare
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.
Hi, and thanks for this! This is great work, only some minor nitpicks to address.
refinery_core/src/runner.rs
Outdated
@@ -11,9 +11,9 @@ use crate::traits::DEFAULT_MIGRATION_TABLE_NAME; | |||
use crate::{AsyncMigrate, Error, Migrate}; | |||
use std::fmt::Formatter; | |||
|
|||
// regex used to match file names | |||
// regex used to preliminary match migration semantics from filenames |
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.
// regex used to preliminary match migration semantics from filenames | |
// Regex used to preliminary match migration semantics from filenames. |
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.
Applied.
refinery_core/src/util.rs
Outdated
@@ -44,15 +40,12 @@ pub fn find_migration_files( | |||
.into_iter() | |||
.filter_map(Result::ok) | |||
.map(DirEntry::into_path) | |||
// filter by migration file regex | |||
// filter by migration type encoded in file extension |
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.
// filter by migration type encoded in file extension | |
// Filter by migration type encoded in file extension. |
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.
Applied.
refinery_core/src/error.rs
Outdated
@@ -43,8 +43,8 @@ impl std::error::Error for Error { | |||
#[derive(Debug, TError)] | |||
pub enum Kind { | |||
/// An Error from an invalid file name migration | |||
#[error("migration name must be in the format V{{number}}__{{name}}")] | |||
InvalidName, | |||
#[error("migration filename must be in the format V{{number}}__{{name}}.rq|sql")] |
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.
#[error("migration filename must be in the format V{{number}}__{{name}}.rq|sql")] | |
#[error("migration filename must be in the format V{{number}}__{{name}}.rs|sql")] |
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.
Thanks, applied.
refinery_core/src/runner.rs
Outdated
@@ -11,9 +11,10 @@ use crate::traits::DEFAULT_MIGRATION_TABLE_NAME; | |||
use crate::{AsyncMigrate, Error, Migrate}; | |||
use std::fmt::Formatter; | |||
|
|||
// regex used to preliminary match migration semantics from filenames | |||
// regex matching migration semantics for filenames |
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.
// regex matching migration semantics for filenames | |
// Regex matching migration semantics for filenames. |
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.
Applied.
refinery_cli/src/migrate.rs
Outdated
.with_context(|| format!("could not read migration file name {}", path.display()))?; | ||
let migration = Migration::unapplied(&filename, &sql).with_context(|| { | ||
format!( | ||
"Could not create new unapplied migration with filename {}", |
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.
do we want to mention to the user that we are creating an unapplied Migration
? I'd say it can be a little confusing as it's giving internal information while the user should only care if the file could or could not be read wdyt?
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.
Yes you are right, I changed the message.
f48a87c
to
551d207
Compare
* refinery_cli will silently skip filenames like "V1__first.base.rs" or "V2__second-base.rs" without any logging/feedback to the user * user should be made aware what exactly is wrong with his filenames * refinery will allow filenames like "V1.5__first.base.rs" with decimal version numbers and will try to convert them into integers. * refinery's database table stores versions as integers
* Feeds nice error messages to the user. * Before the change runner would not have a chance to inspect the formatting of input name.
* including file's extension
551d207
to
e017426
Compare
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.
Sorry Łuksaz, just one more thing. Btw please don't force push as I lose context of which files I have already reviewed.
pub fn file_match_re() -> Regex { | ||
Regex::new(r"^([U|V])(\d+(?:\.\d+)?)__(\w+)").unwrap() | ||
Regex::new(r"^(?P<type>[^_])(?P<version>[^_]+)__(?P<name>.+)(?P<extension>\.(sql|rs))$") |
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.
I'd rather here we still only capture U|V
to not raise errors for other files in the path, btw why did you change the version from d+
?
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.
Hi @jxs ,
not raise errors for other files in the path
is it likely at all that someone uses filenames with two consecutive underscores in a project?
If the pattern would not search for __
, then I would leave V|U
. Then the regex would need to accept both lower and upper cases letters. But it does match on __
, so I find the checking of the version outside of regex better.
why did you change the version from d+
to output a better error to the user.
Additionally now fraction version are not allowed. For example, before the change, the filename V1.1__add.rs
would have a match and the version would be 1.1
which is not supported by the database struct.
Filtering filenames with regex has some drawbacks: