blob: 1fa6c0340d63c7c1c5506bd1cb2a601dc101f21b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
//
// Copyright (c) 2020-2021 science+computing ag and other contributors
//
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//
use anyhow::Result;
use diesel::PgConnection;
use diesel::prelude::*;
use crate::schema::job_envs;
use crate::db::models::Job;
use crate::db::models::EnvVar;
#[derive(Identifiable, Queryable, Associations)]
#[belongs_to(Job)]
#[belongs_to(EnvVar, foreign_key = "env_id")]
#[table_name="job_envs"]
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(())
}
}
|