From f98bdb86d09f803495c9c203c350a7f06d96a8de Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 1 Jun 2018 20:42:03 +0100 Subject: Add an optional DataSnapshot to the MiniEnvironment model To store if a DataSnapshot is being used. --- app/models/mini_environment.rb | 6 ++++++ ...1182655_add_data_snapshot_to_mini_environment.rb | 9 +++++++++ db/structure.sql | 21 +++++++++++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20180601182655_add_data_snapshot_to_mini_environment.rb diff --git a/app/models/mini_environment.rb b/app/models/mini_environment.rb index 77e2f1b..c92a62c 100644 --- a/app/models/mini_environment.rb +++ b/app/models/mini_environment.rb @@ -32,6 +32,7 @@ # backend_id :integer # backend_data :jsonb # signon_users :jsonb +# data_snapshot_id :integer # class MiniEnvironment < ApplicationRecord @@ -50,6 +51,11 @@ class MiniEnvironment < ApplicationRecord belongs_to :backend, polymorphic: true has_many :services, class_name: 'MiniEnvironmentService', dependent: :destroy + belongs_to( + :data_snapshot, + class_name: 'GovukGuix::DataSnapshot', + optional: true + ) def enqueued_terraform_jobs Que.execute("SELECT * FROM que_jobs WHERE args->>0 = '#{id}'") diff --git a/db/migrate/20180601182655_add_data_snapshot_to_mini_environment.rb b/db/migrate/20180601182655_add_data_snapshot_to_mini_environment.rb new file mode 100644 index 0000000..8c12cf0 --- /dev/null +++ b/db/migrate/20180601182655_add_data_snapshot_to_mini_environment.rb @@ -0,0 +1,9 @@ +class AddDataSnapshotToMiniEnvironment < ActiveRecord::Migration[5.1] + def change + add_reference( + :mini_environments, + :data_snapshot, + foreign_key: { to_table: :govuk_guix_data_snapshots } + ) + end +end diff --git a/db/structure.sql b/db/structure.sql index 7b5d81f..9e03d7d 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -167,7 +167,8 @@ CREATE TABLE public.mini_environments ( backend_type character varying, backend_id bigint, backend_data jsonb, - signon_users jsonb + signon_users jsonb, + data_snapshot_id bigint ); @@ -574,6 +575,13 @@ CREATE INDEX index_mini_environment_services_on_mini_environment_id ON public.mi CREATE INDEX index_mini_environments_on_backend_type_and_backend_id ON public.mini_environments USING btree (backend_type, backend_id); +-- +-- Name: index_mini_environments_on_data_snapshot_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_mini_environments_on_data_snapshot_id ON public.mini_environments USING btree (data_snapshot_id); + + -- -- Name: index_mini_environments_on_govuk_guix_revision_id; Type: INDEX; Schema: public; Owner: - -- @@ -605,6 +613,14 @@ ALTER TABLE ONLY public.govuk_guix_data_snapshots ADD CONSTRAINT fk_rails_59b1facc61 FOREIGN KEY (govuk_guix_revision_commit_hash) REFERENCES public.govuk_guix_revisions(commit_hash); +-- +-- Name: mini_environments fk_rails_eba071cb24; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.mini_environments + ADD CONSTRAINT fk_rails_eba071cb24 FOREIGN KEY (data_snapshot_id) REFERENCES public.govuk_guix_data_snapshots(id); + + -- -- PostgreSQL database dump complete -- @@ -643,6 +659,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20180527183740'), ('20180530191341'), ('20180530192706'), -('20180601153537'); +('20180601153537'), +('20180601182655'); -- cgit v1.2.3