From 33e9e5b3f0bb5ba7e62213c162e2acdcddd0c73b Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 26 Oct 2022 03:55:59 -0500 Subject: [PATCH] db: apply good_jobs migrations Apply a couple of migrations from `bin/rails generate good_job:update`. --- ...20221026084655_create_good_job_settings.rb | 19 +++++++++ ..._on_priority_created_at_when_unfinished.rb | 18 +++++++++ db/structure.sql | 39 ++++++++++++++++++- 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20221026084655_create_good_job_settings.rb create mode 100644 db/migrate/20221026084656_create_index_good_jobs_jobs_on_priority_created_at_when_unfinished.rb diff --git a/db/migrate/20221026084655_create_good_job_settings.rb b/db/migrate/20221026084655_create_good_job_settings.rb new file mode 100644 index 000000000..51d9acc30 --- /dev/null +++ b/db/migrate/20221026084655_create_good_job_settings.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true +class CreateGoodJobSettings < ActiveRecord::Migration[7.0] + def change + reversible do |dir| + dir.up do + # Ensure this incremental update migration is idempotent + # with monolithic install migration. + return if connection.table_exists?(:good_job_settings) + end + end + + create_table :good_job_settings, id: :uuid do |t| + t.timestamps + t.text :key + t.jsonb :value + t.index :key, unique: true + end + end +end diff --git a/db/migrate/20221026084656_create_index_good_jobs_jobs_on_priority_created_at_when_unfinished.rb b/db/migrate/20221026084656_create_index_good_jobs_jobs_on_priority_created_at_when_unfinished.rb new file mode 100644 index 000000000..c05fe0b7e --- /dev/null +++ b/db/migrate/20221026084656_create_index_good_jobs_jobs_on_priority_created_at_when_unfinished.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true +class CreateIndexGoodJobsJobsOnPriorityCreatedAtWhenUnfinished < ActiveRecord::Migration[7.0] + disable_ddl_transaction! + + def change + reversible do |dir| + dir.up do + # Ensure this incremental update migration is idempotent + # with monolithic install migration. + return if connection.index_name_exists?(:good_jobs, :index_good_jobs_jobs_on_priority_created_at_when_unfinished) + end + end + + add_index :good_jobs, [:priority, :created_at], order: { priority: "DESC NULLS LAST", created_at: :asc }, + where: "finished_at IS NULL", name: :index_good_jobs_jobs_on_priority_created_at_when_unfinished, + algorithm: :concurrently + end +end diff --git a/db/structure.sql b/db/structure.sql index 3229f7a13..0f8aa3851 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -808,6 +808,19 @@ CREATE TABLE public.good_job_processes ( ); +-- +-- Name: good_job_settings; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.good_job_settings ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL, + key text, + value jsonb +); + + -- -- Name: good_jobs; Type: TABLE; Schema: public; Owner: - -- @@ -3101,6 +3114,14 @@ ALTER TABLE ONLY public.good_job_processes ADD CONSTRAINT good_job_processes_pkey PRIMARY KEY (id); +-- +-- Name: good_job_settings good_job_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.good_job_settings + ADD CONSTRAINT good_job_settings_pkey PRIMARY KEY (id); + + -- -- Name: good_jobs good_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -4204,6 +4225,13 @@ CREATE INDEX index_forum_topics_on_title_tsvector ON public.forum_topics USING g CREATE INDEX index_forum_topics_on_updated_at ON public.forum_topics USING btree (updated_at); +-- +-- Name: index_good_job_settings_on_key; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_good_job_settings_on_key ON public.good_job_settings USING btree (key); + + -- -- Name: index_good_jobs_jobs_on_finished_at; Type: INDEX; Schema: public; Owner: - -- @@ -4211,6 +4239,13 @@ CREATE INDEX index_forum_topics_on_updated_at ON public.forum_topics USING btree CREATE INDEX index_good_jobs_jobs_on_finished_at ON public.good_jobs USING btree (finished_at) WHERE ((retried_good_job_id IS NULL) AND (finished_at IS NOT NULL)); +-- +-- Name: index_good_jobs_jobs_on_priority_created_at_when_unfinished; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_good_jobs_jobs_on_priority_created_at_when_unfinished ON public.good_jobs USING btree (priority DESC NULLS LAST, created_at) WHERE (finished_at IS NULL); + + -- -- Name: index_good_jobs_on_active_job_id; Type: INDEX; Schema: public; Owner: - -- @@ -6870,6 +6905,8 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220925045236'), ('20220926050108'), ('20221003080342'), -('20221010035855'); +('20221010035855'), +('20221026084655'), +('20221026084656');