diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-05-17 13:21:33 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-05-17 13:21:33 +0200 |
commit | 41d058415ceb6cf725416d5cc9cfa49092da0cea (patch) | |
tree | 8ff3cf99df76df8416db5d489fbcb21f63315ab0 /src/commands/db.rs | |
parent | df0db108c06836bd986a091274e027838523c23d (diff) |
Add "db setup" subcommand
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/commands/db.rs')
-rw-r--r-- | src/commands/db.rs | 8 |
1 files changed, 8 insertions, 0 deletions
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; |