Skip to content

Clean up external_service_repos and external_services table on Sourcegraph.com

Created by: ryanslade

While working on https://github.com/sourcegraph/sourcegraph/issues/14985 I noticed some issues in our external_service_repos and external_services tables:

  1. We have a deleted external service, id 12, which still has many rows associated in the external_service_repos table.
  2. At some point an external service with id 15 was added and all our new public repos are being added to this one instead of our GitHub public external service with id 4.
  3. We have repos not owned by any external service:
select count(*) from repo where not exists (select from external_service_repos where repo_id = id) and deleted_at is null;
  1. We have duplicate rows in external_service_repos for the same repo / external service combination. For example, try:
select * from external_service_repos where repo_id = 54;

We need to fix the above as well as the root cause so that it can't happen again.