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:
- We have a deleted external service, id 12, which still has many rows associated in the
external_service_repostable. - 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 publicexternal service with id 4. - 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;
- We have duplicate rows in
external_service_reposfor 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.