aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/jobs/backends/deploy_terraform_libvirt_job.rb33
-rw-r--r--app/jobs/mini_environment_job.rb35
-rw-r--r--app/models/finished_terraform_job.rb34
-rw-r--r--app/models/mini_environment.rb9
-rw-r--r--db/migrate/20180621220505_delete_finished_terraform_job.rb9
-rw-r--r--db/structure.sql50
6 files changed, 25 insertions, 145 deletions
diff --git a/app/jobs/backends/deploy_terraform_libvirt_job.rb b/app/jobs/backends/deploy_terraform_libvirt_job.rb
index 3b8b51a..4565189 100644
--- a/app/jobs/backends/deploy_terraform_libvirt_job.rb
+++ b/app/jobs/backends/deploy_terraform_libvirt_job.rb
@@ -27,33 +27,12 @@ class Backends::DeployTerraformLibvirtJob < Que::Job
.deploy_backend
end
- def destroy
- FinishedTerraformJob.create(
- model_id: @terraform_libvirt_backend_id,
- job_class: attrs[:job_class]
- )
- super
- end
-
def self.jobs(terraform_libvirt_backend_id)
- [
- QueJob
- .where(
- job_class: name
- ).where(
- "args->>0 = '#{terraform_libvirt_backend_id}'"
- ).to_a,
- FinishedTerraformJob
- .where(
- job_class: name,
- model_id: terraform_libvirt_backend_id
- )
- ].flatten.sort_by do |x|
- if x.instance_of? QueJob
- x.run_at
- else # FinishedTerraformJob
- x.created_at
- end
- end
+ QueJob
+ .where(
+ job_class: name
+ ).where(
+ "args->>0 = '#{terraform_libvirt_backend_id}'"
+ ).to_a
end
end
diff --git a/app/jobs/mini_environment_job.rb b/app/jobs/mini_environment_job.rb
index 90fbbd4..e5112cd 100644
--- a/app/jobs/mini_environment_job.rb
+++ b/app/jobs/mini_environment_job.rb
@@ -24,36 +24,17 @@ class MiniEnvironmentJob < Que::Job
@mini_environment = MiniEnvironment.find(mini_environment_id)
@mini_environment.backend.send(action, @mini_environment)
- end
- end
- def destroy
- FinishedTerraformJob.create(
- model_id: @mini_environment.id,
- job_class: attrs[:job_class]
- )
- super
+ finish
+ end
end
def self.jobs(mini_environment_id)
- [
- QueJob
- .where(
- job_class: name
- ).where(
- "args->>0 = '#{mini_environment_id}'"
- ).to_a,
- FinishedTerraformJob
- .where(
- job_class: name,
- model_id: mini_environment_id
- )
- ].flatten.sort_by do |x|
- if x.instance_of? QueJob
- x.run_at
- else # FinishedTerraformJob
- x.created_at
- end
- end
+ QueJob
+ .where(
+ job_class: name
+ ).where(
+ "args->>0 = '#{mini_environment_id}'"
+ ).to_a
end
end
diff --git a/app/models/finished_terraform_job.rb b/app/models/finished_terraform_job.rb
deleted file mode 100644
index ca2cb94..0000000
--- a/app/models/finished_terraform_job.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# 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: finished_terraform_jobs
-#
-# id :integer not null, primary key
-# model_id :integer
-# job_class :string
-# created_at :datetime not null
-# updated_at :datetime not null
-#
-
-class FinishedTerraformJob < ApplicationRecord
- belongs_to :mini_environment
-end
diff --git a/app/models/mini_environment.rb b/app/models/mini_environment.rb
index 502cff2..d3f8ec3 100644
--- a/app/models/mini_environment.rb
+++ b/app/models/mini_environment.rb
@@ -36,15 +36,6 @@
#
class MiniEnvironment < ApplicationRecord
- has_many(
- :finished_terraform_jobs,
- lambda do |mini_environment|
- unscope(:where).where(
- 'finished_terraform_jobs.model_id = ?', mini_environment.id
- )
- end,
- dependent: :destroy
- )
belongs_to :govuk_guix_revision, class_name: 'GovukGuix::Revision'
belongs_to :backend, polymorphic: true
diff --git a/db/migrate/20180621220505_delete_finished_terraform_job.rb b/db/migrate/20180621220505_delete_finished_terraform_job.rb
new file mode 100644
index 0000000..ca68a6e
--- /dev/null
+++ b/db/migrate/20180621220505_delete_finished_terraform_job.rb
@@ -0,0 +1,9 @@
+class DeleteFinishedTerraformJob < ActiveRecord::Migration[5.1]
+ def up
+ drop_table :finished_terraform_jobs
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index 31c2571..342e36c 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -241,38 +241,6 @@ CREATE TABLE public.ar_internal_metadata (
--
--- Name: finished_terraform_jobs; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.finished_terraform_jobs (
- id bigint NOT NULL,
- model_id integer,
- job_class character varying,
- created_at timestamp without time zone NOT NULL,
- updated_at timestamp without time zone NOT NULL
-);
-
-
---
--- Name: finished_terraform_jobs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.finished_terraform_jobs_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: finished_terraform_jobs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.finished_terraform_jobs_id_seq OWNED BY public.finished_terraform_jobs.id;
-
-
---
-- Name: govuk_guix_data_snapshots; Type: TABLE; Schema: public; Owner: -
--
@@ -589,13 +557,6 @@ ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;
--
--- Name: finished_terraform_jobs id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.finished_terraform_jobs ALTER COLUMN id SET DEFAULT nextval('public.finished_terraform_jobs_id_seq'::regclass);
-
-
---
-- Name: govuk_guix_data_snapshots id; Type: DEFAULT; Schema: public; Owner: -
--
@@ -660,14 +621,6 @@ ALTER TABLE ONLY public.ar_internal_metadata
--
--- Name: finished_terraform_jobs finished_terraform_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.finished_terraform_jobs
- ADD CONSTRAINT finished_terraform_jobs_pkey PRIMARY KEY (id);
-
-
---
-- Name: govuk_guix_data_snapshots govuk_guix_data_snapshots_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@@ -920,6 +873,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20180601153537'),
('20180601182655'),
('20180603120426'),
-('20180621065525');
+('20180621065525'),
+('20180621220505');