summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--migrations/2020-12-14-100454_artifact-unique-by-job/down.sql5
-rw-r--r--migrations/2020-12-14-100454_artifact-unique-by-job/up.sql6
-rw-r--r--migrations/2020-12-14-113756_artifact_not_unique_by_path/down.sql7
-rw-r--r--migrations/2020-12-14-113756_artifact_not_unique_by_path/up.sql5
-rw-r--r--src/db/models/artifact.rs3
5 files changed, 24 insertions, 2 deletions
diff --git a/migrations/2020-12-14-100454_artifact-unique-by-job/down.sql b/migrations/2020-12-14-100454_artifact-unique-by-job/down.sql
new file mode 100644
index 0000000..11de887
--- /dev/null
+++ b/migrations/2020-12-14-100454_artifact-unique-by-job/down.sql
@@ -0,0 +1,5 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE
+ artifacts
+DROP CONSTRAINT
+ path_job_id_unique
diff --git a/migrations/2020-12-14-100454_artifact-unique-by-job/up.sql b/migrations/2020-12-14-100454_artifact-unique-by-job/up.sql
new file mode 100644
index 0000000..3749514
--- /dev/null
+++ b/migrations/2020-12-14-100454_artifact-unique-by-job/up.sql
@@ -0,0 +1,6 @@
+-- Your SQL goes here
+ALTER TABLE
+ artifacts
+ADD CONSTRAINT
+ path_job_id_unique
+ UNIQUE (path, job_id)
diff --git a/migrations/2020-12-14-113756_artifact_not_unique_by_path/down.sql b/migrations/2020-12-14-113756_artifact_not_unique_by_path/down.sql
new file mode 100644
index 0000000..c8bfe9d
--- /dev/null
+++ b/migrations/2020-12-14-113756_artifact_not_unique_by_path/down.sql
@@ -0,0 +1,7 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE
+ artifacts
+ADD CONSTRAINT
+ artifacts_path_key -- as generated by default for postgresql
+ UNIQUE (path)
+
diff --git a/migrations/2020-12-14-113756_artifact_not_unique_by_path/up.sql b/migrations/2020-12-14-113756_artifact_not_unique_by_path/up.sql
new file mode 100644
index 0000000..0dee2b4
--- /dev/null
+++ b/migrations/2020-12-14-113756_artifact_not_unique_by_path/up.sql
@@ -0,0 +1,5 @@
+-- Your SQL goes here
+ALTER TABLE
+ artifacts
+DROP CONSTRAINT
+ artifacts_path_key -- as generated by default for postgresql
diff --git a/src/db/models/artifact.rs b/src/db/models/artifact.rs
index 31f80fb..4faf7c4 100644
--- a/src/db/models/artifact.rs
+++ b/src/db/models/artifact.rs
@@ -46,11 +46,10 @@ impl Artifact {
diesel::insert_into(artifacts::table)
.values(&new_art)
- .on_conflict_do_nothing()
.execute(database_connection)?;
dsl::artifacts
- .filter(path.eq(path_str))
+ .filter(path.eq(path_str).and(job_id.eq(job.id)))
.first::<Artifact>(database_connection)
.map_err(Error::from)
}