From 8e86e71e1d8828ddc313676adbf6b1974c0fa240 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 16 Nov 2020 14:57:04 +0100 Subject: Add model type for job to env mapping Signed-off-by: Matthias Beyer --- src/db/models/job_env.rs | 33 +++++++++++++++++++++++++++++++++ src/db/models/mod.rs | 3 +++ 2 files changed, 36 insertions(+) create mode 100644 src/db/models/job_env.rs 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::*; -- cgit v1.2.3