Go · 48808 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 adminForceDeleteRepo = `-- name: AdminForceDeleteRepo :exec
15 UPDATE repos SET deleted_at = now() - interval '1 year' WHERE id = $1
16 `
17
18 // Bypasses the soft-delete grace window (admin only — S34): set
19 // deleted_at to a year ago so the next lifecycle sweep hard-deletes
20 // without waiting. Replaces the inline UPDATE in admin/repos.go
21 // (SR2 M2).
22 func (q *Queries) AdminForceDeleteRepo(ctx context.Context, db DBTX, id int64) error {
23 _, err := db.Exec(ctx, adminForceDeleteRepo, id)
24 return err
25 }
26
27 const countForksOfRepo = `-- name: CountForksOfRepo :one
28 SELECT count(*) FROM repos
29 WHERE fork_of_repo_id = $1 AND deleted_at IS NULL
30 `
31
32 func (q *Queries) CountForksOfRepo(ctx context.Context, db DBTX, forkOfRepoID pgtype.Int8) (int64, error) {
33 row := db.QueryRow(ctx, countForksOfRepo, forkOfRepoID)
34 var count int64
35 err := row.Scan(&count)
36 return count, err
37 }
38
39 const countPublicReposForOwnerOrg = `-- name: CountPublicReposForOwnerOrg :one
40 SELECT count(*) FROM repos
41 WHERE owner_org_id = $1
42 AND visibility = 'public'
43 AND deleted_at IS NULL
44 `
45
46 func (q *Queries) CountPublicReposForOwnerOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) (int64, error) {
47 row := db.QueryRow(ctx, countPublicReposForOwnerOrg, ownerOrgID)
48 var count int64
49 err := row.Scan(&count)
50 return count, err
51 }
52
53 const countPublicReposForOwnerUser = `-- name: CountPublicReposForOwnerUser :one
54 SELECT count(*) FROM repos
55 WHERE owner_user_id = $1
56 AND visibility = 'public'
57 AND deleted_at IS NULL
58 `
59
60 func (q *Queries) CountPublicReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) (int64, error) {
61 row := db.QueryRow(ctx, countPublicReposForOwnerUser, ownerUserID)
62 var count int64
63 err := row.Scan(&count)
64 return count, err
65 }
66
67 const countReposForOwnerOrg = `-- name: CountReposForOwnerOrg :one
68 SELECT count(*) FROM repos
69 WHERE owner_org_id = $1 AND deleted_at IS NULL
70 `
71
72 func (q *Queries) CountReposForOwnerOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) (int64, error) {
73 row := db.QueryRow(ctx, countReposForOwnerOrg, ownerOrgID)
74 var count int64
75 err := row.Scan(&count)
76 return count, err
77 }
78
79 const countReposForOwnerUser = `-- name: CountReposForOwnerUser :one
80 SELECT count(*) FROM repos
81 WHERE owner_user_id = $1 AND deleted_at IS NULL
82 `
83
84 func (q *Queries) CountReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) (int64, error) {
85 row := db.QueryRow(ctx, countReposForOwnerUser, ownerUserID)
86 var count int64
87 err := row.Scan(&count)
88 return count, err
89 }
90
91 const createForkRepo = `-- name: CreateForkRepo :one
92
93 INSERT INTO repos (
94 owner_user_id, owner_org_id, name, description, visibility,
95 default_branch, fork_of_repo_id, init_status
96 ) VALUES (
97 $1, $2, $3, $4, $5, $6, $7, 'init_pending'
98 )
99 RETURNING id, owner_user_id, owner_org_id, name, description, visibility,
100 default_branch, is_archived, archived_at, deleted_at,
101 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
102 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
103 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
104 star_count, watcher_count, fork_count, init_status,
105 last_indexed_oid
106 `
107
108 type CreateForkRepoParams struct {
109 OwnerUserID pgtype.Int8
110 OwnerOrgID pgtype.Int8
111 Name string
112 Description string
113 Visibility RepoVisibility
114 DefaultBranch string
115 ForkOfRepoID pgtype.Int8
116 }
117
118 // ─── S27 forks ─────────────────────────────────────────────────────
119 // Insert a fork shell. Distinct from CreateRepo because forks set
120 // `fork_of_repo_id` (which fires the fork_count trigger) and start
121 // at init_status='init_pending' so the worker job can flip them to
122 // 'initialized' once `git clone --bare --shared` finishes.
123 func (q *Queries) CreateForkRepo(ctx context.Context, db DBTX, arg CreateForkRepoParams) (Repo, error) {
124 row := db.QueryRow(ctx, createForkRepo,
125 arg.OwnerUserID,
126 arg.OwnerOrgID,
127 arg.Name,
128 arg.Description,
129 arg.Visibility,
130 arg.DefaultBranch,
131 arg.ForkOfRepoID,
132 )
133 var i Repo
134 err := row.Scan(
135 &i.ID,
136 &i.OwnerUserID,
137 &i.OwnerOrgID,
138 &i.Name,
139 &i.Description,
140 &i.Visibility,
141 &i.DefaultBranch,
142 &i.IsArchived,
143 &i.ArchivedAt,
144 &i.DeletedAt,
145 &i.DiskUsedBytes,
146 &i.ForkOfRepoID,
147 &i.LicenseKey,
148 &i.PrimaryLanguage,
149 &i.HasIssues,
150 &i.HasPulls,
151 &i.CreatedAt,
152 &i.UpdatedAt,
153 &i.DefaultBranchOid,
154 &i.AllowSquashMerge,
155 &i.AllowRebaseMerge,
156 &i.AllowMergeCommit,
157 &i.DefaultMergeMethod,
158 &i.StarCount,
159 &i.WatcherCount,
160 &i.ForkCount,
161 &i.InitStatus,
162 &i.LastIndexedOid,
163 )
164 return i, err
165 }
166
167 const createRepo = `-- name: CreateRepo :one
168
169 INSERT INTO repos (
170 owner_user_id, owner_org_id, name, description, visibility,
171 default_branch, license_key, primary_language
172 ) VALUES (
173 $1, $2, $3, $4, $5, $6, $7, $8
174 )
175 RETURNING id, owner_user_id, owner_org_id, name, description, visibility,
176 default_branch, is_archived, archived_at, deleted_at,
177 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
178 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
179 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
180 star_count, watcher_count, fork_count, init_status,
181 last_indexed_oid
182 `
183
184 type CreateRepoParams struct {
185 OwnerUserID pgtype.Int8
186 OwnerOrgID pgtype.Int8
187 Name string
188 Description string
189 Visibility RepoVisibility
190 DefaultBranch string
191 LicenseKey pgtype.Text
192 PrimaryLanguage pgtype.Text
193 }
194
195 // SPDX-License-Identifier: AGPL-3.0-or-later
196 func (q *Queries) CreateRepo(ctx context.Context, db DBTX, arg CreateRepoParams) (Repo, error) {
197 row := db.QueryRow(ctx, createRepo,
198 arg.OwnerUserID,
199 arg.OwnerOrgID,
200 arg.Name,
201 arg.Description,
202 arg.Visibility,
203 arg.DefaultBranch,
204 arg.LicenseKey,
205 arg.PrimaryLanguage,
206 )
207 var i Repo
208 err := row.Scan(
209 &i.ID,
210 &i.OwnerUserID,
211 &i.OwnerOrgID,
212 &i.Name,
213 &i.Description,
214 &i.Visibility,
215 &i.DefaultBranch,
216 &i.IsArchived,
217 &i.ArchivedAt,
218 &i.DeletedAt,
219 &i.DiskUsedBytes,
220 &i.ForkOfRepoID,
221 &i.LicenseKey,
222 &i.PrimaryLanguage,
223 &i.HasIssues,
224 &i.HasPulls,
225 &i.CreatedAt,
226 &i.UpdatedAt,
227 &i.DefaultBranchOid,
228 &i.AllowSquashMerge,
229 &i.AllowRebaseMerge,
230 &i.AllowMergeCommit,
231 &i.DefaultMergeMethod,
232 &i.StarCount,
233 &i.WatcherCount,
234 &i.ForkCount,
235 &i.InitStatus,
236 &i.LastIndexedOid,
237 )
238 return i, err
239 }
240
241 const deleteProfilePinsForSet = `-- name: DeleteProfilePinsForSet :exec
242 DELETE FROM profile_pins WHERE set_id = $1
243 `
244
245 func (q *Queries) DeleteProfilePinsForSet(ctx context.Context, db DBTX, setID int64) error {
246 _, err := db.Exec(ctx, deleteProfilePinsForSet, setID)
247 return err
248 }
249
250 const existsRepoForOwnerOrg = `-- name: ExistsRepoForOwnerOrg :one
251 SELECT EXISTS(
252 SELECT 1 FROM repos
253 WHERE owner_org_id = $1 AND name = $2 AND deleted_at IS NULL
254 )
255 `
256
257 type ExistsRepoForOwnerOrgParams struct {
258 OwnerOrgID pgtype.Int8
259 Name string
260 }
261
262 func (q *Queries) ExistsRepoForOwnerOrg(ctx context.Context, db DBTX, arg ExistsRepoForOwnerOrgParams) (bool, error) {
263 row := db.QueryRow(ctx, existsRepoForOwnerOrg, arg.OwnerOrgID, arg.Name)
264 var exists bool
265 err := row.Scan(&exists)
266 return exists, err
267 }
268
269 const existsRepoForOwnerUser = `-- name: ExistsRepoForOwnerUser :one
270 SELECT EXISTS(
271 SELECT 1 FROM repos
272 WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL
273 )
274 `
275
276 type ExistsRepoForOwnerUserParams struct {
277 OwnerUserID pgtype.Int8
278 Name string
279 }
280
281 func (q *Queries) ExistsRepoForOwnerUser(ctx context.Context, db DBTX, arg ExistsRepoForOwnerUserParams) (bool, error) {
282 row := db.QueryRow(ctx, existsRepoForOwnerUser, arg.OwnerUserID, arg.Name)
283 var exists bool
284 err := row.Scan(&exists)
285 return exists, err
286 }
287
288 const getProfilePinSetForOrg = `-- name: GetProfilePinSetForOrg :one
289 SELECT id FROM profile_pin_sets WHERE owner_org_id = $1
290 `
291
292 func (q *Queries) GetProfilePinSetForOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) (int64, error) {
293 row := db.QueryRow(ctx, getProfilePinSetForOrg, ownerOrgID)
294 var id int64
295 err := row.Scan(&id)
296 return id, err
297 }
298
299 const getProfilePinSetForUser = `-- name: GetProfilePinSetForUser :one
300
301 SELECT id FROM profile_pin_sets WHERE owner_user_id = $1
302 `
303
304 // ─── profile/org pinned repositories ───────────────────────────────
305 func (q *Queries) GetProfilePinSetForUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) (int64, error) {
306 row := db.QueryRow(ctx, getProfilePinSetForUser, ownerUserID)
307 var id int64
308 err := row.Scan(&id)
309 return id, err
310 }
311
312 const getRepoByID = `-- name: GetRepoByID :one
313 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
314 default_branch, is_archived, archived_at, deleted_at,
315 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
316 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
317 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
318 star_count, watcher_count, fork_count, init_status,
319 last_indexed_oid
320 FROM repos
321 WHERE id = $1
322 `
323
324 func (q *Queries) GetRepoByID(ctx context.Context, db DBTX, id int64) (Repo, error) {
325 row := db.QueryRow(ctx, getRepoByID, id)
326 var i Repo
327 err := row.Scan(
328 &i.ID,
329 &i.OwnerUserID,
330 &i.OwnerOrgID,
331 &i.Name,
332 &i.Description,
333 &i.Visibility,
334 &i.DefaultBranch,
335 &i.IsArchived,
336 &i.ArchivedAt,
337 &i.DeletedAt,
338 &i.DiskUsedBytes,
339 &i.ForkOfRepoID,
340 &i.LicenseKey,
341 &i.PrimaryLanguage,
342 &i.HasIssues,
343 &i.HasPulls,
344 &i.CreatedAt,
345 &i.UpdatedAt,
346 &i.DefaultBranchOid,
347 &i.AllowSquashMerge,
348 &i.AllowRebaseMerge,
349 &i.AllowMergeCommit,
350 &i.DefaultMergeMethod,
351 &i.StarCount,
352 &i.WatcherCount,
353 &i.ForkCount,
354 &i.InitStatus,
355 &i.LastIndexedOid,
356 )
357 return i, err
358 }
359
360 const getRepoByOwnerOrgAndName = `-- name: GetRepoByOwnerOrgAndName :one
361 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
362 default_branch, is_archived, archived_at, deleted_at,
363 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
364 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
365 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
366 star_count, watcher_count, fork_count, init_status,
367 last_indexed_oid
368 FROM repos
369 WHERE owner_org_id = $1 AND name = $2 AND deleted_at IS NULL
370 `
371
372 type GetRepoByOwnerOrgAndNameParams struct {
373 OwnerOrgID pgtype.Int8
374 Name string
375 }
376
377 // S30: org-owner mirror of GetRepoByOwnerUserAndName. The (owner_org_id,
378 // name) partial unique index from 0017 backs this lookup with the same
379 // O(1) cost the user-side path enjoys.
380 func (q *Queries) GetRepoByOwnerOrgAndName(ctx context.Context, db DBTX, arg GetRepoByOwnerOrgAndNameParams) (Repo, error) {
381 row := db.QueryRow(ctx, getRepoByOwnerOrgAndName, arg.OwnerOrgID, arg.Name)
382 var i Repo
383 err := row.Scan(
384 &i.ID,
385 &i.OwnerUserID,
386 &i.OwnerOrgID,
387 &i.Name,
388 &i.Description,
389 &i.Visibility,
390 &i.DefaultBranch,
391 &i.IsArchived,
392 &i.ArchivedAt,
393 &i.DeletedAt,
394 &i.DiskUsedBytes,
395 &i.ForkOfRepoID,
396 &i.LicenseKey,
397 &i.PrimaryLanguage,
398 &i.HasIssues,
399 &i.HasPulls,
400 &i.CreatedAt,
401 &i.UpdatedAt,
402 &i.DefaultBranchOid,
403 &i.AllowSquashMerge,
404 &i.AllowRebaseMerge,
405 &i.AllowMergeCommit,
406 &i.DefaultMergeMethod,
407 &i.StarCount,
408 &i.WatcherCount,
409 &i.ForkCount,
410 &i.InitStatus,
411 &i.LastIndexedOid,
412 )
413 return i, err
414 }
415
416 const getRepoByOwnerUserAndName = `-- name: GetRepoByOwnerUserAndName :one
417 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
418 default_branch, is_archived, archived_at, deleted_at,
419 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
420 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
421 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
422 star_count, watcher_count, fork_count, init_status,
423 last_indexed_oid
424 FROM repos
425 WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL
426 `
427
428 type GetRepoByOwnerUserAndNameParams struct {
429 OwnerUserID pgtype.Int8
430 Name string
431 }
432
433 func (q *Queries) GetRepoByOwnerUserAndName(ctx context.Context, db DBTX, arg GetRepoByOwnerUserAndNameParams) (Repo, error) {
434 row := db.QueryRow(ctx, getRepoByOwnerUserAndName, arg.OwnerUserID, arg.Name)
435 var i Repo
436 err := row.Scan(
437 &i.ID,
438 &i.OwnerUserID,
439 &i.OwnerOrgID,
440 &i.Name,
441 &i.Description,
442 &i.Visibility,
443 &i.DefaultBranch,
444 &i.IsArchived,
445 &i.ArchivedAt,
446 &i.DeletedAt,
447 &i.DiskUsedBytes,
448 &i.ForkOfRepoID,
449 &i.LicenseKey,
450 &i.PrimaryLanguage,
451 &i.HasIssues,
452 &i.HasPulls,
453 &i.CreatedAt,
454 &i.UpdatedAt,
455 &i.DefaultBranchOid,
456 &i.AllowSquashMerge,
457 &i.AllowRebaseMerge,
458 &i.AllowMergeCommit,
459 &i.DefaultMergeMethod,
460 &i.StarCount,
461 &i.WatcherCount,
462 &i.ForkCount,
463 &i.InitStatus,
464 &i.LastIndexedOid,
465 )
466 return i, err
467 }
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
503 const getRepoOwnerUsernameByID = `-- name: GetRepoOwnerUsernameByID :one
504 SELECT COALESCE(u.username::varchar, o.slug::varchar) AS owner_username, r.name AS repo_name
505 FROM repos r
506 LEFT JOIN users u ON u.id = r.owner_user_id
507 LEFT JOIN orgs o ON o.id = r.owner_org_id
508 WHERE r.id = $1
509 `
510
511 type GetRepoOwnerUsernameByIDRow struct {
512 OwnerUsername interface{}
513 RepoName string
514 }
515
516 // Returns the owner slug for a repo. Used by size-recalc, indexing, and
517 // other jobs that need the bare-repo on-disk path. Org-owned repos use the
518 // org slug in the same path position as user-owned repos.
519 func (q *Queries) GetRepoOwnerUsernameByID(ctx context.Context, db DBTX, id int64) (GetRepoOwnerUsernameByIDRow, error) {
520 row := db.QueryRow(ctx, getRepoOwnerUsernameByID, id)
521 var i GetRepoOwnerUsernameByIDRow
522 err := row.Scan(&i.OwnerUsername, &i.RepoName)
523 return i, err
524 }
525
526 const getSoftDeletedRepoByOwnerOrgAndName = `-- name: GetSoftDeletedRepoByOwnerOrgAndName :one
527 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
528 default_branch, is_archived, archived_at, deleted_at,
529 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
530 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
531 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
532 star_count, watcher_count, fork_count, init_status,
533 last_indexed_oid
534 FROM repos
535 WHERE owner_org_id = $1 AND name = $2 AND deleted_at IS NOT NULL
536 ORDER BY deleted_at DESC, id DESC
537 LIMIT 1
538 `
539
540 type GetSoftDeletedRepoByOwnerOrgAndNameParams struct {
541 OwnerOrgID pgtype.Int8
542 Name string
543 }
544
545 func (q *Queries) GetSoftDeletedRepoByOwnerOrgAndName(ctx context.Context, db DBTX, arg GetSoftDeletedRepoByOwnerOrgAndNameParams) (Repo, error) {
546 row := db.QueryRow(ctx, getSoftDeletedRepoByOwnerOrgAndName, arg.OwnerOrgID, arg.Name)
547 var i Repo
548 err := row.Scan(
549 &i.ID,
550 &i.OwnerUserID,
551 &i.OwnerOrgID,
552 &i.Name,
553 &i.Description,
554 &i.Visibility,
555 &i.DefaultBranch,
556 &i.IsArchived,
557 &i.ArchivedAt,
558 &i.DeletedAt,
559 &i.DiskUsedBytes,
560 &i.ForkOfRepoID,
561 &i.LicenseKey,
562 &i.PrimaryLanguage,
563 &i.HasIssues,
564 &i.HasPulls,
565 &i.CreatedAt,
566 &i.UpdatedAt,
567 &i.DefaultBranchOid,
568 &i.AllowSquashMerge,
569 &i.AllowRebaseMerge,
570 &i.AllowMergeCommit,
571 &i.DefaultMergeMethod,
572 &i.StarCount,
573 &i.WatcherCount,
574 &i.ForkCount,
575 &i.InitStatus,
576 &i.LastIndexedOid,
577 )
578 return i, err
579 }
580
581 const getSoftDeletedRepoByOwnerUserAndName = `-- name: GetSoftDeletedRepoByOwnerUserAndName :one
582 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
583 default_branch, is_archived, archived_at, deleted_at,
584 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
585 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
586 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
587 star_count, watcher_count, fork_count, init_status,
588 last_indexed_oid
589 FROM repos
590 WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NOT NULL
591 ORDER BY deleted_at DESC, id DESC
592 LIMIT 1
593 `
594
595 type GetSoftDeletedRepoByOwnerUserAndNameParams struct {
596 OwnerUserID pgtype.Int8
597 Name string
598 }
599
600 func (q *Queries) GetSoftDeletedRepoByOwnerUserAndName(ctx context.Context, db DBTX, arg GetSoftDeletedRepoByOwnerUserAndNameParams) (Repo, error) {
601 row := db.QueryRow(ctx, getSoftDeletedRepoByOwnerUserAndName, arg.OwnerUserID, arg.Name)
602 var i Repo
603 err := row.Scan(
604 &i.ID,
605 &i.OwnerUserID,
606 &i.OwnerOrgID,
607 &i.Name,
608 &i.Description,
609 &i.Visibility,
610 &i.DefaultBranch,
611 &i.IsArchived,
612 &i.ArchivedAt,
613 &i.DeletedAt,
614 &i.DiskUsedBytes,
615 &i.ForkOfRepoID,
616 &i.LicenseKey,
617 &i.PrimaryLanguage,
618 &i.HasIssues,
619 &i.HasPulls,
620 &i.CreatedAt,
621 &i.UpdatedAt,
622 &i.DefaultBranchOid,
623 &i.AllowSquashMerge,
624 &i.AllowRebaseMerge,
625 &i.AllowMergeCommit,
626 &i.DefaultMergeMethod,
627 &i.StarCount,
628 &i.WatcherCount,
629 &i.ForkCount,
630 &i.InitStatus,
631 &i.LastIndexedOid,
632 )
633 return i, err
634 }
635
636 const insertProfilePin = `-- name: InsertProfilePin :exec
637 INSERT INTO profile_pins (set_id, repo_id, position)
638 VALUES ($1, $2, $3)
639 `
640
641 type InsertProfilePinParams struct {
642 SetID int64
643 RepoID int64
644 Position int32
645 }
646
647 func (q *Queries) InsertProfilePin(ctx context.Context, db DBTX, arg InsertProfilePinParams) error {
648 _, err := db.Exec(ctx, insertProfilePin, arg.SetID, arg.RepoID, arg.Position)
649 return err
650 }
651
652 const insertRepoTopic = `-- name: InsertRepoTopic :exec
653 INSERT INTO repo_topics (repo_id, topic)
654 VALUES ($1, $2)
655 ON CONFLICT DO NOTHING
656 `
657
658 type InsertRepoTopicParams struct {
659 RepoID int64
660 Topic string
661 }
662
663 func (q *Queries) InsertRepoTopic(ctx context.Context, db DBTX, arg InsertRepoTopicParams) error {
664 _, err := db.Exec(ctx, insertRepoTopic, arg.RepoID, arg.Topic)
665 return err
666 }
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
718 const listAllRepoFullNames = `-- name: ListAllRepoFullNames :many
719 SELECT
720 r.id,
721 r.name,
722 u.username AS owner_username
723 FROM repos r
724 JOIN users u ON u.id = r.owner_user_id
725 WHERE r.deleted_at IS NULL
726 ORDER BY r.id
727 `
728
729 type ListAllRepoFullNamesRow struct {
730 ID int64
731 Name string
732 OwnerUsername string
733 }
734
735 // Used by `shithubd hooks reinstall --all` to enumerate every active
736 // bare repo on disk and re-link its hooks.
737 func (q *Queries) ListAllRepoFullNames(ctx context.Context, db DBTX) ([]ListAllRepoFullNamesRow, error) {
738 rows, err := db.Query(ctx, listAllRepoFullNames)
739 if err != nil {
740 return nil, err
741 }
742 defer rows.Close()
743 items := []ListAllRepoFullNamesRow{}
744 for rows.Next() {
745 var i ListAllRepoFullNamesRow
746 if err := rows.Scan(&i.ID, &i.Name, &i.OwnerUsername); err != nil {
747 return nil, err
748 }
749 items = append(items, i)
750 }
751 if err := rows.Err(); err != nil {
752 return nil, err
753 }
754 return items, nil
755 }
756
757 const listForksOfRepo = `-- name: ListForksOfRepo :many
758 SELECT r.id, r.name, r.description, r.visibility, r.created_at,
759 r.star_count, r.fork_count, r.init_status,
760 u.username AS owner_username, u.display_name AS owner_display_name
761 FROM repos r
762 JOIN users u ON u.id = r.owner_user_id
763 WHERE r.fork_of_repo_id = $1
764 AND r.deleted_at IS NULL
765 ORDER BY r.created_at DESC
766 LIMIT $2 OFFSET $3
767 `
768
769 type ListForksOfRepoParams struct {
770 ForkOfRepoID pgtype.Int8
771 Limit int32
772 Offset int32
773 }
774
775 type ListForksOfRepoRow struct {
776 ID int64
777 Name string
778 Description string
779 Visibility RepoVisibility
780 CreatedAt pgtype.Timestamptz
781 StarCount int64
782 ForkCount int64
783 InitStatus RepoInitStatus
784 OwnerUsername string
785 OwnerDisplayName string
786 }
787
788 // Forks of a given source repo, paginated, recency-sorted. Joined
789 // with users for the owner display name. Excludes soft-deleted.
790 func (q *Queries) ListForksOfRepo(ctx context.Context, db DBTX, arg ListForksOfRepoParams) ([]ListForksOfRepoRow, error) {
791 rows, err := db.Query(ctx, listForksOfRepo, arg.ForkOfRepoID, arg.Limit, arg.Offset)
792 if err != nil {
793 return nil, err
794 }
795 defer rows.Close()
796 items := []ListForksOfRepoRow{}
797 for rows.Next() {
798 var i ListForksOfRepoRow
799 if err := rows.Scan(
800 &i.ID,
801 &i.Name,
802 &i.Description,
803 &i.Visibility,
804 &i.CreatedAt,
805 &i.StarCount,
806 &i.ForkCount,
807 &i.InitStatus,
808 &i.OwnerUsername,
809 &i.OwnerDisplayName,
810 ); err != nil {
811 return nil, err
812 }
813 items = append(items, i)
814 }
815 if err := rows.Err(); err != nil {
816 return nil, err
817 }
818 return items, nil
819 }
820
821 const listForksOfRepoForRepack = `-- name: ListForksOfRepoForRepack :many
822 SELECT r.id, r.name, u.username AS owner_username
823 FROM repos r
824 JOIN users u ON u.id = r.owner_user_id
825 WHERE r.fork_of_repo_id = $1
826 AND r.deleted_at IS NULL
827 `
828
829 type ListForksOfRepoForRepackRow struct {
830 ID int64
831 Name string
832 OwnerUsername string
833 }
834
835 // Used by S16's hard-delete cascade (S27 amendment): before deleting
836 // a source repo, every fork must `git repack -a -d --no-shared` so
837 // it has its own copy of the objects. Returns just enough to locate
838 // the bare repo on disk.
839 func (q *Queries) ListForksOfRepoForRepack(ctx context.Context, db DBTX, forkOfRepoID pgtype.Int8) ([]ListForksOfRepoForRepackRow, error) {
840 rows, err := db.Query(ctx, listForksOfRepoForRepack, forkOfRepoID)
841 if err != nil {
842 return nil, err
843 }
844 defer rows.Close()
845 items := []ListForksOfRepoForRepackRow{}
846 for rows.Next() {
847 var i ListForksOfRepoForRepackRow
848 if err := rows.Scan(&i.ID, &i.Name, &i.OwnerUsername); err != nil {
849 return nil, err
850 }
851 items = append(items, i)
852 }
853 if err := rows.Err(); err != nil {
854 return nil, err
855 }
856 return items, nil
857 }
858
859 const listProfilePinCandidateReposForUser = `-- name: ListProfilePinCandidateReposForUser :many
860 SELECT r.id, r.owner_user_id, r.owner_org_id, r.name, r.description, r.visibility, r.default_branch, r.is_archived, r.archived_at, r.deleted_at, r.disk_used_bytes, r.fork_of_repo_id, r.license_key, r.primary_language, r.has_issues, r.has_pulls, r.created_at, r.updated_at, r.default_branch_oid, r.allow_squash_merge, r.allow_rebase_merge, r.allow_merge_commit, r.default_merge_method, r.star_count, r.watcher_count, r.fork_count, r.init_status, r.last_indexed_oid, COALESCE(owner_user.username, owner_org.slug)::text AS owner_slug
861 FROM repos r
862 LEFT JOIN users owner_user ON owner_user.id = r.owner_user_id
863 LEFT JOIN orgs owner_org ON owner_org.id = r.owner_org_id
864 WHERE r.deleted_at IS NULL
865 AND r.visibility = 'public'
866 AND (
867 (r.owner_user_id IS NOT NULL AND owner_user.deleted_at IS NULL AND owner_user.suspended_at IS NULL)
868 OR (r.owner_org_id IS NOT NULL AND owner_org.deleted_at IS NULL)
869 )
870 AND (
871 r.owner_user_id = $1
872 OR EXISTS (
873 SELECT 1
874 FROM org_members m
875 WHERE m.org_id = r.owner_org_id
876 AND m.user_id = $1
877 )
878 OR EXISTS (
879 SELECT 1
880 FROM repo_collaborators c
881 WHERE c.repo_id = r.id
882 AND c.user_id = $1
883 )
884 )
885 ORDER BY lower(COALESCE(owner_user.username::text, owner_org.slug::text, '')), lower(r.name::text), r.id
886 `
887
888 type ListProfilePinCandidateReposForUserRow struct {
889 Repo Repo
890 OwnerSlug string
891 }
892
893 func (q *Queries) ListProfilePinCandidateReposForUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) ([]ListProfilePinCandidateReposForUserRow, error) {
894 rows, err := db.Query(ctx, listProfilePinCandidateReposForUser, ownerUserID)
895 if err != nil {
896 return nil, err
897 }
898 defer rows.Close()
899 items := []ListProfilePinCandidateReposForUserRow{}
900 for rows.Next() {
901 var i ListProfilePinCandidateReposForUserRow
902 if err := rows.Scan(
903 &i.Repo.ID,
904 &i.Repo.OwnerUserID,
905 &i.Repo.OwnerOrgID,
906 &i.Repo.Name,
907 &i.Repo.Description,
908 &i.Repo.Visibility,
909 &i.Repo.DefaultBranch,
910 &i.Repo.IsArchived,
911 &i.Repo.ArchivedAt,
912 &i.Repo.DeletedAt,
913 &i.Repo.DiskUsedBytes,
914 &i.Repo.ForkOfRepoID,
915 &i.Repo.LicenseKey,
916 &i.Repo.PrimaryLanguage,
917 &i.Repo.HasIssues,
918 &i.Repo.HasPulls,
919 &i.Repo.CreatedAt,
920 &i.Repo.UpdatedAt,
921 &i.Repo.DefaultBranchOid,
922 &i.Repo.AllowSquashMerge,
923 &i.Repo.AllowRebaseMerge,
924 &i.Repo.AllowMergeCommit,
925 &i.Repo.DefaultMergeMethod,
926 &i.Repo.StarCount,
927 &i.Repo.WatcherCount,
928 &i.Repo.ForkCount,
929 &i.Repo.InitStatus,
930 &i.Repo.LastIndexedOid,
931 &i.OwnerSlug,
932 ); err != nil {
933 return nil, err
934 }
935 items = append(items, i)
936 }
937 if err := rows.Err(); err != nil {
938 return nil, err
939 }
940 return items, nil
941 }
942
943 const listProfilePinsForSet = `-- name: ListProfilePinsForSet :many
944 SELECT repo_id, position
945 FROM profile_pins
946 WHERE set_id = $1
947 ORDER BY position ASC
948 `
949
950 type ListProfilePinsForSetRow struct {
951 RepoID int64
952 Position int32
953 }
954
955 func (q *Queries) ListProfilePinsForSet(ctx context.Context, db DBTX, setID int64) ([]ListProfilePinsForSetRow, error) {
956 rows, err := db.Query(ctx, listProfilePinsForSet, setID)
957 if err != nil {
958 return nil, err
959 }
960 defer rows.Close()
961 items := []ListProfilePinsForSetRow{}
962 for rows.Next() {
963 var i ListProfilePinsForSetRow
964 if err := rows.Scan(&i.RepoID, &i.Position); err != nil {
965 return nil, err
966 }
967 items = append(items, i)
968 }
969 if err := rows.Err(); err != nil {
970 return nil, err
971 }
972 return items, nil
973 }
974
975 const listPublicContributionRepos = `-- name: ListPublicContributionRepos :many
976 SELECT r.id, r.owner_user_id, r.owner_org_id, r.name, r.description, r.visibility, r.default_branch, r.is_archived, r.archived_at, r.deleted_at, r.disk_used_bytes, r.fork_of_repo_id, r.license_key, r.primary_language, r.has_issues, r.has_pulls, r.created_at, r.updated_at, r.default_branch_oid, r.allow_squash_merge, r.allow_rebase_merge, r.allow_merge_commit, r.default_merge_method, r.star_count, r.watcher_count, r.fork_count, r.init_status, r.last_indexed_oid, COALESCE(u.username, o.slug)::text AS owner_slug
977 FROM repos r
978 LEFT JOIN users u ON u.id = r.owner_user_id
979 LEFT JOIN orgs o ON o.id = r.owner_org_id
980 WHERE r.deleted_at IS NULL
981 AND r.visibility = 'public'
982 AND (
983 (r.owner_user_id IS NOT NULL AND u.deleted_at IS NULL AND u.suspended_at IS NULL)
984 OR (r.owner_org_id IS NOT NULL AND o.deleted_at IS NULL)
985 )
986 ORDER BY r.updated_at DESC, r.id DESC
987 LIMIT $1
988 `
989
990 type ListPublicContributionReposRow struct {
991 Repo Repo
992 OwnerSlug string
993 }
994
995 func (q *Queries) ListPublicContributionRepos(ctx context.Context, db DBTX, limit int32) ([]ListPublicContributionReposRow, error) {
996 rows, err := db.Query(ctx, listPublicContributionRepos, limit)
997 if err != nil {
998 return nil, err
999 }
1000 defer rows.Close()
1001 items := []ListPublicContributionReposRow{}
1002 for rows.Next() {
1003 var i ListPublicContributionReposRow
1004 if err := rows.Scan(
1005 &i.Repo.ID,
1006 &i.Repo.OwnerUserID,
1007 &i.Repo.OwnerOrgID,
1008 &i.Repo.Name,
1009 &i.Repo.Description,
1010 &i.Repo.Visibility,
1011 &i.Repo.DefaultBranch,
1012 &i.Repo.IsArchived,
1013 &i.Repo.ArchivedAt,
1014 &i.Repo.DeletedAt,
1015 &i.Repo.DiskUsedBytes,
1016 &i.Repo.ForkOfRepoID,
1017 &i.Repo.LicenseKey,
1018 &i.Repo.PrimaryLanguage,
1019 &i.Repo.HasIssues,
1020 &i.Repo.HasPulls,
1021 &i.Repo.CreatedAt,
1022 &i.Repo.UpdatedAt,
1023 &i.Repo.DefaultBranchOid,
1024 &i.Repo.AllowSquashMerge,
1025 &i.Repo.AllowRebaseMerge,
1026 &i.Repo.AllowMergeCommit,
1027 &i.Repo.DefaultMergeMethod,
1028 &i.Repo.StarCount,
1029 &i.Repo.WatcherCount,
1030 &i.Repo.ForkCount,
1031 &i.Repo.InitStatus,
1032 &i.Repo.LastIndexedOid,
1033 &i.OwnerSlug,
1034 ); err != nil {
1035 return nil, err
1036 }
1037 items = append(items, i)
1038 }
1039 if err := rows.Err(); err != nil {
1040 return nil, err
1041 }
1042 return items, nil
1043 }
1044
1045 const listPublicReposForOwnerOrg = `-- name: ListPublicReposForOwnerOrg :many
1046 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
1047 default_branch, is_archived, archived_at, deleted_at,
1048 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
1049 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
1050 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
1051 star_count, watcher_count, fork_count, init_status,
1052 last_indexed_oid
1053 FROM repos
1054 WHERE owner_org_id = $1
1055 AND visibility = 'public'
1056 AND deleted_at IS NULL
1057 ORDER BY updated_at DESC
1058 LIMIT $2 OFFSET $3
1059 `
1060
1061 type ListPublicReposForOwnerOrgParams struct {
1062 OwnerOrgID pgtype.Int8
1063 Limit int32
1064 Offset int32
1065 }
1066
1067 // Public-only org repo listing for non-member callers (and the no-auth
1068 // public-discovery REST view).
1069 func (q *Queries) ListPublicReposForOwnerOrg(ctx context.Context, db DBTX, arg ListPublicReposForOwnerOrgParams) ([]Repo, error) {
1070 rows, err := db.Query(ctx, listPublicReposForOwnerOrg, arg.OwnerOrgID, arg.Limit, arg.Offset)
1071 if err != nil {
1072 return nil, err
1073 }
1074 defer rows.Close()
1075 items := []Repo{}
1076 for rows.Next() {
1077 var i Repo
1078 if err := rows.Scan(
1079 &i.ID,
1080 &i.OwnerUserID,
1081 &i.OwnerOrgID,
1082 &i.Name,
1083 &i.Description,
1084 &i.Visibility,
1085 &i.DefaultBranch,
1086 &i.IsArchived,
1087 &i.ArchivedAt,
1088 &i.DeletedAt,
1089 &i.DiskUsedBytes,
1090 &i.ForkOfRepoID,
1091 &i.LicenseKey,
1092 &i.PrimaryLanguage,
1093 &i.HasIssues,
1094 &i.HasPulls,
1095 &i.CreatedAt,
1096 &i.UpdatedAt,
1097 &i.DefaultBranchOid,
1098 &i.AllowSquashMerge,
1099 &i.AllowRebaseMerge,
1100 &i.AllowMergeCommit,
1101 &i.DefaultMergeMethod,
1102 &i.StarCount,
1103 &i.WatcherCount,
1104 &i.ForkCount,
1105 &i.InitStatus,
1106 &i.LastIndexedOid,
1107 ); err != nil {
1108 return nil, err
1109 }
1110 items = append(items, i)
1111 }
1112 if err := rows.Err(); err != nil {
1113 return nil, err
1114 }
1115 return items, nil
1116 }
1117
1118 const listPublicReposForOwnerUser = `-- name: ListPublicReposForOwnerUser :many
1119 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
1120 default_branch, is_archived, archived_at, deleted_at,
1121 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
1122 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
1123 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
1124 star_count, watcher_count, fork_count, init_status,
1125 last_indexed_oid
1126 FROM repos
1127 WHERE owner_user_id = $1
1128 AND visibility = 'public'
1129 AND deleted_at IS NULL
1130 ORDER BY updated_at DESC
1131 LIMIT $2 OFFSET $3
1132 `
1133
1134 type ListPublicReposForOwnerUserParams struct {
1135 OwnerUserID pgtype.Int8
1136 Limit int32
1137 Offset int32
1138 }
1139
1140 // Public-only view of a user's repos for the "list another user's repos"
1141 // REST endpoint. Hidden behind the same updated_at ordering.
1142 func (q *Queries) ListPublicReposForOwnerUser(ctx context.Context, db DBTX, arg ListPublicReposForOwnerUserParams) ([]Repo, error) {
1143 rows, err := db.Query(ctx, listPublicReposForOwnerUser, arg.OwnerUserID, arg.Limit, arg.Offset)
1144 if err != nil {
1145 return nil, err
1146 }
1147 defer rows.Close()
1148 items := []Repo{}
1149 for rows.Next() {
1150 var i Repo
1151 if err := rows.Scan(
1152 &i.ID,
1153 &i.OwnerUserID,
1154 &i.OwnerOrgID,
1155 &i.Name,
1156 &i.Description,
1157 &i.Visibility,
1158 &i.DefaultBranch,
1159 &i.IsArchived,
1160 &i.ArchivedAt,
1161 &i.DeletedAt,
1162 &i.DiskUsedBytes,
1163 &i.ForkOfRepoID,
1164 &i.LicenseKey,
1165 &i.PrimaryLanguage,
1166 &i.HasIssues,
1167 &i.HasPulls,
1168 &i.CreatedAt,
1169 &i.UpdatedAt,
1170 &i.DefaultBranchOid,
1171 &i.AllowSquashMerge,
1172 &i.AllowRebaseMerge,
1173 &i.AllowMergeCommit,
1174 &i.DefaultMergeMethod,
1175 &i.StarCount,
1176 &i.WatcherCount,
1177 &i.ForkCount,
1178 &i.InitStatus,
1179 &i.LastIndexedOid,
1180 ); err != nil {
1181 return nil, err
1182 }
1183 items = append(items, i)
1184 }
1185 if err := rows.Err(); err != nil {
1186 return nil, err
1187 }
1188 return items, nil
1189 }
1190
1191 const listRepoTopics = `-- name: ListRepoTopics :many
1192
1193 SELECT topic FROM repo_topics WHERE repo_id = $1 ORDER BY topic ASC
1194 `
1195
1196 // ─── repo_topics (S32) ─────────────────────────────────────────────
1197 func (q *Queries) ListRepoTopics(ctx context.Context, db DBTX, repoID int64) ([]string, error) {
1198 rows, err := db.Query(ctx, listRepoTopics, repoID)
1199 if err != nil {
1200 return nil, err
1201 }
1202 defer rows.Close()
1203 items := []string{}
1204 for rows.Next() {
1205 var topic string
1206 if err := rows.Scan(&topic); err != nil {
1207 return nil, err
1208 }
1209 items = append(items, topic)
1210 }
1211 if err := rows.Err(); err != nil {
1212 return nil, err
1213 }
1214 return items, nil
1215 }
1216
1217 const listReposForOwnerOrg = `-- name: ListReposForOwnerOrg :many
1218 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
1219 default_branch, is_archived, archived_at, deleted_at,
1220 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
1221 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
1222 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
1223 star_count, watcher_count, fork_count, init_status,
1224 last_indexed_oid
1225 FROM repos
1226 WHERE owner_org_id = $1 AND deleted_at IS NULL
1227 ORDER BY updated_at DESC
1228 `
1229
1230 func (q *Queries) ListReposForOwnerOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) ([]Repo, error) {
1231 rows, err := db.Query(ctx, listReposForOwnerOrg, ownerOrgID)
1232 if err != nil {
1233 return nil, err
1234 }
1235 defer rows.Close()
1236 items := []Repo{}
1237 for rows.Next() {
1238 var i Repo
1239 if err := rows.Scan(
1240 &i.ID,
1241 &i.OwnerUserID,
1242 &i.OwnerOrgID,
1243 &i.Name,
1244 &i.Description,
1245 &i.Visibility,
1246 &i.DefaultBranch,
1247 &i.IsArchived,
1248 &i.ArchivedAt,
1249 &i.DeletedAt,
1250 &i.DiskUsedBytes,
1251 &i.ForkOfRepoID,
1252 &i.LicenseKey,
1253 &i.PrimaryLanguage,
1254 &i.HasIssues,
1255 &i.HasPulls,
1256 &i.CreatedAt,
1257 &i.UpdatedAt,
1258 &i.DefaultBranchOid,
1259 &i.AllowSquashMerge,
1260 &i.AllowRebaseMerge,
1261 &i.AllowMergeCommit,
1262 &i.DefaultMergeMethod,
1263 &i.StarCount,
1264 &i.WatcherCount,
1265 &i.ForkCount,
1266 &i.InitStatus,
1267 &i.LastIndexedOid,
1268 ); err != nil {
1269 return nil, err
1270 }
1271 items = append(items, i)
1272 }
1273 if err := rows.Err(); err != nil {
1274 return nil, err
1275 }
1276 return items, nil
1277 }
1278
1279 const listReposForOwnerOrgPaged = `-- name: ListReposForOwnerOrgPaged :many
1280 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
1281 default_branch, is_archived, archived_at, deleted_at,
1282 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
1283 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
1284 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
1285 star_count, watcher_count, fork_count, init_status,
1286 last_indexed_oid
1287 FROM repos
1288 WHERE owner_org_id = $1 AND deleted_at IS NULL
1289 ORDER BY updated_at DESC
1290 LIMIT $2 OFFSET $3
1291 `
1292
1293 type ListReposForOwnerOrgPagedParams struct {
1294 OwnerOrgID pgtype.Int8
1295 Limit int32
1296 Offset int32
1297 }
1298
1299 // Paginated mirror of ListReposForOwnerOrg for the REST list endpoint
1300 // when the viewer is an org member and may see private repos.
1301 func (q *Queries) ListReposForOwnerOrgPaged(ctx context.Context, db DBTX, arg ListReposForOwnerOrgPagedParams) ([]Repo, error) {
1302 rows, err := db.Query(ctx, listReposForOwnerOrgPaged, arg.OwnerOrgID, arg.Limit, arg.Offset)
1303 if err != nil {
1304 return nil, err
1305 }
1306 defer rows.Close()
1307 items := []Repo{}
1308 for rows.Next() {
1309 var i Repo
1310 if err := rows.Scan(
1311 &i.ID,
1312 &i.OwnerUserID,
1313 &i.OwnerOrgID,
1314 &i.Name,
1315 &i.Description,
1316 &i.Visibility,
1317 &i.DefaultBranch,
1318 &i.IsArchived,
1319 &i.ArchivedAt,
1320 &i.DeletedAt,
1321 &i.DiskUsedBytes,
1322 &i.ForkOfRepoID,
1323 &i.LicenseKey,
1324 &i.PrimaryLanguage,
1325 &i.HasIssues,
1326 &i.HasPulls,
1327 &i.CreatedAt,
1328 &i.UpdatedAt,
1329 &i.DefaultBranchOid,
1330 &i.AllowSquashMerge,
1331 &i.AllowRebaseMerge,
1332 &i.AllowMergeCommit,
1333 &i.DefaultMergeMethod,
1334 &i.StarCount,
1335 &i.WatcherCount,
1336 &i.ForkCount,
1337 &i.InitStatus,
1338 &i.LastIndexedOid,
1339 ); err != nil {
1340 return nil, err
1341 }
1342 items = append(items, i)
1343 }
1344 if err := rows.Err(); err != nil {
1345 return nil, err
1346 }
1347 return items, nil
1348 }
1349
1350 const listReposForOwnerUser = `-- name: ListReposForOwnerUser :many
1351 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
1352 default_branch, is_archived, archived_at, deleted_at,
1353 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
1354 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
1355 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
1356 star_count, watcher_count, fork_count, init_status,
1357 last_indexed_oid
1358 FROM repos
1359 WHERE owner_user_id = $1 AND deleted_at IS NULL
1360 ORDER BY updated_at DESC
1361 `
1362
1363 func (q *Queries) ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) ([]Repo, error) {
1364 rows, err := db.Query(ctx, listReposForOwnerUser, ownerUserID)
1365 if err != nil {
1366 return nil, err
1367 }
1368 defer rows.Close()
1369 items := []Repo{}
1370 for rows.Next() {
1371 var i Repo
1372 if err := rows.Scan(
1373 &i.ID,
1374 &i.OwnerUserID,
1375 &i.OwnerOrgID,
1376 &i.Name,
1377 &i.Description,
1378 &i.Visibility,
1379 &i.DefaultBranch,
1380 &i.IsArchived,
1381 &i.ArchivedAt,
1382 &i.DeletedAt,
1383 &i.DiskUsedBytes,
1384 &i.ForkOfRepoID,
1385 &i.LicenseKey,
1386 &i.PrimaryLanguage,
1387 &i.HasIssues,
1388 &i.HasPulls,
1389 &i.CreatedAt,
1390 &i.UpdatedAt,
1391 &i.DefaultBranchOid,
1392 &i.AllowSquashMerge,
1393 &i.AllowRebaseMerge,
1394 &i.AllowMergeCommit,
1395 &i.DefaultMergeMethod,
1396 &i.StarCount,
1397 &i.WatcherCount,
1398 &i.ForkCount,
1399 &i.InitStatus,
1400 &i.LastIndexedOid,
1401 ); err != nil {
1402 return nil, err
1403 }
1404 items = append(items, i)
1405 }
1406 if err := rows.Err(); err != nil {
1407 return nil, err
1408 }
1409 return items, nil
1410 }
1411
1412 const listReposForOwnerUserPaged = `-- name: ListReposForOwnerUserPaged :many
1413 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
1414 default_branch, is_archived, archived_at, deleted_at,
1415 disk_used_bytes, fork_of_repo_id, license_key, primary_language,
1416 has_issues, has_pulls, created_at, updated_at, default_branch_oid,
1417 allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
1418 star_count, watcher_count, fork_count, init_status,
1419 last_indexed_oid
1420 FROM repos
1421 WHERE owner_user_id = $1 AND deleted_at IS NULL
1422 ORDER BY updated_at DESC
1423 LIMIT $2 OFFSET $3
1424 `
1425
1426 type ListReposForOwnerUserPagedParams struct {
1427 OwnerUserID pgtype.Int8
1428 Limit int32
1429 Offset int32
1430 }
1431
1432 // Paginated mirror of ListReposForOwnerUser. Used by the REST surface
1433 // where the caller is the owner (or a site admin) and is allowed to see
1434 // private repos. Order matches the un-paginated form so callers can
1435 // swap between them without observing a reshuffle.
1436 func (q *Queries) ListReposForOwnerUserPaged(ctx context.Context, db DBTX, arg ListReposForOwnerUserPagedParams) ([]Repo, error) {
1437 rows, err := db.Query(ctx, listReposForOwnerUserPaged, arg.OwnerUserID, arg.Limit, arg.Offset)
1438 if err != nil {
1439 return nil, err
1440 }
1441 defer rows.Close()
1442 items := []Repo{}
1443 for rows.Next() {
1444 var i Repo
1445 if err := rows.Scan(
1446 &i.ID,
1447 &i.OwnerUserID,
1448 &i.OwnerOrgID,
1449 &i.Name,
1450 &i.Description,
1451 &i.Visibility,
1452 &i.DefaultBranch,
1453 &i.IsArchived,
1454 &i.ArchivedAt,
1455 &i.DeletedAt,
1456 &i.DiskUsedBytes,
1457 &i.ForkOfRepoID,
1458 &i.LicenseKey,
1459 &i.PrimaryLanguage,
1460 &i.HasIssues,
1461 &i.HasPulls,
1462 &i.CreatedAt,
1463 &i.UpdatedAt,
1464 &i.DefaultBranchOid,
1465 &i.AllowSquashMerge,
1466 &i.AllowRebaseMerge,
1467 &i.AllowMergeCommit,
1468 &i.DefaultMergeMethod,
1469 &i.StarCount,
1470 &i.WatcherCount,
1471 &i.ForkCount,
1472 &i.InitStatus,
1473 &i.LastIndexedOid,
1474 ); err != nil {
1475 return nil, err
1476 }
1477 items = append(items, i)
1478 }
1479 if err := rows.Err(); err != nil {
1480 return nil, err
1481 }
1482 return items, nil
1483 }
1484
1485 const listReposNeedingReindex = `-- name: ListReposNeedingReindex :many
1486 SELECT id, name, default_branch, default_branch_oid
1487 FROM repos
1488 WHERE deleted_at IS NULL
1489 AND default_branch_oid IS NOT NULL
1490 AND (last_indexed_oid IS NULL OR last_indexed_oid <> default_branch_oid)
1491 ORDER BY id
1492 LIMIT $1
1493 `
1494
1495 type ListReposNeedingReindexRow struct {
1496 ID int64
1497 Name string
1498 DefaultBranch string
1499 DefaultBranchOid pgtype.Text
1500 }
1501
1502 // S28 code-search reconciler: returns repos whose default_branch_oid
1503 // has advanced past last_indexed_oid (or last_indexed_oid is NULL
1504 // and a default exists). Limited so a single tick of the cron
1505 // doesn't try to re-index the whole world.
1506 func (q *Queries) ListReposNeedingReindex(ctx context.Context, db DBTX, limit int32) ([]ListReposNeedingReindexRow, error) {
1507 rows, err := db.Query(ctx, listReposNeedingReindex, limit)
1508 if err != nil {
1509 return nil, err
1510 }
1511 defer rows.Close()
1512 items := []ListReposNeedingReindexRow{}
1513 for rows.Next() {
1514 var i ListReposNeedingReindexRow
1515 if err := rows.Scan(
1516 &i.ID,
1517 &i.Name,
1518 &i.DefaultBranch,
1519 &i.DefaultBranchOid,
1520 ); err != nil {
1521 return nil, err
1522 }
1523 items = append(items, i)
1524 }
1525 if err := rows.Err(); err != nil {
1526 return nil, err
1527 }
1528 return items, nil
1529 }
1530
1531 const lockRepoOwnerName = `-- name: LockRepoOwnerName :exec
1532 SELECT pg_advisory_xact_lock(hashtextextended($1, 0))
1533 `
1534
1535 // Serializes DB + filesystem operations for one logical owner/name
1536 // pair. Create, soft-delete, restore, and hard-delete all touch the
1537 // canonical bare path; a transaction-scoped advisory lock keeps those
1538 // cross-resource moves from racing.
1539 func (q *Queries) LockRepoOwnerName(ctx context.Context, db DBTX, hashtextextended string) error {
1540 _, err := db.Exec(ctx, lockRepoOwnerName, hashtextextended)
1541 return err
1542 }
1543
1544 const replaceRepoTopics = `-- name: ReplaceRepoTopics :exec
1545 DELETE FROM repo_topics WHERE repo_id = $1
1546 `
1547
1548 // Atomic full-replace: callers compose the new topic set in Go,
1549 // then replace the existing rows in one tx (DELETE + INSERT). The
1550 // caller's tx wraps both calls for atomicity.
1551 func (q *Queries) ReplaceRepoTopics(ctx context.Context, db DBTX, repoID int64) error {
1552 _, err := db.Exec(ctx, replaceRepoTopics, repoID)
1553 return err
1554 }
1555
1556 const setLastIndexedOID = `-- name: SetLastIndexedOID :exec
1557 UPDATE repos SET last_indexed_oid = $2::text WHERE id = $1
1558 `
1559
1560 type SetLastIndexedOIDParams struct {
1561 ID int64
1562 LastIndexedOid pgtype.Text
1563 }
1564
1565 // S28 code-search: the worker writes the OID it finished indexing
1566 // so the reconciler can detect drift (default_branch_oid moved but
1567 // last_indexed_oid lagged).
1568 func (q *Queries) SetLastIndexedOID(ctx context.Context, db DBTX, arg SetLastIndexedOIDParams) error {
1569 _, err := db.Exec(ctx, setLastIndexedOID, arg.ID, arg.LastIndexedOid)
1570 return err
1571 }
1572
1573 const setRepoInitStatus = `-- name: SetRepoInitStatus :exec
1574 UPDATE repos SET init_status = $2 WHERE id = $1
1575 `
1576
1577 type SetRepoInitStatusParams struct {
1578 ID int64
1579 InitStatus RepoInitStatus
1580 }
1581
1582 // Promotes a fork from init_pending to initialized (or init_failed).
1583 // The DB row is created up-front so the URL resolves immediately and
1584 // the user sees a "preparing your fork" placeholder while the worker
1585 // runs `git clone --bare --shared`.
1586 func (q *Queries) SetRepoInitStatus(ctx context.Context, db DBTX, arg SetRepoInitStatusParams) error {
1587 _, err := db.Exec(ctx, setRepoInitStatus, arg.ID, arg.InitStatus)
1588 return err
1589 }
1590
1591 const softDeleteRepo = `-- name: SoftDeleteRepo :exec
1592 UPDATE repos SET deleted_at = now() WHERE id = $1
1593 `
1594
1595 func (q *Queries) SoftDeleteRepo(ctx context.Context, db DBTX, id int64) error {
1596 _, err := db.Exec(ctx, softDeleteRepo, id)
1597 return err
1598 }
1599
1600 const updateRepoDefaultBranchOID = `-- name: UpdateRepoDefaultBranchOID :exec
1601 UPDATE repos SET default_branch_oid = $2::text WHERE id = $1
1602 `
1603
1604 type UpdateRepoDefaultBranchOIDParams struct {
1605 ID int64
1606 DefaultBranchOid pgtype.Text
1607 }
1608
1609 // Set when push:process detects a commit on the repo's default branch.
1610 // Pass NULL to clear (e.g. when the branch is force-deleted in a future
1611 // sprint). The repo home view reads this to decide between empty and
1612 // populated layouts.
1613 func (q *Queries) UpdateRepoDefaultBranchOID(ctx context.Context, db DBTX, arg UpdateRepoDefaultBranchOIDParams) error {
1614 _, err := db.Exec(ctx, updateRepoDefaultBranchOID, arg.ID, arg.DefaultBranchOid)
1615 return err
1616 }
1617
1618 const updateRepoDiskUsed = `-- name: UpdateRepoDiskUsed :exec
1619 UPDATE repos SET disk_used_bytes = $2 WHERE id = $1
1620 `
1621
1622 type UpdateRepoDiskUsedParams struct {
1623 ID int64
1624 DiskUsedBytes int64
1625 }
1626
1627 func (q *Queries) UpdateRepoDiskUsed(ctx context.Context, db DBTX, arg UpdateRepoDiskUsedParams) error {
1628 _, err := db.Exec(ctx, updateRepoDiskUsed, arg.ID, arg.DiskUsedBytes)
1629 return err
1630 }
1631
1632 const updateRepoGeneralSettings = `-- name: UpdateRepoGeneralSettings :exec
1633 UPDATE repos
1634 SET description = $2,
1635 has_issues = $3,
1636 has_pulls = $4,
1637 updated_at = now()
1638 WHERE id = $1
1639 `
1640
1641 type UpdateRepoGeneralSettingsParams struct {
1642 ID int64
1643 Description string
1644 HasIssues bool
1645 HasPulls bool
1646 }
1647
1648 // S32: General-tab settings persist via this single query so each
1649 // form post is one round-trip. The merge-method toggles are kept
1650 // separate from the repo create flow because they're admin-only.
1651 func (q *Queries) UpdateRepoGeneralSettings(ctx context.Context, db DBTX, arg UpdateRepoGeneralSettingsParams) error {
1652 _, err := db.Exec(ctx, updateRepoGeneralSettings,
1653 arg.ID,
1654 arg.Description,
1655 arg.HasIssues,
1656 arg.HasPulls,
1657 )
1658 return err
1659 }
1660
1661 const updateRepoMergeSettings = `-- name: UpdateRepoMergeSettings :exec
1662 UPDATE repos
1663 SET allow_merge_commit = $2,
1664 allow_squash_merge = $3,
1665 allow_rebase_merge = $4,
1666 default_merge_method = $5,
1667 updated_at = now()
1668 WHERE id = $1
1669 `
1670
1671 type UpdateRepoMergeSettingsParams struct {
1672 ID int64
1673 AllowMergeCommit bool
1674 AllowSquashMerge bool
1675 AllowRebaseMerge bool
1676 DefaultMergeMethod PrMergeMethod
1677 }
1678
1679 func (q *Queries) UpdateRepoMergeSettings(ctx context.Context, db DBTX, arg UpdateRepoMergeSettingsParams) error {
1680 _, err := db.Exec(ctx, updateRepoMergeSettings,
1681 arg.ID,
1682 arg.AllowMergeCommit,
1683 arg.AllowSquashMerge,
1684 arg.AllowRebaseMerge,
1685 arg.DefaultMergeMethod,
1686 )
1687 return err
1688 }
1689
1690 const upsertProfilePinSetForOrg = `-- name: UpsertProfilePinSetForOrg :one
1691 INSERT INTO profile_pin_sets (owner_org_id)
1692 VALUES ($1)
1693 ON CONFLICT (owner_org_id) WHERE owner_org_id IS NOT NULL
1694 DO UPDATE SET updated_at = now()
1695 RETURNING id
1696 `
1697
1698 func (q *Queries) UpsertProfilePinSetForOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) (int64, error) {
1699 row := db.QueryRow(ctx, upsertProfilePinSetForOrg, ownerOrgID)
1700 var id int64
1701 err := row.Scan(&id)
1702 return id, err
1703 }
1704
1705 const upsertProfilePinSetForUser = `-- name: UpsertProfilePinSetForUser :one
1706 INSERT INTO profile_pin_sets (owner_user_id)
1707 VALUES ($1)
1708 ON CONFLICT (owner_user_id) WHERE owner_user_id IS NOT NULL
1709 DO UPDATE SET updated_at = now()
1710 RETURNING id
1711 `
1712
1713 func (q *Queries) UpsertProfilePinSetForUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) (int64, error) {
1714 row := db.QueryRow(ctx, upsertProfilePinSetForUser, ownerUserID)
1715 var id int64
1716 err := row.Scan(&id)
1717 return id, err
1718 }
1719