diff --git a/app/models/repository.rb b/app/models/repository.rb index 5c042d81..7e9fd097 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -16,6 +16,7 @@ # # Indexes # +# index_repositories_on_github_id (github_id) UNIQUE # index_repositories_on_language_id (language_id) # index_repositories_on_product_id (product_id) # diff --git a/app/services/builders/external_pull_request.rb b/app/services/builders/external_pull_request.rb index 339c22be..4ccbaf19 100644 --- a/app/services/builders/external_pull_request.rb +++ b/app/services/builders/external_pull_request.rb @@ -79,13 +79,22 @@ def initialize(repository_full_name, pull_request_number) end def call - Builders::ExternalPullRequest.call(pull_request_data) + Builders::ExternalPullRequest.call(pull_request_data) if pull_request_data.present? end private def pull_request_data GithubClient::PullRequest.new(pull_request).get + rescue Faraday::ResourceNotFound => exception + Rails.logger.error("Failed to fetch pull request data: #{exception.message}") + + Honeybadger.notify(exception, context: { + repository_full_name: @repository_full_name, + pull_request_number: @pull_request_number + }) + + nil end def pull_request diff --git a/db/migrate/20240829142623_add_unique_index_to_github_id_in_repositories.rb b/db/migrate/20240829142623_add_unique_index_to_github_id_in_repositories.rb new file mode 100644 index 00000000..12035714 --- /dev/null +++ b/db/migrate/20240829142623_add_unique_index_to_github_id_in_repositories.rb @@ -0,0 +1,5 @@ +class AddUniqueIndexToGithubIdInRepositories < ActiveRecord::Migration[7.1] + def change + add_index :repositories, :github_id, unique: true + end +end diff --git a/db/structure.sql b/db/structure.sql index 4739dbba..80ac6871 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -9,6 +9,27 @@ SET xmloption = content; SET client_min_messages = warning; SET row_security = off; +-- +-- Name: public; Type: SCHEMA; Schema: -; Owner: - +-- + +-- *not* creating schema, since initdb creates it + + +-- +-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public; + + +-- +-- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION pg_stat_statements IS 'track planning and execution statistics of all SQL statements executed'; + + -- -- Name: pg_trgm; Type: EXTENSION; Schema: -; Owner: - -- @@ -859,9 +880,9 @@ CREATE TABLE public.external_pull_requests ( external_repository_id bigint NOT NULL, created_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL, - number integer, opened_at timestamp without time zone, - state public.external_pull_request_state + state public.external_pull_request_state, + number integer ); @@ -2428,6 +2449,13 @@ CREATE INDEX index_products_on_enabled ON public.products USING btree (enabled); CREATE INDEX index_products_on_name ON public.products USING btree (name); +-- +-- Name: index_repositories_on_github_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_repositories_on_github_id ON public.repositories USING btree (github_id); + + -- -- Name: index_repositories_on_language_id; Type: INDEX; Schema: public; Owner: - -- @@ -2910,151 +2938,151 @@ ALTER TABLE ONLY public.review_requests SET search_path TO "$user", public; INSERT INTO "schema_migrations" (version) VALUES -('20191220183808'), -('20191220183838'), -('20191220190613'), -('20191220192022'), -('20191223133115'), -('20191223133712'), -('20191223141540'), -('20191223145336'), -('20191223145416'), -('20191226185853'), -('20191226190938'), -('20191226195441'), -('20191227202204'), -('20191227203014'), -('20191230180053'), -('20191231130959'), -('20191231134130'), -('20200122143238'), -('20200122180806'), -('20200128190806'), -('20200131153049'), -('20200131153056'), -('20200203141336'), -('20200204134248'), -('20200204134315'), -('20200204140453'), -('20200204201145'), -('20200204202145'), -('20200206203510'), -('20200206203850'), -('20200212151614'), -('20200217165218'), -('20200219141137'), -('20200302120947'), -('20200303210031'), -('20200305141203'), -('20200305142724'), -('20200305150412'), -('20200305150445'), -('20200305171608'), -('20200311132103'), -('20200312144232'), -('20200312161141'), -('20200318125243'), -('20200318160321'), -('20200318171820'), -('20200327172924'), -('20200330162011'), -('20200401200520'), -('20200401205154'), -('20200402175059'), -('20200403140307'), -('20200414205816'), -('20200415162514'), -('20200416212440'), -('20200421172329'), -('20200422173907'), -('20200423134541'), -('20200423170720'), -('20200423175049'), -('20200423185715'), -('20200424155835'), -('20200504143532'), -('20200506182951'), -('20200507135524'), -('20200507174834'), -('20200511180927'), -('20200518155135'), -('20200518155136'), -('20200518160851'), -('20200602181502'), -('20200605192032'), -('20200611153414'), -('20200611190026'), -('20200612195323'), -('20200616154910'), -('20200617145408'), -('20200618174209'), -('20200622214544'), -('20200622221335'), -('20200622221651'), -('20200622221729'), -('20200625144922'), -('20200630165139'), -('20200701133311'), -('20200703141617'), -('20200713152004'), -('20200714160138'), -('20200720155715'), -('20200723174621'), -('20200730142418'), -('20200806131024'), -('20200813162522'), -('20200819142237'), -('20200820180521'), -('20200824202901'), -('20200825151321'), -('20200901185355'), -('20200908121903'), -('20200908173642'), -('20200911143301'), -('20200922131539'), -('20200925174541'), -('20200929205630'), -('20201029141417'), -('20201102203739'), -('20201201184505'), -('20201201193101'), -('20201211133046'), -('20201214192048'), -('20210115132729'), -('20210118145940'), -('20210315154031'), -('20210316150725'), -('20210317024356'), -('20210318034939'), -('20210706143943'), -('20210707194545'), -('20210707210306'), -('20210707221342'), -('20210707225815'), -('20210708153602'), -('20210712190532'), -('20210714143812'), -('20210714155857'), -('20210720212026'), -('20210722152015'), -('20210723184744'), -('20210726184449'), -('20210810122756'), -('20210810123929'), -('20210810184003'), -('20210810202705'), -('20210811165206'), -('20210827172747'), -('20210830200109'), -('20210830200129'), -('20210830211654'), -('20210902140638'), -('20210902182225'), -('20210915145551'), -('20210916151310'), -('20220412181602'), -('20221228101900'), +('20240829142623'), +('20240627133952'), ('20221228121949'), -('20240627133952'); - +('20221228101900'), +('20220412181602'), +('20210916151310'), +('20210915145551'), +('20210902182225'), +('20210902140638'), +('20210830211654'), +('20210830200129'), +('20210830200109'), +('20210827172747'), +('20210811165206'), +('20210810202705'), +('20210810184003'), +('20210810123929'), +('20210810122756'), +('20210726184449'), +('20210723184744'), +('20210722152015'), +('20210720212026'), +('20210714155857'), +('20210714143812'), +('20210712190532'), +('20210708153602'), +('20210707225815'), +('20210707221342'), +('20210707210306'), +('20210707194545'), +('20210706143943'), +('20210318034939'), +('20210317024356'), +('20210316150725'), +('20210315154031'), +('20210118145940'), +('20210115132729'), +('20201214192048'), +('20201211133046'), +('20201201193101'), +('20201201184505'), +('20201102203739'), +('20201029141417'), +('20200929205630'), +('20200925174541'), +('20200922131539'), +('20200911143301'), +('20200908173642'), +('20200908121903'), +('20200901185355'), +('20200825151321'), +('20200824202901'), +('20200820180521'), +('20200819142237'), +('20200813162522'), +('20200806131024'), +('20200730142418'), +('20200723174621'), +('20200720155715'), +('20200714160138'), +('20200713152004'), +('20200703141617'), +('20200701133311'), +('20200630165139'), +('20200625144922'), +('20200622221729'), +('20200622221651'), +('20200622221335'), +('20200622214544'), +('20200618174209'), +('20200617145408'), +('20200616154910'), +('20200612195323'), +('20200611190026'), +('20200611153414'), +('20200605192032'), +('20200602181502'), +('20200518160851'), +('20200518155136'), +('20200518155135'), +('20200511180927'), +('20200507174834'), +('20200507135524'), +('20200506182951'), +('20200504143532'), +('20200424155835'), +('20200423185715'), +('20200423175049'), +('20200423170720'), +('20200423134541'), +('20200422173907'), +('20200421172329'), +('20200416212440'), +('20200415162514'), +('20200414205816'), +('20200403140307'), +('20200402175059'), +('20200401205154'), +('20200401200520'), +('20200330162011'), +('20200327172924'), +('20200318171820'), +('20200318160321'), +('20200318125243'), +('20200312161141'), +('20200312144232'), +('20200311132103'), +('20200305171608'), +('20200305150445'), +('20200305150412'), +('20200305142724'), +('20200305141203'), +('20200303210031'), +('20200302120947'), +('20200219141137'), +('20200217165218'), +('20200212151614'), +('20200206203850'), +('20200206203510'), +('20200204202145'), +('20200204201145'), +('20200204140453'), +('20200204134315'), +('20200204134248'), +('20200203141336'), +('20200131153056'), +('20200131153049'), +('20200128190806'), +('20200122180806'), +('20200122143238'), +('20191231134130'), +('20191231130959'), +('20191230180053'), +('20191227203014'), +('20191227202204'), +('20191226195441'), +('20191226190938'), +('20191226185853'), +('20191223145416'), +('20191223145336'), +('20191223141540'), +('20191223133712'), +('20191223133115'), +('20191220192022'), +('20191220190613'), +('20191220183838'), +('20191220183808'); diff --git a/spec/factories/repositories.rb b/spec/factories/repositories.rb index 461323ff..89ec3a15 100644 --- a/spec/factories/repositories.rb +++ b/spec/factories/repositories.rb @@ -16,6 +16,7 @@ # # Indexes # +# index_repositories_on_github_id (github_id) UNIQUE # index_repositories_on_language_id (language_id) # index_repositories_on_product_id (product_id) # diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index c69d2200..37c439f8 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -16,6 +16,7 @@ # # Indexes # +# index_repositories_on_github_id (github_id) UNIQUE # index_repositories_on_language_id (language_id) # index_repositories_on_product_id (product_id) #