aboutsummaryrefslogtreecommitdiff
path: root/sqitch/deploy
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-05-05 13:35:48 +0100
committerChristopher Baines <mail@cbaines.net>2019-05-05 14:36:52 +0100
commitce4c3c6ed3979e54a8d5db6514bf4ed87de8b707 (patch)
treeed0e8c4b4a87ebad122fb831e6ea1d01ac6f037b /sqitch/deploy
parent051962b54d9a647adc8c09fb8ef33db2ac9b659a (diff)
downloaddata-service-ce4c3c6ed3979e54a8d5db6514bf4ed87de8b707.tar
data-service-ce4c3c6ed3979e54a8d5db6514bf4ed87de8b707.tar.gz
Switch to storing Git repositories in a table
Rather than just storing the URL in the guix_revisions and load_new_guix_revision_jobs tables. This will help when storing more information like tags and branches in the future.
Diffstat (limited to 'sqitch/deploy')
-rw-r--r--sqitch/deploy/git_repositories.sql41
1 files changed, 41 insertions, 0 deletions
diff --git a/sqitch/deploy/git_repositories.sql b/sqitch/deploy/git_repositories.sql
new file mode 100644
index 0000000..e61c25b
--- /dev/null
+++ b/sqitch/deploy/git_repositories.sql
@@ -0,0 +1,41 @@
+-- Deploy guix-data-service:git_repositories to pg
+-- requires: initial_import
+
+BEGIN;
+
+CREATE TABLE git_repositories (
+ id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
+ label character varying,
+ url character varying NOT NULL UNIQUE
+);
+
+INSERT INTO git_repositories (url)
+SELECT DISTINCT url FROM guix_revisions;
+
+-- Change the guix_revisions table
+
+ALTER TABLE guix_revisions ADD COLUMN git_repository_id integer
+REFERENCES git_repositories (id);
+
+UPDATE guix_revisions SET git_repository_id = (
+ SELECT id FROM git_repositories WHERE guix_revisions.url = git_repositories.url
+);
+
+ALTER TABLE guix_revisions ALTER COLUMN git_repository_id SET NOT NULL;
+
+ALTER TABLE guix_revisions DROP COLUMN url;
+
+-- Change the load_new_guix_revision_jobs table
+
+ALTER TABLE load_new_guix_revision_jobs ADD COLUMN git_repository_id integer
+REFERENCES git_repositories (id);
+
+UPDATE load_new_guix_revision_jobs SET git_repository_id = (
+ SELECT id FROM git_repositories WHERE load_new_guix_revision_jobs.url = git_repositories.url
+);
+
+ALTER TABLE load_new_guix_revision_jobs ALTER COLUMN git_repository_id SET NOT NULL;
+
+ALTER TABLE load_new_guix_revision_jobs DROP COLUMN url;
+
+COMMIT;