diff options
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/cli.rs | 8 | ||||
-rw-r--r-- | src/commands/db.rs | 8 | ||||
-rw-r--r-- | src/main.rs | 2 |
4 files changed, 19 insertions, 0 deletions
@@ -35,6 +35,7 @@ csv = "1.1" daggy = { version = "0.7", features = [ "serde" ] } dialoguer = "0.8" diesel = { version = ">=1.4.6", features = ["postgres", "chrono", "uuid", "serde_json"] } +diesel_migrations = "*" env_logger = "0.8" filters = "0.4.0" futures = "0.3" @@ -121,6 +121,14 @@ pub fn cli<'a>() -> App<'a> { ) ) + .subcommand(App::new("setup") + .version(crate_version!()) + .about("Run the database setup") + .long_about(indoc::indoc!(r#" + Run the database setup migrations + "#)) + ) + .subcommand(App::new("artifacts") .version(crate_version!()) .about("List artifacts from the DB") diff --git a/src/commands/db.rs b/src/commands/db.rs index 2481259..7939b20 100644 --- a/src/commands/db.rs +++ b/src/commands/db.rs @@ -36,6 +36,8 @@ use crate::db::DbConnectionConfig; use crate::package::Script; use crate::schema; +diesel_migrations::embed_migrations!("migrations"); + /// Implementation of the "db" subcommand pub fn db( db_connection_config: DbConnectionConfig<'_>, @@ -44,6 +46,7 @@ pub fn db( ) -> Result<()> { match matches.subcommand() { Some(("cli", matches)) => cli(db_connection_config, matches), + Some(("setup", _matches)) => setup(db_connection_config), Some(("artifacts", matches)) => artifacts(db_connection_config, matches), Some(("envvars", matches)) => envvars(db_connection_config, matches), Some(("images", matches)) => images(db_connection_config, matches), @@ -142,6 +145,11 @@ fn cli(db_connection_config: DbConnectionConfig<'_>, matches: &ArgMatches) -> Re .run_for_uri(db_connection_config) } +fn setup(conn_cfg: DbConnectionConfig<'_>) -> Result<()> { + let conn = conn_cfg.establish_connection()?; + embedded_migrations::run_with_output(&conn, &mut std::io::stdout()).map_err(Error::from) +} + /// Implementation of the "db artifacts" subcommand fn artifacts(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> { use crate::schema::artifacts::dsl; diff --git a/src/main.rs b/src/main.rs index 20f0191..59dd559 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,6 +47,8 @@ extern crate log as logcrate; #[macro_use] extern crate diesel; +#[macro_use] +extern crate diesel_migrations; use std::path::PathBuf; |