diff options
author | Christopher Baines <mail@cbaines.net> | 2018-05-28 20:36:00 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2018-05-30 20:17:50 +0100 |
commit | 3b135d15e48eafb99395b3f1a62e15e5de1c5a4f (patch) | |
tree | e672864451e2f55216006ce90c8520f71cd31d7e | |
parent | 9df1bb790e24cad296d1187225dcb1fabed4b98b (diff) | |
download | govuk-mini-environment-admin-3b135d15e48eafb99395b3f1a62e15e5de1c5a4f.tar govuk-mini-environment-admin-3b135d15e48eafb99395b3f1a62e15e5de1c5a4f.tar.gz |
Add a new model to track services
Associated with a mini environment. This can also be used to store
customisations over the chosen revision of govuk-guix.
-rw-r--r-- | app/models/mini_environment.rb | 2 | ||||
-rw-r--r-- | app/models/mini_environment_service.rb | 57 | ||||
-rw-r--r-- | db/migrate/20180527183740_create_mini_environment_services.rb | 11 | ||||
-rw-r--r-- | db/structure.sql | 66 |
4 files changed, 135 insertions, 1 deletions
diff --git a/app/models/mini_environment.rb b/app/models/mini_environment.rb index 712e3a0..77e2f1b 100644 --- a/app/models/mini_environment.rb +++ b/app/models/mini_environment.rb @@ -49,6 +49,8 @@ class MiniEnvironment < ApplicationRecord belongs_to :govuk_guix_revision, class_name: 'GovukGuix::Revision' belongs_to :backend, polymorphic: true + has_many :services, class_name: 'MiniEnvironmentService', dependent: :destroy + def enqueued_terraform_jobs Que.execute("SELECT * FROM que_jobs WHERE args->>0 = '#{id}'") end diff --git a/app/models/mini_environment_service.rb b/app/models/mini_environment_service.rb new file mode 100644 index 0000000..73aa8aa --- /dev/null +++ b/app/models/mini_environment_service.rb @@ -0,0 +1,57 @@ +# GOV.UK Mini Environment Admin +# Copyright © 2018 Christopher Baines <mail@cbaines.net> +# +# This file is part of the GOV.UK Mini Environment Admin. +# +# The GOV.UK Mini Environment Admin is free software: you can +# redistribute it and/or modify it under the terms of the GNU Affero +# General Public License as published by the Free Software Foundation, +# either version 3 of the License, or (at your option) any later +# version. +# +# The GOV.UK Mini Environment Admin is distributed in the hope that it +# will be useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with the GOV.UK Mini Environment Admin. If not, see +# <http://www.gnu.org/licenses/>. + +# == Schema Information +# +# Table name: mini_environment_services +# +# id :integer not null, primary key +# name :string +# revision :string +# mini_environment_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# + +class MiniEnvironmentService < ApplicationRecord + belongs_to :mini_environment + + def customised? + service = mini_environment + .govuk_guix_revision + .all_available_services + .find do |s| + + s['name'] == name + end + + Rails.logger.info service + + service['package']['version'] != revision + end + + def build_argument_string + if customised? + "#{name}@#{revision}" + else + name + end + end +end diff --git a/db/migrate/20180527183740_create_mini_environment_services.rb b/db/migrate/20180527183740_create_mini_environment_services.rb new file mode 100644 index 0000000..135889c --- /dev/null +++ b/db/migrate/20180527183740_create_mini_environment_services.rb @@ -0,0 +1,11 @@ +class CreateMiniEnvironmentServices < ActiveRecord::Migration[5.1] + def change + create_table :mini_environment_services do |t| + t.string :name + t.string :revision + t.references :mini_environment, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/structure.sql b/db/structure.sql index 12c19cf..cd71ee3 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -85,6 +85,39 @@ CREATE TABLE public.govuk_guix_revisions ( -- +-- Name: mini_environment_services; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.mini_environment_services ( + id bigint NOT NULL, + name character varying, + revision character varying, + mini_environment_id bigint, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL +); + + +-- +-- Name: mini_environment_services_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.mini_environment_services_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: mini_environment_services_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.mini_environment_services_id_seq OWNED BY public.mini_environment_services.id; + + +-- -- Name: mini_environments; Type: TABLE; Schema: public; Owner: - -- @@ -319,6 +352,13 @@ ALTER TABLE ONLY public.finished_terraform_jobs ALTER COLUMN id SET DEFAULT next -- +-- Name: mini_environment_services id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.mini_environment_services ALTER COLUMN id SET DEFAULT nextval('public.mini_environment_services_id_seq'::regclass); + + +-- -- Name: mini_environments id; Type: DEFAULT; Schema: public; Owner: - -- @@ -385,6 +425,14 @@ ALTER TABLE ONLY public.govuk_guix_revisions -- +-- Name: mini_environment_services mini_environment_services_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.mini_environment_services + ADD CONSTRAINT mini_environment_services_pkey PRIMARY KEY (id); + + +-- -- Name: mini_environments mini_environments_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -448,6 +496,13 @@ CREATE UNIQUE INDEX index_govuk_guix_revisions_on_commit_hash ON public.govuk_gu -- +-- Name: index_mini_environment_services_on_mini_environment_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_mini_environment_services_on_mini_environment_id ON public.mini_environment_services USING btree (mini_environment_id); + + +-- -- Name: index_mini_environments_on_backend_type_and_backend_id; Type: INDEX; Schema: public; Owner: - -- @@ -470,6 +525,14 @@ ALTER TABLE ONLY public.mini_environments -- +-- Name: mini_environment_services fk_rails_36052da616; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.mini_environment_services + ADD CONSTRAINT fk_rails_36052da616 FOREIGN KEY (mini_environment_id) REFERENCES public.mini_environments(id); + + +-- -- PostgreSQL database dump complete -- @@ -503,6 +566,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20180410192329'), ('20180410192412'), ('20180417195307'), -('20180523062426'); +('20180523062426'), +('20180527183740'); |