summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-12-03 09:55:29 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-12-03 09:55:29 +0100
commit0f6b4a32ccf5d88debbfa4a7d7feaea8ca0969bc (patch)
treeab90f6f0314acfe2d95825567a186e770ce332f4
parentd7667a7aab2ffae5934292b16167f66a80bb9439 (diff)
An Artifact belongs to a job
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--migrations/2020-12-03-085333_artifact_belongs_to_job/down.sql5
-rw-r--r--migrations/2020-12-03-085333_artifact_belongs_to_job/up.sql5
-rw-r--r--src/db/models/artifact.rs6
-rw-r--r--src/schema.rs2
4 files changed, 17 insertions, 1 deletions
diff --git a/migrations/2020-12-03-085333_artifact_belongs_to_job/down.sql b/migrations/2020-12-03-085333_artifact_belongs_to_job/down.sql
new file mode 100644
index 0000000..3a56084
--- /dev/null
+++ b/migrations/2020-12-03-085333_artifact_belongs_to_job/down.sql
@@ -0,0 +1,5 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE
+ artifacts
+DROP COLUMN
+ job_id
diff --git a/migrations/2020-12-03-085333_artifact_belongs_to_job/up.sql b/migrations/2020-12-03-085333_artifact_belongs_to_job/up.sql
new file mode 100644
index 0000000..c838962
--- /dev/null
+++ b/migrations/2020-12-03-085333_artifact_belongs_to_job/up.sql
@@ -0,0 +1,5 @@
+-- Your SQL goes here
+ALTER TABLE
+ artifacts
+ADD COLUMN
+ job_id INTEGER REFERENCES jobs(id) NOT NULL
diff --git a/src/db/models/artifact.rs b/src/db/models/artifact.rs
index 92b6531..546df9b 100644
--- a/src/db/models/artifact.rs
+++ b/src/db/models/artifact.rs
@@ -1,7 +1,11 @@
-#[derive(Queryable)]
+use diesel::prelude::*;
+
+#[derive(Identifiable, Queryable, Associations)]
+#[belongs_to(Job)]
pub struct Artifact {
pub id: i32,
pub path: String,
pub released: bool,
+ pub job_id: i32,
}
diff --git a/src/schema.rs b/src/schema.rs
index 3b7c4d4..cca6a25 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -3,6 +3,7 @@ table! {
id -> Int4,
path -> Varchar,
released -> Bool,
+ job_id -> Int4,
}
}
@@ -101,6 +102,7 @@ table! {
}
}
+joinable!(artifacts -> jobs (job_id));
joinable!(job_envs -> envvars (env_id));
joinable!(job_envs -> jobs (job_id));
joinable!(job_input_artifacts -> artifacts (artifact_id));