Skip to content

Improve poor filename filtering feedback to user #252

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions refinery/tests/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod mysql {
.unwrap();

let migration3 = Migration::unapplied(
"V3__add_brand_to_cars_table",
"V3__add_brand_to_cars_table.sql",
include_str!("./migrations/V3/V3__add_brand_to_cars_table.sql"),
)
.unwrap();
Expand All @@ -57,7 +57,7 @@ mod mysql {
.unwrap();

let migration5 = Migration::unapplied(
"V5__add_year_field_to_cars",
"V5__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -471,7 +471,7 @@ mod mysql {
embedded::migrations::runner().run(&mut conn).unwrap();

let migration = Migration::unapplied(
"V4__add_year_field_to_cars",
"V4__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -507,7 +507,7 @@ mod mysql {
embedded::migrations::runner().run(&mut conn).unwrap();

let migration = Migration::unapplied(
"V2__add_year_field_to_cars",
"V2__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -544,7 +544,7 @@ mod mysql {
missing::migrations::runner().run(&mut conn).unwrap();

let migration1 = Migration::unapplied(
"V1__initial",
"V1__initial.sql",
concat!(
"CREATE TABLE persons (",
"id int,",
Expand All @@ -556,7 +556,7 @@ mod mysql {
.unwrap();

let migration2 = Migration::unapplied(
"V2__add_cars_table",
"V2__add_cars_table.sql",
include_str!("./migrations_missing/V2__add_cars_table.sql"),
)
.unwrap();
Expand Down
12 changes: 6 additions & 6 deletions refinery/tests/mysql_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod mysql_async {
.unwrap();

let migration3 = Migration::unapplied(
"V3__add_brand_to_cars_table",
"V3__add_brand_to_cars_table.sql",
include_str!("./migrations/V3/V3__add_brand_to_cars_table.sql"),
)
.unwrap();
Expand All @@ -41,7 +41,7 @@ mod mysql_async {
.unwrap();

let migration5 = Migration::unapplied(
"V5__add_year_field_to_cars",
"V5__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -481,7 +481,7 @@ mod mysql_async {
.unwrap();

let migration = Migration::unapplied(
"V4__add_year_field_to_cars",
"V4__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -526,7 +526,7 @@ mod mysql_async {
.unwrap();

let migration = Migration::unapplied(
"V2__add_year_field_to_cars",
"V2__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -567,7 +567,7 @@ mod mysql_async {
.unwrap();

let migration1 = Migration::unapplied(
"V1__initial",
"V1__initial.sql",
concat!(
"CREATE TABLE persons (",
"id int,",
Expand All @@ -579,7 +579,7 @@ mod mysql_async {
.unwrap();

let migration2 = Migration::unapplied(
"V2__add_cars_table",
"V2__add_cars_table.sql",
include_str!("./migrations_missing/V2__add_cars_table.sql"),
)
.unwrap();
Expand Down
12 changes: 6 additions & 6 deletions refinery/tests/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod postgres {
.unwrap();

let migration3 = Migration::unapplied(
"V3__add_brand_to_cars_table",
"V3__add_brand_to_cars_table.sql",
include_str!("./migrations/V3/V3__add_brand_to_cars_table.sql"),
)
.unwrap();
Expand All @@ -56,7 +56,7 @@ mod postgres {
.unwrap();

let migration5 = Migration::unapplied(
"V5__add_year_field_to_cars",
"V5__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -460,7 +460,7 @@ mod postgres {
embedded::migrations::runner().run(&mut client).unwrap();

let migration = Migration::unapplied(
"V4__add_year_field_to_cars",
"V4__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -494,7 +494,7 @@ mod postgres {
embedded::migrations::runner().run(&mut client).unwrap();

let migration = Migration::unapplied(
"V2__add_year_field_to_cars",
"V2__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -529,7 +529,7 @@ mod postgres {
missing::migrations::runner().run(&mut client).unwrap();

let migration1 = Migration::unapplied(
"V1__initial",
"V1__initial.sql",
concat!(
"CREATE TABLE persons (",
"id int,",
Expand All @@ -541,7 +541,7 @@ mod postgres {
.unwrap();

let migration2 = Migration::unapplied(
"V2__add_cars_table",
"V2__add_cars_table.sql",
include_str!("./migrations_missing/V2__add_cars_table.sql"),
)
.unwrap();
Expand Down
12 changes: 6 additions & 6 deletions refinery/tests/rusqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod rusqlite {
.unwrap();

let migration3 = Migration::unapplied(
"V3__add_brand_to_cars_table",
"V3__add_brand_to_cars_table.sql",
include_str!("./migrations/V3/V3__add_brand_to_cars_table.sql"),
)
.unwrap();
Expand All @@ -72,7 +72,7 @@ mod rusqlite {
.unwrap();

let migration5 = Migration::unapplied(
"V5__add_year_field_to_cars",
"V5__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -408,7 +408,7 @@ mod rusqlite {
embedded::migrations::runner().run(&mut conn).unwrap();

let migration = Migration::unapplied(
"V4__add_year_field_to_cars",
"V4__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -439,7 +439,7 @@ mod rusqlite {
embedded::migrations::runner().run(&mut conn).unwrap();

let migration = Migration::unapplied(
"V2__add_year_field_to_cars",
"V2__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -471,7 +471,7 @@ mod rusqlite {
missing::migrations::runner().run(&mut conn).unwrap();

let migration1 = Migration::unapplied(
"V1__initial",
"V1__initial.sql",
concat!(
"CREATE TABLE persons (",
"id int,",
Expand All @@ -483,7 +483,7 @@ mod rusqlite {
.unwrap();

let migration2 = Migration::unapplied(
"V2__add_cars_table",
"V2__add_cars_table.sql",
include_str!("./migrations_missing/V2__add_cars_table.sql"),
)
.unwrap();
Expand Down
12 changes: 6 additions & 6 deletions refinery/tests/tiberius.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod tiberius {
.unwrap();

let migration3 = Migration::unapplied(
"V3__add_brand_to_cars_table",
"V3__add_brand_to_cars_table.sql",
include_str!("./migrations/V3/V3__add_brand_to_cars_table.sql"),
)
.unwrap();
Expand All @@ -44,7 +44,7 @@ mod tiberius {
.unwrap();

let migration5 = Migration::unapplied(
"V5__add_year_field_to_cars",
"V5__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -126,7 +126,7 @@ mod tiberius {
.unwrap();

let migration = Migration::unapplied(
"V4__add_year_field_to_cars",
"V4__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -177,7 +177,7 @@ mod tiberius {
.unwrap();

let migration = Migration::unapplied(
"V2__add_year_field_to_cars",
"V2__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -229,7 +229,7 @@ mod tiberius {
.unwrap();

let migration1 = Migration::unapplied(
"V1__initial",
"V1__initial.sql",
concat!(
"CREATE TABLE persons (",
"id int,",
Expand All @@ -241,7 +241,7 @@ mod tiberius {
.unwrap();

let migration2 = Migration::unapplied(
"V2__add_cars_table",
"V2__add_cars_table.sql",
include_str!("./migrations_missing/V2__add_cars_table.sql"),
)
.unwrap();
Expand Down
12 changes: 6 additions & 6 deletions refinery/tests/tokio_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod tokio_postgres {
.unwrap();

let migration3 = Migration::unapplied(
"V3__add_brand_to_cars_table",
"V3__add_brand_to_cars_table.sql",
include_str!("./migrations/V3/V3__add_brand_to_cars_table.sql"),
)
.unwrap();
Expand All @@ -41,7 +41,7 @@ mod tokio_postgres {
.unwrap();

let migration5 = Migration::unapplied(
"V5__add_year_field_to_cars",
"V5__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -619,7 +619,7 @@ mod tokio_postgres {
.unwrap();

let migration = Migration::unapplied(
"V4__add_year_field_to_cars",
"V4__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -664,7 +664,7 @@ mod tokio_postgres {
.unwrap();

let migration = Migration::unapplied(
"V2__add_year_field_to_cars",
"V2__add_year_field_to_cars.sql",
"ALTER TABLE cars ADD year INTEGER;",
)
.unwrap();
Expand Down Expand Up @@ -711,7 +711,7 @@ mod tokio_postgres {
.unwrap();

let migration1 = Migration::unapplied(
"V1__initial",
"V1__initial.sql",
concat!(
"CREATE TABLE persons (",
"id int,",
Expand All @@ -723,7 +723,7 @@ mod tokio_postgres {
.unwrap();

let migration2 = Migration::unapplied(
"V2__add_cars_table",
"V2__add_cars_table.sql",
include_str!("./migrations_missing/V2__add_cars_table.sql"),
)
.unwrap();
Expand Down
12 changes: 8 additions & 4 deletions refinery_cli/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ fn run_migrations(
let mut migrations = Vec::new();
for path in migration_files_path {
let sql = std::fs::read_to_string(path.as_path())
.with_context(|| format!("could not read migration file name {}", path.display()))?;
.with_context(|| format!("Could not read contents of file {}", path.display()))?;

//safe to call unwrap as find_migration_filenames returns canonical paths
let filename = path
.file_stem()
.file_name()
.and_then(|file| file.to_os_string().into_string().ok())
.unwrap();

let migration = Migration::unapplied(&filename, &sql)
.with_context(|| format!("could not read migration file name {}", path.display()))?;
let migration = Migration::unapplied(&filename, &sql).with_context(|| {
format!(
"Could not create new migration from contents of file {}",
path.display()
)
})?;
migrations.push(migration);
}
let mut config = config(config_location, env_var_opt)?;
Expand Down
7 changes: 5 additions & 2 deletions refinery_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ 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}}.rs|sql")]
InvalidFilename,
/// An Error from an invalid version on a file name migration
#[error("migration version must be a valid integer")]
InvalidVersion,
/// An Error from an invalid version type on a file name migration
#[error("migration version type must be either the V or U character.")]
InvalidType,
/// An Error from a repeated version, migration version numbers must be unique
#[error("migration {0} is repeated, migration versions must be unique")]
RepeatedVersion(Migration),
Expand Down
Loading