summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--src/cli.rs8
-rw-r--r--src/commands/db.rs8
-rw-r--r--src/main.rs2
4 files changed, 19 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index bf51180..8dc8e26 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"
diff --git a/src/cli.rs b/src/cli.rs
index 1796b14..5d687dc 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -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;