summaryrefslogtreecommitdiffstats
path: root/migrations
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-12-14 11:08:07 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-12-14 12:47:03 +0100
commit182d1454eb5f2bde86ef2256bb945bc41ee45be5 (patch)
tree94c6f1ef785993cd5a438b5d702d70a8742e482b /migrations
parent98a227248449e71f08cc7ff80579978bf0e5440e (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 'migrations')
-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
4 files changed, 23 insertions, 0 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