diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-12-14 11:08:07 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-12-14 12:47:03 +0100 |
commit | 182d1454eb5f2bde86ef2256bb945bc41ee45be5 (patch) | |
tree | 94c6f1ef785993cd5a438b5d702d70a8742e482b /src | |
parent | 98a227248449e71f08cc7ff80579978bf0e5440e (diff) |
Fix: Add constraints that artifact entries must be unique by path and job id
This patch alters the database so that artifact entries in the db are
unique by path and job they belong to.
The `db::models::Artifact` implementation was updated to select the
newly created Artifact object by path and by job id.
The uniqueness constraint on the `path` column in the `artifacts` table
was dropped.
Uncool: We did not generate the constraint name explicitely. That's
unfortunate as we have to gamble here that the constraint name is always
guaranteed to be the same ("artifacts_path_key").
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/db/models/artifact.rs | 3 |
1 files changed, 1 insertions, 2 deletions
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) } |