@@ -466,6 +466,40 @@ func (q *Queries) GetRepoByOwnerUserAndName(ctx context.Context, db DBTX, arg Ge |
| 466 | 466 | return i, err |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | +const getRepoForBackfill = `-- name: GetRepoForBackfill :one |
| 470 | +SELECT |
| 471 | + r.id, |
| 472 | + r.name, |
| 473 | + r.default_branch, |
| 474 | + COALESCE(u.username, o.slug) AS owner |
| 475 | +FROM repos r |
| 476 | +LEFT JOIN users u ON u.id = r.owner_user_id |
| 477 | +LEFT JOIN orgs o ON o.id = r.owner_org_id |
| 478 | +WHERE r.id = $1 AND r.deleted_at IS NULL |
| 479 | +` |
| 480 | + |
| 481 | +type GetRepoForBackfillRow struct { |
| 482 | + ID int64 |
| 483 | + Name string |
| 484 | + DefaultBranch string |
| 485 | + Owner string |
| 486 | +} |
| 487 | + |
| 488 | +// Lookup the per-repo backfill metadata. Mirrors the row shape of |
| 489 | +// ListAllActiveReposWithOwner so the per-repo job handler can run |
| 490 | +// the same code path the bulk handler uses. |
| 491 | +func (q *Queries) GetRepoForBackfill(ctx context.Context, db DBTX, id int64) (GetRepoForBackfillRow, error) { |
| 492 | + row := db.QueryRow(ctx, getRepoForBackfill, id) |
| 493 | + var i GetRepoForBackfillRow |
| 494 | + err := row.Scan( |
| 495 | + &i.ID, |
| 496 | + &i.Name, |
| 497 | + &i.DefaultBranch, |
| 498 | + &i.Owner, |
| 499 | + ) |
| 500 | + return i, err |
| 501 | +} |
| 502 | + |
| 469 | 503 | const getRepoOwnerUsernameByID = `-- name: GetRepoOwnerUsernameByID :one |
| 470 | 504 | SELECT COALESCE(u.username::varchar, o.slug::varchar) AS owner_username, r.name AS repo_name |
| 471 | 505 | FROM repos r |
@@ -631,6 +665,56 @@ func (q *Queries) InsertRepoTopic(ctx context.Context, db DBTX, arg InsertRepoTo |
| 631 | 665 | return err |
| 632 | 666 | } |
| 633 | 667 | |
| 668 | +const listAllActiveReposWithOwner = `-- name: ListAllActiveReposWithOwner :many |
| 669 | +SELECT |
| 670 | + r.id, |
| 671 | + r.name, |
| 672 | + r.default_branch, |
| 673 | + COALESCE(u.username, o.slug) AS owner |
| 674 | +FROM repos r |
| 675 | +LEFT JOIN users u ON u.id = r.owner_user_id |
| 676 | +LEFT JOIN orgs o ON o.id = r.owner_org_id |
| 677 | +WHERE r.deleted_at IS NULL |
| 678 | +ORDER BY r.id |
| 679 | +` |
| 680 | + |
| 681 | +type ListAllActiveReposWithOwnerRow struct { |
| 682 | + ID int64 |
| 683 | + Name string |
| 684 | + DefaultBranch string |
| 685 | + Owner string |
| 686 | +} |
| 687 | + |
| 688 | +// Used by the GPG verification backfill (S51) to enumerate every |
| 689 | +// active repo system-wide. Unlike ListAllRepoFullNames this query |
| 690 | +// handles BOTH user-owned and org-owned repos via a COALESCE between |
| 691 | +// users.username and orgs.slug; the owner string is whatever |
| 692 | +// RepoFS.RepoPath expects. |
| 693 | +func (q *Queries) ListAllActiveReposWithOwner(ctx context.Context, db DBTX) ([]ListAllActiveReposWithOwnerRow, error) { |
| 694 | + rows, err := db.Query(ctx, listAllActiveReposWithOwner) |
| 695 | + if err != nil { |
| 696 | + return nil, err |
| 697 | + } |
| 698 | + defer rows.Close() |
| 699 | + items := []ListAllActiveReposWithOwnerRow{} |
| 700 | + for rows.Next() { |
| 701 | + var i ListAllActiveReposWithOwnerRow |
| 702 | + if err := rows.Scan( |
| 703 | + &i.ID, |
| 704 | + &i.Name, |
| 705 | + &i.DefaultBranch, |
| 706 | + &i.Owner, |
| 707 | + ); err != nil { |
| 708 | + return nil, err |
| 709 | + } |
| 710 | + items = append(items, i) |
| 711 | + } |
| 712 | + if err := rows.Err(); err != nil { |
| 713 | + return nil, err |
| 714 | + } |
| 715 | + return items, nil |
| 716 | +} |
| 717 | + |
| 634 | 718 | const listAllRepoFullNames = `-- name: ListAllRepoFullNames :many |
| 635 | 719 | SELECT |
| 636 | 720 | r.id, |