summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-11-16 14:57:04 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-11-16 14:57:04 +0100
commit8e86e71e1d8828ddc313676adbf6b1974c0fa240 (patch)
tree9c36ebaa38aae36ae55dff05d9d0754935f44709
parentfad93aa5464fd084e91b72fc3d2b00d85f984edd (diff)
Add model type for job to env mapping
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/db/models/job_env.rs33
-rw-r--r--src/db/models/mod.rs3
2 files changed, 36 insertions, 0 deletions
diff --git a/src/db/models/job_env.rs b/src/db/models/job_env.rs
new file mode 100644
index 0000000..31c7a92
--- /dev/null
+++ b/src/db/models/job_env.rs
@@ -0,0 +1,33 @@
+use anyhow::Result;
+use diesel::PgConnection;
+use diesel::prelude::*;
+
+use crate::schema::job_envs::*;
+use crate::schema::job_envs;
+use crate::db::models::{Job, EnvVar};
+
+#[derive(Queryable)]
+pub struct JobEnv {
+ pub id: i32,
+ pub job_id: i32,
+ pub env_id: i32,
+}
+
+#[derive(Insertable)]
+#[table_name="job_envs"]
+struct NewJobEnv {
+ pub job_id: i32,
+ pub env_id: i32,
+}
+
+impl JobEnv {
+ pub fn create(database_connection: &PgConnection, job: &Job, env: &EnvVar) -> Result<()> {
+ let new_jobenv = NewJobEnv { job_id: job.id, env_id: env.id };
+
+ diesel::insert_into(job_envs::table)
+ .values(&new_jobenv)
+ .execute(database_connection)?;
+ Ok(())
+ }
+}
+
diff --git a/src/db/models/mod.rs b/src/db/models/mod.rs
index 26875bc..8e1eb8e 100644
--- a/src/db/models/mod.rs
+++ b/src/db/models/mod.rs
@@ -13,6 +13,9 @@ pub use image::*;
mod job;
pub use job::*;
+mod job_env;
+pub use job_env::*;
+
mod githash;
pub use githash::*;