Skip to content

Commit

Permalink
Removal of files option of the cli + dep upgrade + cs (#175)
Browse files Browse the repository at this point in the history
* Removal of files option of the cli + dep upgrade + cs

* Remove the "files" logic

* Oops

Co-authored-by: João Oliveira <[email protected]>
  • Loading branch information
omid and jxs authored Sep 18, 2021
1 parent 8d8e6e2 commit 273eb2f
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 50 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- `include_migration_mods` macro has been removed. Instead of that, use `embed_migrations` macro, and there is no need to have `mod.rs`. [#154](https://github.com/rust-db/refinery/pull/154)

### Removed
- Removal of "files" argument from refinery cli [#174](https://github.com/rust-db/refinery/pull/174)

## [0.6.0] - 2021-07-10
### Changed
- Update mysql to 0.21, [#164](https://github.com/rust-db/refinery/pull/164)
Expand Down
8 changes: 4 additions & 4 deletions refinery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ tiberius = ["refinery-core/tiberius"]
tiberius-config = ["refinery-core/tiberius", "refinery-core/tiberius-config"]

[dependencies]
refinery-core= { version = "0.6.0", path = "../refinery_core" }
refinery-macros= { version = "0.6.0", path = "../refinery_macros" }
refinery-core = { version = "0.6.0", path = "../refinery_core" }
refinery-macros = { version = "0.6.0", path = "../refinery_macros" }

[dev-dependencies]
barrel = { git = "https://github.com/jxs/barrel", features = ["sqlite3", "pg", "mysql", "mssql"] }
futures = "0.3"
assert_cmd = "1.0"
predicates = "1"
assert_cmd = "2.0"
predicates = "2"
tempfile = "3"
chrono = "0.4"
tokio-util = { version = "0.6.7", features = ["compat"] }
Expand Down
1 change: 0 additions & 1 deletion refinery/tests/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ mod mysql {
"migrate",
"-c",
"tests/mysql_refinery.toml",
"files",
"-p",
"tests/migrations",
])
Expand Down
1 change: 0 additions & 1 deletion refinery/tests/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ mod postgres {
"migrate",
"-c",
"tests/postgres_refinery.toml",
"files",
"-p",
"tests/migrations",
])
Expand Down
1 change: 0 additions & 1 deletion refinery/tests/rusqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ mod rusqlite {
"migrate",
"-c",
"tests/sqlite_refinery.toml",
"files",
"-p",
"tests/migrations",
])
Expand Down
1 change: 0 additions & 1 deletion refinery/tests/tiberius.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,6 @@ mod tiberius {
"migrate",
"-c",
"tests/tiberius_refinery.toml",
"files",
"-p",
"tests/migrations",
])
Expand Down
6 changes: 3 additions & 3 deletions refinery_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ refinery-core = { version = "0.6", path = "../refinery_core", default-features =
clap = { version = "2", features = ["wrap_help"] }
human-panic = "=1.0.3" # locked as 1.0.2 introduced breaking changes
toml = "0.5"
env_logger = "0.8"
env_logger = "0.9"
log = "0.4"
anyhow = "1"
regex = "1"
Expand All @@ -36,5 +36,5 @@ cfg-if = "1.0.0"
tokio = { version = "1.0", features = ["full"], optional = true }

[dev-dependencies]
predicates = "1"
assert_cmd = "1"
predicates = "2"
assert_cmd = "2"
4 changes: 2 additions & 2 deletions refinery_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ refinery setup
After that, just run your migrations giving your config file with `-c` flag (by defaults it is the `refinery.toml` generated by the setup) and migrations dir with `files -p $dir`.

```sh
refinery migrate -c sqlite_refinery.toml files -p ./sql_migrations
refinery migrate -c sqlite_refinery.toml -p ./sql_migrations
```

### Running via database uri

To run migrations from a database [uri](http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING) (like: postgres://user_name:passwd@hostname:5432/myDB ) stored in an environment variable DB_URI.

```sh
refinery migrate -e DB_URI files -p ./sql_migrations
refinery migrate -e DB_URI -p ./sql_migrations
```
This option is also useful when running refinery inside a docker container, where you usually have the db connection info stored as an environment variable.

Expand Down
26 changes: 7 additions & 19 deletions refinery_cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,13 @@ pub fn create_cli() -> App<'static, 'static> {
.help("if set, migrates even if missing migrations are found")
.takes_value(false),
)
// .subcommand(
// SubCommand::with_name("mod")
// .display_order(1)
// .about("Run migrations in rust modules")
// .arg_from_usage("<location> 'migrations module path i.e. crate::migrations'"),
// )
.subcommand(
SubCommand::with_name("files")
.display_order(2)
.about("Run migrations in .sql or .rs files")
.arg(
Arg::with_name("path")
.short("p")
.help("migrations dir path")
.default_value("./migrations")
.empty_values(false),
),
)
.setting(AppSettings::SubcommandRequired);
.arg(
Arg::with_name("path")
.short("p")
.help("migrations dir path")
.default_value("./migrations")
.empty_values(false),
);

/* Create an app and return it */
App::new(APP_NAME)
Expand Down
27 changes: 12 additions & 15 deletions refinery_cli/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,28 @@ pub fn handle_migration_command(args: &ArgMatches) -> anyhow::Result<()> {
let divergent = !args.is_present("divergent");
let missing = !args.is_present("missing");
let env_var_opt = args.value_of("env-var");
//safe to call unwrap as we specified default value
let path = args.value_of("path").unwrap();

match args.subcommand() {
("files", Some(args)) => run_files_migrations(
config_location,
grouped,
divergent,
missing,
env_var_opt,
args,
)?,
_ => unreachable!("Can't touch this..."),
}
run_migrations(
config_location,
grouped,
divergent,
missing,
env_var_opt,
path,
)?;
Ok(())
}

fn run_files_migrations(
fn run_migrations(
config_location: &str,
grouped: bool,
divergent: bool,
missing: bool,
env_var_opt: Option<&str>,
arg: &ArgMatches,
path: &str,
) -> anyhow::Result<()> {
//safe to call unwrap as we specified default value
let path = arg.value_of("path").unwrap();
let path = Path::new(path);
let migration_files_path = find_migration_files(path, MigrationType::Sql)?;
let mut migrations = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions refinery_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ toml = "0.5"
url = "2.0"
walkdir = "2.3.1"

rusqlite = {version = ">= 0.23, < 0.26", optional = true}
postgres = {version = "0.19", optional = true}
rusqlite = { version = ">= 0.23, < 0.26", optional = true }
postgres = { version = "0.19", optional = true }
tokio-postgres-driver = { package = "tokio-postgres", version = "0.7", optional = true }
mysql = { version = "21.0.0", optional = true }
mysql-async-driver = { package = "mysql_async", version = "0.28.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion refinery_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2018"
proc-macro = true

[dependencies]
refinery-core= { version = "0.6.0", path = "../refinery_core" }
refinery-core = { version = "0.6.0", path = "../refinery_core" }
quote = "1"
syn = "1"
proc-macro2 = "1"
Expand Down

0 comments on commit 273eb2f

Please sign in to comment.