Go · 21815 bytes Raw Blame History
1 // Code generated by sqlc. DO NOT EDIT.
2 // versions:
3 // sqlc v1.31.1
4 // source: repos.sql
5
6 package reposdb
7
8 import (
9 "context"
10
11 "github.com/jackc/pgx/v5/pgtype"
12 )
13
14 const countForksOfRepo = `-- name: CountForksOfRepo :one
15 SELECT count(*) FROM repos
16 WHERE fork_of_repo_id = $1 AND deleted_at IS NULL
17 `
18
19 func (q *Queries) CountForksOfRepo(ctx context.Context, db DBTX, forkOfRepoID pgtype.Int8) (int64, error) {
20 row := db.QueryRow(ctx, countForksOfRepo, forkOfRepoID)
21 var count int64
22 err := row.Scan(&count)
23 return count, err
24 }
25
26 const countReposForOwnerUser = `-- name: CountReposForOwnerUser :one
27 SELECT count(*) FROM repos
28 WHERE owner_user_id = $1 AND deleted_at IS NULL
29 `
30
31 func (q *Queries) CountReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) (int64, error) {
32 row := db.QueryRow(ctx, countReposForOwnerUser, ownerUserID)
33 var count int64
34 err := row.Scan(&count)
35 return count, err
36 }
37
38 const createForkRepo = `-- name: CreateForkRepo :one
39
40 INSERT INTO repos (
41 owner_user_id, owner_org_id, name, description, visibility,
42 default_branch, fork_of_repo_id, init_status
43 ) VALUES (
44 $1, $2, $3, $4, $5, $6, $7, 'init_pending'
45 )
46 RETURNING id, owner_user_id, owner_org_id, name, description, visibility,
47 default_branch, is_archived, archived_at, deleted_at,
48 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
49 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
50 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
51 star_count, watcher_count, fork_count, init_status,
52 last_indexed_oid
53 `
54
55 type CreateForkRepoParams struct {
56 OwnerUserID pgtype.Int8
57 OwnerOrgID pgtype.Int8
58 Name string
59 Description string
60 Visibility RepoVisibility
61 DefaultBranch string
62 ForkOfRepoID pgtype.Int8
63 }
64
65 // ─── S27 forks ─────────────────────────────────────────────────────
66 // Insert a fork shell. Distinct from CreateRepo because forks set
67 // `fork_of_repo_id` (which fires the fork_count trigger) and start
68 // at init_status='init_pending' so the worker job can flip them to
69 // 'initialized' once `git clone --bare --shared` finishes.
70 func (q *Queries) CreateForkRepo(ctx context.Context, db DBTX, arg CreateForkRepoParams) (Repo, error) {
71 row := db.QueryRow(ctx, createForkRepo,
72 arg.OwnerUserID,
73 arg.OwnerOrgID,
74 arg.Name,
75 arg.Description,
76 arg.Visibility,
77 arg.DefaultBranch,
78 arg.ForkOfRepoID,
79 )
80 var i Repo
81 err := row.Scan(
82 &i.ID,
83 &i.OwnerUserID,
84 &i.OwnerOrgID,
85 &i.Name,
86 &i.Description,
87 &i.Visibility,
88 &i.DefaultBranch,
89 &i.IsArchived,
90 &i.ArchivedAt,
91 &i.DeletedAt,
92 &i.DiskUsedBytes,
93 &i.ForkOfRepoID,
94 &i.LicenseKey,
95 &i.PrimaryLanguage,
96 &i.HasIssues,
97 &i.HasPulls,
98 &i.CreatedAt,
99 &i.UpdatedAt,
100 &i.DefaultBranchOid,
101 &i.AllowSquashMerge,
102 &i.AllowRebaseMerge,
103 &i.AllowMergeCommit,
104 &i.DefaultMergeMethod,
105 &i.StarCount,
106 &i.WatcherCount,
107 &i.ForkCount,
108 &i.InitStatus,
109 &i.LastIndexedOid,
110 )
111 return i, err
112 }
113
114 const createRepo = `-- name: CreateRepo :one
115
116 INSERT INTO repos (
117 owner_user_id, owner_org_id, name, description, visibility,
118 default_branch, license_key, primary_language
119 ) VALUES (
120 $1, $2, $3, $4, $5, $6, $7, $8
121 )
122 RETURNING id, owner_user_id, owner_org_id, name, description, visibility,
123 default_branch, is_archived, archived_at, deleted_at,
124 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
125 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
126 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
127 star_count, watcher_count, fork_count, init_status,
128 last_indexed_oid
129 `
130
131 type CreateRepoParams struct {
132 OwnerUserID pgtype.Int8
133 OwnerOrgID pgtype.Int8
134 Name string
135 Description string
136 Visibility RepoVisibility
137 DefaultBranch string
138 LicenseKey pgtype.Text
139 PrimaryLanguage pgtype.Text
140 }
141
142 // SPDX-License-Identifier: AGPL-3.0-or-later
143 func (q *Queries) CreateRepo(ctx context.Context, db DBTX, arg CreateRepoParams) (Repo, error) {
144 row := db.QueryRow(ctx, createRepo,
145 arg.OwnerUserID,
146 arg.OwnerOrgID,
147 arg.Name,
148 arg.Description,
149 arg.Visibility,
150 arg.DefaultBranch,
151 arg.LicenseKey,
152 arg.PrimaryLanguage,
153 )
154 var i Repo
155 err := row.Scan(
156 &i.ID,
157 &i.OwnerUserID,
158 &i.OwnerOrgID,
159 &i.Name,
160 &i.Description,
161 &i.Visibility,
162 &i.DefaultBranch,
163 &i.IsArchived,
164 &i.ArchivedAt,
165 &i.DeletedAt,
166 &i.DiskUsedBytes,
167 &i.ForkOfRepoID,
168 &i.LicenseKey,
169 &i.PrimaryLanguage,
170 &i.HasIssues,
171 &i.HasPulls,
172 &i.CreatedAt,
173 &i.UpdatedAt,
174 &i.DefaultBranchOid,
175 &i.AllowSquashMerge,
176 &i.AllowRebaseMerge,
177 &i.AllowMergeCommit,
178 &i.DefaultMergeMethod,
179 &i.StarCount,
180 &i.WatcherCount,
181 &i.ForkCount,
182 &i.InitStatus,
183 &i.LastIndexedOid,
184 )
185 return i, err
186 }
187
188 const existsRepoForOwnerOrg = `-- name: ExistsRepoForOwnerOrg :one
189 SELECT EXISTS(
190 SELECT 1 FROM repos
191 WHERE owner_org_id = $1 AND name = $2 AND deleted_at IS NULL
192 )
193 `
194
195 type ExistsRepoForOwnerOrgParams struct {
196 OwnerOrgID pgtype.Int8
197 Name string
198 }
199
200 func (q *Queries) ExistsRepoForOwnerOrg(ctx context.Context, db DBTX, arg ExistsRepoForOwnerOrgParams) (bool, error) {
201 row := db.QueryRow(ctx, existsRepoForOwnerOrg, arg.OwnerOrgID, arg.Name)
202 var exists bool
203 err := row.Scan(&exists)
204 return exists, err
205 }
206
207 const existsRepoForOwnerUser = `-- name: ExistsRepoForOwnerUser :one
208 SELECT EXISTS(
209 SELECT 1 FROM repos
210 WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL
211 )
212 `
213
214 type ExistsRepoForOwnerUserParams struct {
215 OwnerUserID pgtype.Int8
216 Name string
217 }
218
219 func (q *Queries) ExistsRepoForOwnerUser(ctx context.Context, db DBTX, arg ExistsRepoForOwnerUserParams) (bool, error) {
220 row := db.QueryRow(ctx, existsRepoForOwnerUser, arg.OwnerUserID, arg.Name)
221 var exists bool
222 err := row.Scan(&exists)
223 return exists, err
224 }
225
226 const getRepoByID = `-- name: GetRepoByID :one
227 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
228 default_branch, is_archived, archived_at, deleted_at,
229 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
230 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
231 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
232 star_count, watcher_count, fork_count, init_status,
233 last_indexed_oid
234 FROM repos
235 WHERE id = $1
236 `
237
238 func (q *Queries) GetRepoByID(ctx context.Context, db DBTX, id int64) (Repo, error) {
239 row := db.QueryRow(ctx, getRepoByID, id)
240 var i Repo
241 err := row.Scan(
242 &i.ID,
243 &i.OwnerUserID,
244 &i.OwnerOrgID,
245 &i.Name,
246 &i.Description,
247 &i.Visibility,
248 &i.DefaultBranch,
249 &i.IsArchived,
250 &i.ArchivedAt,
251 &i.DeletedAt,
252 &i.DiskUsedBytes,
253 &i.ForkOfRepoID,
254 &i.LicenseKey,
255 &i.PrimaryLanguage,
256 &i.HasIssues,
257 &i.HasPulls,
258 &i.CreatedAt,
259 &i.UpdatedAt,
260 &i.DefaultBranchOid,
261 &i.AllowSquashMerge,
262 &i.AllowRebaseMerge,
263 &i.AllowMergeCommit,
264 &i.DefaultMergeMethod,
265 &i.StarCount,
266 &i.WatcherCount,
267 &i.ForkCount,
268 &i.InitStatus,
269 &i.LastIndexedOid,
270 )
271 return i, err
272 }
273
274 const getRepoByOwnerOrgAndName = `-- name: GetRepoByOwnerOrgAndName :one
275 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
276 default_branch, is_archived, archived_at, deleted_at,
277 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
278 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
279 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
280 star_count, watcher_count, fork_count, init_status,
281 last_indexed_oid
282 FROM repos
283 WHERE owner_org_id = $1 AND name = $2 AND deleted_at IS NULL
284 `
285
286 type GetRepoByOwnerOrgAndNameParams struct {
287 OwnerOrgID pgtype.Int8
288 Name string
289 }
290
291 // S30: org-owner mirror of GetRepoByOwnerUserAndName. The (owner_org_id,
292 // name) partial unique index from 0017 backs this lookup with the same
293 // O(1) cost the user-side path enjoys.
294 func (q *Queries) GetRepoByOwnerOrgAndName(ctx context.Context, db DBTX, arg GetRepoByOwnerOrgAndNameParams) (Repo, error) {
295 row := db.QueryRow(ctx, getRepoByOwnerOrgAndName, arg.OwnerOrgID, arg.Name)
296 var i Repo
297 err := row.Scan(
298 &i.ID,
299 &i.OwnerUserID,
300 &i.OwnerOrgID,
301 &i.Name,
302 &i.Description,
303 &i.Visibility,
304 &i.DefaultBranch,
305 &i.IsArchived,
306 &i.ArchivedAt,
307 &i.DeletedAt,
308 &i.DiskUsedBytes,
309 &i.ForkOfRepoID,
310 &i.LicenseKey,
311 &i.PrimaryLanguage,
312 &i.HasIssues,
313 &i.HasPulls,
314 &i.CreatedAt,
315 &i.UpdatedAt,
316 &i.DefaultBranchOid,
317 &i.AllowSquashMerge,
318 &i.AllowRebaseMerge,
319 &i.AllowMergeCommit,
320 &i.DefaultMergeMethod,
321 &i.StarCount,
322 &i.WatcherCount,
323 &i.ForkCount,
324 &i.InitStatus,
325 &i.LastIndexedOid,
326 )
327 return i, err
328 }
329
330 const getRepoByOwnerUserAndName = `-- name: GetRepoByOwnerUserAndName :one
331 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
332 default_branch, is_archived, archived_at, deleted_at,
333 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
334 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
335 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
336 star_count, watcher_count, fork_count, init_status,
337 last_indexed_oid
338 FROM repos
339 WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL
340 `
341
342 type GetRepoByOwnerUserAndNameParams struct {
343 OwnerUserID pgtype.Int8
344 Name string
345 }
346
347 func (q *Queries) GetRepoByOwnerUserAndName(ctx context.Context, db DBTX, arg GetRepoByOwnerUserAndNameParams) (Repo, error) {
348 row := db.QueryRow(ctx, getRepoByOwnerUserAndName, arg.OwnerUserID, arg.Name)
349 var i Repo
350 err := row.Scan(
351 &i.ID,
352 &i.OwnerUserID,
353 &i.OwnerOrgID,
354 &i.Name,
355 &i.Description,
356 &i.Visibility,
357 &i.DefaultBranch,
358 &i.IsArchived,
359 &i.ArchivedAt,
360 &i.DeletedAt,
361 &i.DiskUsedBytes,
362 &i.ForkOfRepoID,
363 &i.LicenseKey,
364 &i.PrimaryLanguage,
365 &i.HasIssues,
366 &i.HasPulls,
367 &i.CreatedAt,
368 &i.UpdatedAt,
369 &i.DefaultBranchOid,
370 &i.AllowSquashMerge,
371 &i.AllowRebaseMerge,
372 &i.AllowMergeCommit,
373 &i.DefaultMergeMethod,
374 &i.StarCount,
375 &i.WatcherCount,
376 &i.ForkCount,
377 &i.InitStatus,
378 &i.LastIndexedOid,
379 )
380 return i, err
381 }
382
383 const getRepoOwnerUsernameByID = `-- name: GetRepoOwnerUsernameByID :one
384 SELECT u.username AS owner_username, r.name AS repo_name
385 FROM repos r
386 JOIN users u ON u.id = r.owner_user_id
387 WHERE r.id = $1
388 `
389
390 type GetRepoOwnerUsernameByIDRow struct {
391 OwnerUsername string
392 RepoName string
393 }
394
395 // Returns the owner_username for a repo. Used by size-recalc and other
396 // jobs that need to derive the bare-repo on-disk path without round-
397 // tripping through the full user row.
398 func (q *Queries) GetRepoOwnerUsernameByID(ctx context.Context, db DBTX, id int64) (GetRepoOwnerUsernameByIDRow, error) {
399 row := db.QueryRow(ctx, getRepoOwnerUsernameByID, id)
400 var i GetRepoOwnerUsernameByIDRow
401 err := row.Scan(&i.OwnerUsername, &i.RepoName)
402 return i, err
403 }
404
405 const listAllRepoFullNames = `-- name: ListAllRepoFullNames :many
406 SELECT
407 r.id,
408 r.name,
409 u.username AS owner_username
410 FROM repos r
411 JOIN users u ON u.id = r.owner_user_id
412 WHERE r.deleted_at IS NULL
413 ORDER BY r.id
414 `
415
416 type ListAllRepoFullNamesRow struct {
417 ID int64
418 Name string
419 OwnerUsername string
420 }
421
422 // Used by `shithubd hooks reinstall --all` to enumerate every active
423 // bare repo on disk and re-link its hooks.
424 func (q *Queries) ListAllRepoFullNames(ctx context.Context, db DBTX) ([]ListAllRepoFullNamesRow, error) {
425 rows, err := db.Query(ctx, listAllRepoFullNames)
426 if err != nil {
427 return nil, err
428 }
429 defer rows.Close()
430 items := []ListAllRepoFullNamesRow{}
431 for rows.Next() {
432 var i ListAllRepoFullNamesRow
433 if err := rows.Scan(&i.ID, &i.Name, &i.OwnerUsername); err != nil {
434 return nil, err
435 }
436 items = append(items, i)
437 }
438 if err := rows.Err(); err != nil {
439 return nil, err
440 }
441 return items, nil
442 }
443
444 const listForksOfRepo = `-- name: ListForksOfRepo :many
445 SELECT r.id, r.name, r.description, r.visibility, r.created_at,
446 r.star_count, r.fork_count, r.init_status,
447 u.username AS owner_username, u.display_name AS owner_display_name
448 FROM repos r
449 JOIN users u ON u.id = r.owner_user_id
450 WHERE r.fork_of_repo_id = $1
451 AND r.deleted_at IS NULL
452 ORDER BY r.created_at DESC
453 LIMIT $2 OFFSET $3
454 `
455
456 type ListForksOfRepoParams struct {
457 ForkOfRepoID pgtype.Int8
458 Limit int32
459 Offset int32
460 }
461
462 type ListForksOfRepoRow struct {
463 ID int64
464 Name string
465 Description string
466 Visibility RepoVisibility
467 CreatedAt pgtype.Timestamptz
468 StarCount int64
469 ForkCount int64
470 InitStatus RepoInitStatus
471 OwnerUsername string
472 OwnerDisplayName string
473 }
474
475 // Forks of a given source repo, paginated, recency-sorted. Joined
476 // with users for the owner display name. Excludes soft-deleted.
477 func (q *Queries) ListForksOfRepo(ctx context.Context, db DBTX, arg ListForksOfRepoParams) ([]ListForksOfRepoRow, error) {
478 rows, err := db.Query(ctx, listForksOfRepo, arg.ForkOfRepoID, arg.Limit, arg.Offset)
479 if err != nil {
480 return nil, err
481 }
482 defer rows.Close()
483 items := []ListForksOfRepoRow{}
484 for rows.Next() {
485 var i ListForksOfRepoRow
486 if err := rows.Scan(
487 &i.ID,
488 &i.Name,
489 &i.Description,
490 &i.Visibility,
491 &i.CreatedAt,
492 &i.StarCount,
493 &i.ForkCount,
494 &i.InitStatus,
495 &i.OwnerUsername,
496 &i.OwnerDisplayName,
497 ); err != nil {
498 return nil, err
499 }
500 items = append(items, i)
501 }
502 if err := rows.Err(); err != nil {
503 return nil, err
504 }
505 return items, nil
506 }
507
508 const listForksOfRepoForRepack = `-- name: ListForksOfRepoForRepack :many
509 SELECT r.id, r.name, u.username AS owner_username
510 FROM repos r
511 JOIN users u ON u.id = r.owner_user_id
512 WHERE r.fork_of_repo_id = $1
513 AND r.deleted_at IS NULL
514 `
515
516 type ListForksOfRepoForRepackRow struct {
517 ID int64
518 Name string
519 OwnerUsername string
520 }
521
522 // Used by S16's hard-delete cascade (S27 amendment): before deleting
523 // a source repo, every fork must `git repack -a -d --no-shared` so
524 // it has its own copy of the objects. Returns just enough to locate
525 // the bare repo on disk.
526 func (q *Queries) ListForksOfRepoForRepack(ctx context.Context, db DBTX, forkOfRepoID pgtype.Int8) ([]ListForksOfRepoForRepackRow, error) {
527 rows, err := db.Query(ctx, listForksOfRepoForRepack, forkOfRepoID)
528 if err != nil {
529 return nil, err
530 }
531 defer rows.Close()
532 items := []ListForksOfRepoForRepackRow{}
533 for rows.Next() {
534 var i ListForksOfRepoForRepackRow
535 if err := rows.Scan(&i.ID, &i.Name, &i.OwnerUsername); err != nil {
536 return nil, err
537 }
538 items = append(items, i)
539 }
540 if err := rows.Err(); err != nil {
541 return nil, err
542 }
543 return items, nil
544 }
545
546 const listReposForOwnerOrg = `-- name: ListReposForOwnerOrg :many
547 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
548 default_branch, is_archived, archived_at, deleted_at,
549 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
550 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
551 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
552 star_count, watcher_count, fork_count, init_status,
553 last_indexed_oid
554 FROM repos
555 WHERE owner_org_id = $1 AND deleted_at IS NULL
556 ORDER BY updated_at DESC
557 `
558
559 func (q *Queries) ListReposForOwnerOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) ([]Repo, error) {
560 rows, err := db.Query(ctx, listReposForOwnerOrg, ownerOrgID)
561 if err != nil {
562 return nil, err
563 }
564 defer rows.Close()
565 items := []Repo{}
566 for rows.Next() {
567 var i Repo
568 if err := rows.Scan(
569 &i.ID,
570 &i.OwnerUserID,
571 &i.OwnerOrgID,
572 &i.Name,
573 &i.Description,
574 &i.Visibility,
575 &i.DefaultBranch,
576 &i.IsArchived,
577 &i.ArchivedAt,
578 &i.DeletedAt,
579 &i.DiskUsedBytes,
580 &i.ForkOfRepoID,
581 &i.LicenseKey,
582 &i.PrimaryLanguage,
583 &i.HasIssues,
584 &i.HasPulls,
585 &i.CreatedAt,
586 &i.UpdatedAt,
587 &i.DefaultBranchOid,
588 &i.AllowSquashMerge,
589 &i.AllowRebaseMerge,
590 &i.AllowMergeCommit,
591 &i.DefaultMergeMethod,
592 &i.StarCount,
593 &i.WatcherCount,
594 &i.ForkCount,
595 &i.InitStatus,
596 &i.LastIndexedOid,
597 ); err != nil {
598 return nil, err
599 }
600 items = append(items, i)
601 }
602 if err := rows.Err(); err != nil {
603 return nil, err
604 }
605 return items, nil
606 }
607
608 const listReposForOwnerUser = `-- name: ListReposForOwnerUser :many
609 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
610 default_branch, is_archived, archived_at, deleted_at,
611 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
612 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
613 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
614 star_count, watcher_count, fork_count, init_status,
615 last_indexed_oid
616 FROM repos
617 WHERE owner_user_id = $1 AND deleted_at IS NULL
618 ORDER BY updated_at DESC
619 `
620
621 func (q *Queries) ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) ([]Repo, error) {
622 rows, err := db.Query(ctx, listReposForOwnerUser, ownerUserID)
623 if err != nil {
624 return nil, err
625 }
626 defer rows.Close()
627 items := []Repo{}
628 for rows.Next() {
629 var i Repo
630 if err := rows.Scan(
631 &i.ID,
632 &i.OwnerUserID,
633 &i.OwnerOrgID,
634 &i.Name,
635 &i.Description,
636 &i.Visibility,
637 &i.DefaultBranch,
638 &i.IsArchived,
639 &i.ArchivedAt,
640 &i.DeletedAt,
641 &i.DiskUsedBytes,
642 &i.ForkOfRepoID,
643 &i.LicenseKey,
644 &i.PrimaryLanguage,
645 &i.HasIssues,
646 &i.HasPulls,
647 &i.CreatedAt,
648 &i.UpdatedAt,
649 &i.DefaultBranchOid,
650 &i.AllowSquashMerge,
651 &i.AllowRebaseMerge,
652 &i.AllowMergeCommit,
653 &i.DefaultMergeMethod,
654 &i.StarCount,
655 &i.WatcherCount,
656 &i.ForkCount,
657 &i.InitStatus,
658 &i.LastIndexedOid,
659 ); err != nil {
660 return nil, err
661 }
662 items = append(items, i)
663 }
664 if err := rows.Err(); err != nil {
665 return nil, err
666 }
667 return items, nil
668 }
669
670 const listReposNeedingReindex = `-- name: ListReposNeedingReindex :many
671 SELECT id, name, default_branch, default_branch_oid
672 FROM repos
673 WHERE deleted_at IS NULL
674 AND default_branch_oid IS NOT NULL
675 AND (last_indexed_oid IS NULL OR last_indexed_oid <> default_branch_oid)
676 ORDER BY id
677 LIMIT $1
678 `
679
680 type ListReposNeedingReindexRow struct {
681 ID int64
682 Name string
683 DefaultBranch string
684 DefaultBranchOid pgtype.Text
685 }
686
687 // S28 code-search reconciler: returns repos whose default_branch_oid
688 // has advanced past last_indexed_oid (or last_indexed_oid is NULL
689 // and a default exists). Limited so a single tick of the cron
690 // doesn't try to re-index the whole world.
691 func (q *Queries) ListReposNeedingReindex(ctx context.Context, db DBTX, limit int32) ([]ListReposNeedingReindexRow, error) {
692 rows, err := db.Query(ctx, listReposNeedingReindex, limit)
693 if err != nil {
694 return nil, err
695 }
696 defer rows.Close()
697 items := []ListReposNeedingReindexRow{}
698 for rows.Next() {
699 var i ListReposNeedingReindexRow
700 if err := rows.Scan(
701 &i.ID,
702 &i.Name,
703 &i.DefaultBranch,
704 &i.DefaultBranchOid,
705 ); err != nil {
706 return nil, err
707 }
708 items = append(items, i)
709 }
710 if err := rows.Err(); err != nil {
711 return nil, err
712 }
713 return items, nil
714 }
715
716 const setLastIndexedOID = `-- name: SetLastIndexedOID :exec
717 UPDATE repos SET last_indexed_oid = $2::text WHERE id = $1
718 `
719
720 type SetLastIndexedOIDParams struct {
721 ID int64
722 LastIndexedOid pgtype.Text
723 }
724
725 // S28 code-search: the worker writes the OID it finished indexing
726 // so the reconciler can detect drift (default_branch_oid moved but
727 // last_indexed_oid lagged).
728 func (q *Queries) SetLastIndexedOID(ctx context.Context, db DBTX, arg SetLastIndexedOIDParams) error {
729 _, err := db.Exec(ctx, setLastIndexedOID, arg.ID, arg.LastIndexedOid)
730 return err
731 }
732
733 const setRepoInitStatus = `-- name: SetRepoInitStatus :exec
734 UPDATE repos SET init_status = $2 WHERE id = $1
735 `
736
737 type SetRepoInitStatusParams struct {
738 ID int64
739 InitStatus RepoInitStatus
740 }
741
742 // Promotes a fork from init_pending to initialized (or init_failed).
743 // The DB row is created up-front so the URL resolves immediately and
744 // the user sees a "preparing your fork" placeholder while the worker
745 // runs `git clone --bare --shared`.
746 func (q *Queries) SetRepoInitStatus(ctx context.Context, db DBTX, arg SetRepoInitStatusParams) error {
747 _, err := db.Exec(ctx, setRepoInitStatus, arg.ID, arg.InitStatus)
748 return err
749 }
750
751 const softDeleteRepo = `-- name: SoftDeleteRepo :exec
752 UPDATE repos SET deleted_at = now() WHERE id = $1
753 `
754
755 func (q *Queries) SoftDeleteRepo(ctx context.Context, db DBTX, id int64) error {
756 _, err := db.Exec(ctx, softDeleteRepo, id)
757 return err
758 }
759
760 const updateRepoDefaultBranchOID = `-- name: UpdateRepoDefaultBranchOID :exec
761 UPDATE repos SET default_branch_oid = $2::text WHERE id = $1
762 `
763
764 type UpdateRepoDefaultBranchOIDParams struct {
765 ID int64
766 DefaultBranchOid pgtype.Text
767 }
768
769 // Set when push:process detects a commit on the repo's default branch.
770 // Pass NULL to clear (e.g. when the branch is force-deleted in a future
771 // sprint). The repo home view reads this to decide between empty and
772 // populated layouts.
773 func (q *Queries) UpdateRepoDefaultBranchOID(ctx context.Context, db DBTX, arg UpdateRepoDefaultBranchOIDParams) error {
774 _, err := db.Exec(ctx, updateRepoDefaultBranchOID, arg.ID, arg.DefaultBranchOid)
775 return err
776 }
777
778 const updateRepoDiskUsed = `-- name: UpdateRepoDiskUsed :exec
779 UPDATE repos SET disk_used_bytes = $2 WHERE id = $1
780 `
781
782 type UpdateRepoDiskUsedParams struct {
783 ID int64
784 DiskUsedBytes int64
785 }
786
787 func (q *Queries) UpdateRepoDiskUsed(ctx context.Context, db DBTX, arg UpdateRepoDiskUsedParams) error {
788 _, err := db.Exec(ctx, updateRepoDiskUsed, arg.ID, arg.DiskUsedBytes)
789 return err
790 }
791