| 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 countReposForOwnerUser = `-- name: CountReposForOwnerUser :one |
| 40 | SELECT count(*) FROM repos |
| 41 | WHERE owner_user_id = $1 AND deleted_at IS NULL |
| 42 | ` |
| 43 | |
| 44 | func (q *Queries) CountReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) (int64, error) { |
| 45 | row := db.QueryRow(ctx, countReposForOwnerUser, ownerUserID) |
| 46 | var count int64 |
| 47 | err := row.Scan(&count) |
| 48 | return count, err |
| 49 | } |
| 50 | |
| 51 | const createForkRepo = `-- name: CreateForkRepo :one |
| 52 | |
| 53 | INSERT INTO repos ( |
| 54 | owner_user_id, owner_org_id, name, description, visibility, |
| 55 | default_branch, fork_of_repo_id, init_status |
| 56 | ) VALUES ( |
| 57 | $1, $2, $3, $4, $5, $6, $7, 'init_pending' |
| 58 | ) |
| 59 | RETURNING id, owner_user_id, owner_org_id, name, description, visibility, |
| 60 | default_branch, is_archived, archived_at, deleted_at, |
| 61 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 62 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 63 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 64 | star_count, watcher_count, fork_count, init_status, |
| 65 | last_indexed_oid |
| 66 | ` |
| 67 | |
| 68 | type CreateForkRepoParams struct { |
| 69 | OwnerUserID pgtype.Int8 |
| 70 | OwnerOrgID pgtype.Int8 |
| 71 | Name string |
| 72 | Description string |
| 73 | Visibility RepoVisibility |
| 74 | DefaultBranch string |
| 75 | ForkOfRepoID pgtype.Int8 |
| 76 | } |
| 77 | |
| 78 | // ─── S27 forks ───────────────────────────────────────────────────── |
| 79 | // Insert a fork shell. Distinct from CreateRepo because forks set |
| 80 | // `fork_of_repo_id` (which fires the fork_count trigger) and start |
| 81 | // at init_status='init_pending' so the worker job can flip them to |
| 82 | // 'initialized' once `git clone --bare --shared` finishes. |
| 83 | func (q *Queries) CreateForkRepo(ctx context.Context, db DBTX, arg CreateForkRepoParams) (Repo, error) { |
| 84 | row := db.QueryRow(ctx, createForkRepo, |
| 85 | arg.OwnerUserID, |
| 86 | arg.OwnerOrgID, |
| 87 | arg.Name, |
| 88 | arg.Description, |
| 89 | arg.Visibility, |
| 90 | arg.DefaultBranch, |
| 91 | arg.ForkOfRepoID, |
| 92 | ) |
| 93 | var i Repo |
| 94 | err := row.Scan( |
| 95 | &i.ID, |
| 96 | &i.OwnerUserID, |
| 97 | &i.OwnerOrgID, |
| 98 | &i.Name, |
| 99 | &i.Description, |
| 100 | &i.Visibility, |
| 101 | &i.DefaultBranch, |
| 102 | &i.IsArchived, |
| 103 | &i.ArchivedAt, |
| 104 | &i.DeletedAt, |
| 105 | &i.DiskUsedBytes, |
| 106 | &i.ForkOfRepoID, |
| 107 | &i.LicenseKey, |
| 108 | &i.PrimaryLanguage, |
| 109 | &i.HasIssues, |
| 110 | &i.HasPulls, |
| 111 | &i.CreatedAt, |
| 112 | &i.UpdatedAt, |
| 113 | &i.DefaultBranchOid, |
| 114 | &i.AllowSquashMerge, |
| 115 | &i.AllowRebaseMerge, |
| 116 | &i.AllowMergeCommit, |
| 117 | &i.DefaultMergeMethod, |
| 118 | &i.StarCount, |
| 119 | &i.WatcherCount, |
| 120 | &i.ForkCount, |
| 121 | &i.InitStatus, |
| 122 | &i.LastIndexedOid, |
| 123 | ) |
| 124 | return i, err |
| 125 | } |
| 126 | |
| 127 | const createRepo = `-- name: CreateRepo :one |
| 128 | |
| 129 | INSERT INTO repos ( |
| 130 | owner_user_id, owner_org_id, name, description, visibility, |
| 131 | default_branch, license_key, primary_language |
| 132 | ) VALUES ( |
| 133 | $1, $2, $3, $4, $5, $6, $7, $8 |
| 134 | ) |
| 135 | RETURNING id, owner_user_id, owner_org_id, name, description, visibility, |
| 136 | default_branch, is_archived, archived_at, deleted_at, |
| 137 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 138 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 139 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 140 | star_count, watcher_count, fork_count, init_status, |
| 141 | last_indexed_oid |
| 142 | ` |
| 143 | |
| 144 | type CreateRepoParams struct { |
| 145 | OwnerUserID pgtype.Int8 |
| 146 | OwnerOrgID pgtype.Int8 |
| 147 | Name string |
| 148 | Description string |
| 149 | Visibility RepoVisibility |
| 150 | DefaultBranch string |
| 151 | LicenseKey pgtype.Text |
| 152 | PrimaryLanguage pgtype.Text |
| 153 | } |
| 154 | |
| 155 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 156 | func (q *Queries) CreateRepo(ctx context.Context, db DBTX, arg CreateRepoParams) (Repo, error) { |
| 157 | row := db.QueryRow(ctx, createRepo, |
| 158 | arg.OwnerUserID, |
| 159 | arg.OwnerOrgID, |
| 160 | arg.Name, |
| 161 | arg.Description, |
| 162 | arg.Visibility, |
| 163 | arg.DefaultBranch, |
| 164 | arg.LicenseKey, |
| 165 | arg.PrimaryLanguage, |
| 166 | ) |
| 167 | var i Repo |
| 168 | err := row.Scan( |
| 169 | &i.ID, |
| 170 | &i.OwnerUserID, |
| 171 | &i.OwnerOrgID, |
| 172 | &i.Name, |
| 173 | &i.Description, |
| 174 | &i.Visibility, |
| 175 | &i.DefaultBranch, |
| 176 | &i.IsArchived, |
| 177 | &i.ArchivedAt, |
| 178 | &i.DeletedAt, |
| 179 | &i.DiskUsedBytes, |
| 180 | &i.ForkOfRepoID, |
| 181 | &i.LicenseKey, |
| 182 | &i.PrimaryLanguage, |
| 183 | &i.HasIssues, |
| 184 | &i.HasPulls, |
| 185 | &i.CreatedAt, |
| 186 | &i.UpdatedAt, |
| 187 | &i.DefaultBranchOid, |
| 188 | &i.AllowSquashMerge, |
| 189 | &i.AllowRebaseMerge, |
| 190 | &i.AllowMergeCommit, |
| 191 | &i.DefaultMergeMethod, |
| 192 | &i.StarCount, |
| 193 | &i.WatcherCount, |
| 194 | &i.ForkCount, |
| 195 | &i.InitStatus, |
| 196 | &i.LastIndexedOid, |
| 197 | ) |
| 198 | return i, err |
| 199 | } |
| 200 | |
| 201 | const deleteProfilePinsForSet = `-- name: DeleteProfilePinsForSet :exec |
| 202 | DELETE FROM profile_pins WHERE set_id = $1 |
| 203 | ` |
| 204 | |
| 205 | func (q *Queries) DeleteProfilePinsForSet(ctx context.Context, db DBTX, setID int64) error { |
| 206 | _, err := db.Exec(ctx, deleteProfilePinsForSet, setID) |
| 207 | return err |
| 208 | } |
| 209 | |
| 210 | const existsRepoForOwnerOrg = `-- name: ExistsRepoForOwnerOrg :one |
| 211 | SELECT EXISTS( |
| 212 | SELECT 1 FROM repos |
| 213 | WHERE owner_org_id = $1 AND name = $2 AND deleted_at IS NULL |
| 214 | ) |
| 215 | ` |
| 216 | |
| 217 | type ExistsRepoForOwnerOrgParams struct { |
| 218 | OwnerOrgID pgtype.Int8 |
| 219 | Name string |
| 220 | } |
| 221 | |
| 222 | func (q *Queries) ExistsRepoForOwnerOrg(ctx context.Context, db DBTX, arg ExistsRepoForOwnerOrgParams) (bool, error) { |
| 223 | row := db.QueryRow(ctx, existsRepoForOwnerOrg, arg.OwnerOrgID, arg.Name) |
| 224 | var exists bool |
| 225 | err := row.Scan(&exists) |
| 226 | return exists, err |
| 227 | } |
| 228 | |
| 229 | const existsRepoForOwnerUser = `-- name: ExistsRepoForOwnerUser :one |
| 230 | SELECT EXISTS( |
| 231 | SELECT 1 FROM repos |
| 232 | WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL |
| 233 | ) |
| 234 | ` |
| 235 | |
| 236 | type ExistsRepoForOwnerUserParams struct { |
| 237 | OwnerUserID pgtype.Int8 |
| 238 | Name string |
| 239 | } |
| 240 | |
| 241 | func (q *Queries) ExistsRepoForOwnerUser(ctx context.Context, db DBTX, arg ExistsRepoForOwnerUserParams) (bool, error) { |
| 242 | row := db.QueryRow(ctx, existsRepoForOwnerUser, arg.OwnerUserID, arg.Name) |
| 243 | var exists bool |
| 244 | err := row.Scan(&exists) |
| 245 | return exists, err |
| 246 | } |
| 247 | |
| 248 | const getProfilePinSetForOrg = `-- name: GetProfilePinSetForOrg :one |
| 249 | SELECT id FROM profile_pin_sets WHERE owner_org_id = $1 |
| 250 | ` |
| 251 | |
| 252 | func (q *Queries) GetProfilePinSetForOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) (int64, error) { |
| 253 | row := db.QueryRow(ctx, getProfilePinSetForOrg, ownerOrgID) |
| 254 | var id int64 |
| 255 | err := row.Scan(&id) |
| 256 | return id, err |
| 257 | } |
| 258 | |
| 259 | const getProfilePinSetForUser = `-- name: GetProfilePinSetForUser :one |
| 260 | |
| 261 | SELECT id FROM profile_pin_sets WHERE owner_user_id = $1 |
| 262 | ` |
| 263 | |
| 264 | // ─── profile/org pinned repositories ─────────────────────────────── |
| 265 | func (q *Queries) GetProfilePinSetForUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) (int64, error) { |
| 266 | row := db.QueryRow(ctx, getProfilePinSetForUser, ownerUserID) |
| 267 | var id int64 |
| 268 | err := row.Scan(&id) |
| 269 | return id, err |
| 270 | } |
| 271 | |
| 272 | const getRepoByID = `-- name: GetRepoByID :one |
| 273 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 274 | default_branch, is_archived, archived_at, deleted_at, |
| 275 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 276 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 277 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 278 | star_count, watcher_count, fork_count, init_status, |
| 279 | last_indexed_oid |
| 280 | FROM repos |
| 281 | WHERE id = $1 |
| 282 | ` |
| 283 | |
| 284 | func (q *Queries) GetRepoByID(ctx context.Context, db DBTX, id int64) (Repo, error) { |
| 285 | row := db.QueryRow(ctx, getRepoByID, id) |
| 286 | var i Repo |
| 287 | err := row.Scan( |
| 288 | &i.ID, |
| 289 | &i.OwnerUserID, |
| 290 | &i.OwnerOrgID, |
| 291 | &i.Name, |
| 292 | &i.Description, |
| 293 | &i.Visibility, |
| 294 | &i.DefaultBranch, |
| 295 | &i.IsArchived, |
| 296 | &i.ArchivedAt, |
| 297 | &i.DeletedAt, |
| 298 | &i.DiskUsedBytes, |
| 299 | &i.ForkOfRepoID, |
| 300 | &i.LicenseKey, |
| 301 | &i.PrimaryLanguage, |
| 302 | &i.HasIssues, |
| 303 | &i.HasPulls, |
| 304 | &i.CreatedAt, |
| 305 | &i.UpdatedAt, |
| 306 | &i.DefaultBranchOid, |
| 307 | &i.AllowSquashMerge, |
| 308 | &i.AllowRebaseMerge, |
| 309 | &i.AllowMergeCommit, |
| 310 | &i.DefaultMergeMethod, |
| 311 | &i.StarCount, |
| 312 | &i.WatcherCount, |
| 313 | &i.ForkCount, |
| 314 | &i.InitStatus, |
| 315 | &i.LastIndexedOid, |
| 316 | ) |
| 317 | return i, err |
| 318 | } |
| 319 | |
| 320 | const getRepoByOwnerOrgAndName = `-- name: GetRepoByOwnerOrgAndName :one |
| 321 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 322 | default_branch, is_archived, archived_at, deleted_at, |
| 323 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 324 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 325 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 326 | star_count, watcher_count, fork_count, init_status, |
| 327 | last_indexed_oid |
| 328 | FROM repos |
| 329 | WHERE owner_org_id = $1 AND name = $2 AND deleted_at IS NULL |
| 330 | ` |
| 331 | |
| 332 | type GetRepoByOwnerOrgAndNameParams struct { |
| 333 | OwnerOrgID pgtype.Int8 |
| 334 | Name string |
| 335 | } |
| 336 | |
| 337 | // S30: org-owner mirror of GetRepoByOwnerUserAndName. The (owner_org_id, |
| 338 | // name) partial unique index from 0017 backs this lookup with the same |
| 339 | // O(1) cost the user-side path enjoys. |
| 340 | func (q *Queries) GetRepoByOwnerOrgAndName(ctx context.Context, db DBTX, arg GetRepoByOwnerOrgAndNameParams) (Repo, error) { |
| 341 | row := db.QueryRow(ctx, getRepoByOwnerOrgAndName, arg.OwnerOrgID, arg.Name) |
| 342 | var i Repo |
| 343 | err := row.Scan( |
| 344 | &i.ID, |
| 345 | &i.OwnerUserID, |
| 346 | &i.OwnerOrgID, |
| 347 | &i.Name, |
| 348 | &i.Description, |
| 349 | &i.Visibility, |
| 350 | &i.DefaultBranch, |
| 351 | &i.IsArchived, |
| 352 | &i.ArchivedAt, |
| 353 | &i.DeletedAt, |
| 354 | &i.DiskUsedBytes, |
| 355 | &i.ForkOfRepoID, |
| 356 | &i.LicenseKey, |
| 357 | &i.PrimaryLanguage, |
| 358 | &i.HasIssues, |
| 359 | &i.HasPulls, |
| 360 | &i.CreatedAt, |
| 361 | &i.UpdatedAt, |
| 362 | &i.DefaultBranchOid, |
| 363 | &i.AllowSquashMerge, |
| 364 | &i.AllowRebaseMerge, |
| 365 | &i.AllowMergeCommit, |
| 366 | &i.DefaultMergeMethod, |
| 367 | &i.StarCount, |
| 368 | &i.WatcherCount, |
| 369 | &i.ForkCount, |
| 370 | &i.InitStatus, |
| 371 | &i.LastIndexedOid, |
| 372 | ) |
| 373 | return i, err |
| 374 | } |
| 375 | |
| 376 | const getRepoByOwnerUserAndName = `-- name: GetRepoByOwnerUserAndName :one |
| 377 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 378 | default_branch, is_archived, archived_at, deleted_at, |
| 379 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 380 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 381 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 382 | star_count, watcher_count, fork_count, init_status, |
| 383 | last_indexed_oid |
| 384 | FROM repos |
| 385 | WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL |
| 386 | ` |
| 387 | |
| 388 | type GetRepoByOwnerUserAndNameParams struct { |
| 389 | OwnerUserID pgtype.Int8 |
| 390 | Name string |
| 391 | } |
| 392 | |
| 393 | func (q *Queries) GetRepoByOwnerUserAndName(ctx context.Context, db DBTX, arg GetRepoByOwnerUserAndNameParams) (Repo, error) { |
| 394 | row := db.QueryRow(ctx, getRepoByOwnerUserAndName, arg.OwnerUserID, arg.Name) |
| 395 | var i Repo |
| 396 | err := row.Scan( |
| 397 | &i.ID, |
| 398 | &i.OwnerUserID, |
| 399 | &i.OwnerOrgID, |
| 400 | &i.Name, |
| 401 | &i.Description, |
| 402 | &i.Visibility, |
| 403 | &i.DefaultBranch, |
| 404 | &i.IsArchived, |
| 405 | &i.ArchivedAt, |
| 406 | &i.DeletedAt, |
| 407 | &i.DiskUsedBytes, |
| 408 | &i.ForkOfRepoID, |
| 409 | &i.LicenseKey, |
| 410 | &i.PrimaryLanguage, |
| 411 | &i.HasIssues, |
| 412 | &i.HasPulls, |
| 413 | &i.CreatedAt, |
| 414 | &i.UpdatedAt, |
| 415 | &i.DefaultBranchOid, |
| 416 | &i.AllowSquashMerge, |
| 417 | &i.AllowRebaseMerge, |
| 418 | &i.AllowMergeCommit, |
| 419 | &i.DefaultMergeMethod, |
| 420 | &i.StarCount, |
| 421 | &i.WatcherCount, |
| 422 | &i.ForkCount, |
| 423 | &i.InitStatus, |
| 424 | &i.LastIndexedOid, |
| 425 | ) |
| 426 | return i, err |
| 427 | } |
| 428 | |
| 429 | const getRepoOwnerUsernameByID = `-- name: GetRepoOwnerUsernameByID :one |
| 430 | SELECT u.username AS owner_username, r.name AS repo_name |
| 431 | FROM repos r |
| 432 | JOIN users u ON u.id = r.owner_user_id |
| 433 | WHERE r.id = $1 |
| 434 | ` |
| 435 | |
| 436 | type GetRepoOwnerUsernameByIDRow struct { |
| 437 | OwnerUsername string |
| 438 | RepoName string |
| 439 | } |
| 440 | |
| 441 | // Returns the owner_username for a repo. Used by size-recalc and other |
| 442 | // jobs that need to derive the bare-repo on-disk path without round- |
| 443 | // tripping through the full user row. |
| 444 | func (q *Queries) GetRepoOwnerUsernameByID(ctx context.Context, db DBTX, id int64) (GetRepoOwnerUsernameByIDRow, error) { |
| 445 | row := db.QueryRow(ctx, getRepoOwnerUsernameByID, id) |
| 446 | var i GetRepoOwnerUsernameByIDRow |
| 447 | err := row.Scan(&i.OwnerUsername, &i.RepoName) |
| 448 | return i, err |
| 449 | } |
| 450 | |
| 451 | const getSoftDeletedRepoByOwnerOrgAndName = `-- name: GetSoftDeletedRepoByOwnerOrgAndName :one |
| 452 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 453 | default_branch, is_archived, archived_at, deleted_at, |
| 454 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 455 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 456 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 457 | star_count, watcher_count, fork_count, init_status, |
| 458 | last_indexed_oid |
| 459 | FROM repos |
| 460 | WHERE owner_org_id = $1 AND name = $2 AND deleted_at IS NOT NULL |
| 461 | ORDER BY deleted_at DESC, id DESC |
| 462 | LIMIT 1 |
| 463 | ` |
| 464 | |
| 465 | type GetSoftDeletedRepoByOwnerOrgAndNameParams struct { |
| 466 | OwnerOrgID pgtype.Int8 |
| 467 | Name string |
| 468 | } |
| 469 | |
| 470 | func (q *Queries) GetSoftDeletedRepoByOwnerOrgAndName(ctx context.Context, db DBTX, arg GetSoftDeletedRepoByOwnerOrgAndNameParams) (Repo, error) { |
| 471 | row := db.QueryRow(ctx, getSoftDeletedRepoByOwnerOrgAndName, arg.OwnerOrgID, arg.Name) |
| 472 | var i Repo |
| 473 | err := row.Scan( |
| 474 | &i.ID, |
| 475 | &i.OwnerUserID, |
| 476 | &i.OwnerOrgID, |
| 477 | &i.Name, |
| 478 | &i.Description, |
| 479 | &i.Visibility, |
| 480 | &i.DefaultBranch, |
| 481 | &i.IsArchived, |
| 482 | &i.ArchivedAt, |
| 483 | &i.DeletedAt, |
| 484 | &i.DiskUsedBytes, |
| 485 | &i.ForkOfRepoID, |
| 486 | &i.LicenseKey, |
| 487 | &i.PrimaryLanguage, |
| 488 | &i.HasIssues, |
| 489 | &i.HasPulls, |
| 490 | &i.CreatedAt, |
| 491 | &i.UpdatedAt, |
| 492 | &i.DefaultBranchOid, |
| 493 | &i.AllowSquashMerge, |
| 494 | &i.AllowRebaseMerge, |
| 495 | &i.AllowMergeCommit, |
| 496 | &i.DefaultMergeMethod, |
| 497 | &i.StarCount, |
| 498 | &i.WatcherCount, |
| 499 | &i.ForkCount, |
| 500 | &i.InitStatus, |
| 501 | &i.LastIndexedOid, |
| 502 | ) |
| 503 | return i, err |
| 504 | } |
| 505 | |
| 506 | const getSoftDeletedRepoByOwnerUserAndName = `-- name: GetSoftDeletedRepoByOwnerUserAndName :one |
| 507 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 508 | default_branch, is_archived, archived_at, deleted_at, |
| 509 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 510 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 511 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 512 | star_count, watcher_count, fork_count, init_status, |
| 513 | last_indexed_oid |
| 514 | FROM repos |
| 515 | WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NOT NULL |
| 516 | ORDER BY deleted_at DESC, id DESC |
| 517 | LIMIT 1 |
| 518 | ` |
| 519 | |
| 520 | type GetSoftDeletedRepoByOwnerUserAndNameParams struct { |
| 521 | OwnerUserID pgtype.Int8 |
| 522 | Name string |
| 523 | } |
| 524 | |
| 525 | func (q *Queries) GetSoftDeletedRepoByOwnerUserAndName(ctx context.Context, db DBTX, arg GetSoftDeletedRepoByOwnerUserAndNameParams) (Repo, error) { |
| 526 | row := db.QueryRow(ctx, getSoftDeletedRepoByOwnerUserAndName, arg.OwnerUserID, arg.Name) |
| 527 | var i Repo |
| 528 | err := row.Scan( |
| 529 | &i.ID, |
| 530 | &i.OwnerUserID, |
| 531 | &i.OwnerOrgID, |
| 532 | &i.Name, |
| 533 | &i.Description, |
| 534 | &i.Visibility, |
| 535 | &i.DefaultBranch, |
| 536 | &i.IsArchived, |
| 537 | &i.ArchivedAt, |
| 538 | &i.DeletedAt, |
| 539 | &i.DiskUsedBytes, |
| 540 | &i.ForkOfRepoID, |
| 541 | &i.LicenseKey, |
| 542 | &i.PrimaryLanguage, |
| 543 | &i.HasIssues, |
| 544 | &i.HasPulls, |
| 545 | &i.CreatedAt, |
| 546 | &i.UpdatedAt, |
| 547 | &i.DefaultBranchOid, |
| 548 | &i.AllowSquashMerge, |
| 549 | &i.AllowRebaseMerge, |
| 550 | &i.AllowMergeCommit, |
| 551 | &i.DefaultMergeMethod, |
| 552 | &i.StarCount, |
| 553 | &i.WatcherCount, |
| 554 | &i.ForkCount, |
| 555 | &i.InitStatus, |
| 556 | &i.LastIndexedOid, |
| 557 | ) |
| 558 | return i, err |
| 559 | } |
| 560 | |
| 561 | const insertProfilePin = `-- name: InsertProfilePin :exec |
| 562 | INSERT INTO profile_pins (set_id, repo_id, position) |
| 563 | VALUES ($1, $2, $3) |
| 564 | ` |
| 565 | |
| 566 | type InsertProfilePinParams struct { |
| 567 | SetID int64 |
| 568 | RepoID int64 |
| 569 | Position int32 |
| 570 | } |
| 571 | |
| 572 | func (q *Queries) InsertProfilePin(ctx context.Context, db DBTX, arg InsertProfilePinParams) error { |
| 573 | _, err := db.Exec(ctx, insertProfilePin, arg.SetID, arg.RepoID, arg.Position) |
| 574 | return err |
| 575 | } |
| 576 | |
| 577 | const insertRepoTopic = `-- name: InsertRepoTopic :exec |
| 578 | INSERT INTO repo_topics (repo_id, topic) |
| 579 | VALUES ($1, $2) |
| 580 | ON CONFLICT DO NOTHING |
| 581 | ` |
| 582 | |
| 583 | type InsertRepoTopicParams struct { |
| 584 | RepoID int64 |
| 585 | Topic string |
| 586 | } |
| 587 | |
| 588 | func (q *Queries) InsertRepoTopic(ctx context.Context, db DBTX, arg InsertRepoTopicParams) error { |
| 589 | _, err := db.Exec(ctx, insertRepoTopic, arg.RepoID, arg.Topic) |
| 590 | return err |
| 591 | } |
| 592 | |
| 593 | const listAllRepoFullNames = `-- name: ListAllRepoFullNames :many |
| 594 | SELECT |
| 595 | r.id, |
| 596 | r.name, |
| 597 | u.username AS owner_username |
| 598 | FROM repos r |
| 599 | JOIN users u ON u.id = r.owner_user_id |
| 600 | WHERE r.deleted_at IS NULL |
| 601 | ORDER BY r.id |
| 602 | ` |
| 603 | |
| 604 | type ListAllRepoFullNamesRow struct { |
| 605 | ID int64 |
| 606 | Name string |
| 607 | OwnerUsername string |
| 608 | } |
| 609 | |
| 610 | // Used by `shithubd hooks reinstall --all` to enumerate every active |
| 611 | // bare repo on disk and re-link its hooks. |
| 612 | func (q *Queries) ListAllRepoFullNames(ctx context.Context, db DBTX) ([]ListAllRepoFullNamesRow, error) { |
| 613 | rows, err := db.Query(ctx, listAllRepoFullNames) |
| 614 | if err != nil { |
| 615 | return nil, err |
| 616 | } |
| 617 | defer rows.Close() |
| 618 | items := []ListAllRepoFullNamesRow{} |
| 619 | for rows.Next() { |
| 620 | var i ListAllRepoFullNamesRow |
| 621 | if err := rows.Scan(&i.ID, &i.Name, &i.OwnerUsername); err != nil { |
| 622 | return nil, err |
| 623 | } |
| 624 | items = append(items, i) |
| 625 | } |
| 626 | if err := rows.Err(); err != nil { |
| 627 | return nil, err |
| 628 | } |
| 629 | return items, nil |
| 630 | } |
| 631 | |
| 632 | const listForksOfRepo = `-- name: ListForksOfRepo :many |
| 633 | SELECT r.id, r.name, r.description, r.visibility, r.created_at, |
| 634 | r.star_count, r.fork_count, r.init_status, |
| 635 | u.username AS owner_username, u.display_name AS owner_display_name |
| 636 | FROM repos r |
| 637 | JOIN users u ON u.id = r.owner_user_id |
| 638 | WHERE r.fork_of_repo_id = $1 |
| 639 | AND r.deleted_at IS NULL |
| 640 | ORDER BY r.created_at DESC |
| 641 | LIMIT $2 OFFSET $3 |
| 642 | ` |
| 643 | |
| 644 | type ListForksOfRepoParams struct { |
| 645 | ForkOfRepoID pgtype.Int8 |
| 646 | Limit int32 |
| 647 | Offset int32 |
| 648 | } |
| 649 | |
| 650 | type ListForksOfRepoRow struct { |
| 651 | ID int64 |
| 652 | Name string |
| 653 | Description string |
| 654 | Visibility RepoVisibility |
| 655 | CreatedAt pgtype.Timestamptz |
| 656 | StarCount int64 |
| 657 | ForkCount int64 |
| 658 | InitStatus RepoInitStatus |
| 659 | OwnerUsername string |
| 660 | OwnerDisplayName string |
| 661 | } |
| 662 | |
| 663 | // Forks of a given source repo, paginated, recency-sorted. Joined |
| 664 | // with users for the owner display name. Excludes soft-deleted. |
| 665 | func (q *Queries) ListForksOfRepo(ctx context.Context, db DBTX, arg ListForksOfRepoParams) ([]ListForksOfRepoRow, error) { |
| 666 | rows, err := db.Query(ctx, listForksOfRepo, arg.ForkOfRepoID, arg.Limit, arg.Offset) |
| 667 | if err != nil { |
| 668 | return nil, err |
| 669 | } |
| 670 | defer rows.Close() |
| 671 | items := []ListForksOfRepoRow{} |
| 672 | for rows.Next() { |
| 673 | var i ListForksOfRepoRow |
| 674 | if err := rows.Scan( |
| 675 | &i.ID, |
| 676 | &i.Name, |
| 677 | &i.Description, |
| 678 | &i.Visibility, |
| 679 | &i.CreatedAt, |
| 680 | &i.StarCount, |
| 681 | &i.ForkCount, |
| 682 | &i.InitStatus, |
| 683 | &i.OwnerUsername, |
| 684 | &i.OwnerDisplayName, |
| 685 | ); err != nil { |
| 686 | return nil, err |
| 687 | } |
| 688 | items = append(items, i) |
| 689 | } |
| 690 | if err := rows.Err(); err != nil { |
| 691 | return nil, err |
| 692 | } |
| 693 | return items, nil |
| 694 | } |
| 695 | |
| 696 | const listForksOfRepoForRepack = `-- name: ListForksOfRepoForRepack :many |
| 697 | SELECT r.id, r.name, u.username AS owner_username |
| 698 | FROM repos r |
| 699 | JOIN users u ON u.id = r.owner_user_id |
| 700 | WHERE r.fork_of_repo_id = $1 |
| 701 | AND r.deleted_at IS NULL |
| 702 | ` |
| 703 | |
| 704 | type ListForksOfRepoForRepackRow struct { |
| 705 | ID int64 |
| 706 | Name string |
| 707 | OwnerUsername string |
| 708 | } |
| 709 | |
| 710 | // Used by S16's hard-delete cascade (S27 amendment): before deleting |
| 711 | // a source repo, every fork must `git repack -a -d --no-shared` so |
| 712 | // it has its own copy of the objects. Returns just enough to locate |
| 713 | // the bare repo on disk. |
| 714 | func (q *Queries) ListForksOfRepoForRepack(ctx context.Context, db DBTX, forkOfRepoID pgtype.Int8) ([]ListForksOfRepoForRepackRow, error) { |
| 715 | rows, err := db.Query(ctx, listForksOfRepoForRepack, forkOfRepoID) |
| 716 | if err != nil { |
| 717 | return nil, err |
| 718 | } |
| 719 | defer rows.Close() |
| 720 | items := []ListForksOfRepoForRepackRow{} |
| 721 | for rows.Next() { |
| 722 | var i ListForksOfRepoForRepackRow |
| 723 | if err := rows.Scan(&i.ID, &i.Name, &i.OwnerUsername); err != nil { |
| 724 | return nil, err |
| 725 | } |
| 726 | items = append(items, i) |
| 727 | } |
| 728 | if err := rows.Err(); err != nil { |
| 729 | return nil, err |
| 730 | } |
| 731 | return items, nil |
| 732 | } |
| 733 | |
| 734 | const listProfilePinsForSet = `-- name: ListProfilePinsForSet :many |
| 735 | SELECT repo_id, position |
| 736 | FROM profile_pins |
| 737 | WHERE set_id = $1 |
| 738 | ORDER BY position ASC |
| 739 | ` |
| 740 | |
| 741 | type ListProfilePinsForSetRow struct { |
| 742 | RepoID int64 |
| 743 | Position int32 |
| 744 | } |
| 745 | |
| 746 | func (q *Queries) ListProfilePinsForSet(ctx context.Context, db DBTX, setID int64) ([]ListProfilePinsForSetRow, error) { |
| 747 | rows, err := db.Query(ctx, listProfilePinsForSet, setID) |
| 748 | if err != nil { |
| 749 | return nil, err |
| 750 | } |
| 751 | defer rows.Close() |
| 752 | items := []ListProfilePinsForSetRow{} |
| 753 | for rows.Next() { |
| 754 | var i ListProfilePinsForSetRow |
| 755 | if err := rows.Scan(&i.RepoID, &i.Position); err != nil { |
| 756 | return nil, err |
| 757 | } |
| 758 | items = append(items, i) |
| 759 | } |
| 760 | if err := rows.Err(); err != nil { |
| 761 | return nil, err |
| 762 | } |
| 763 | return items, nil |
| 764 | } |
| 765 | |
| 766 | const listPublicContributionRepos = `-- name: ListPublicContributionRepos :many |
| 767 | 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 |
| 768 | FROM repos r |
| 769 | LEFT JOIN users u ON u.id = r.owner_user_id |
| 770 | LEFT JOIN orgs o ON o.id = r.owner_org_id |
| 771 | WHERE r.deleted_at IS NULL |
| 772 | AND r.visibility = 'public' |
| 773 | AND ( |
| 774 | (r.owner_user_id IS NOT NULL AND u.deleted_at IS NULL AND u.suspended_at IS NULL) |
| 775 | OR (r.owner_org_id IS NOT NULL AND o.deleted_at IS NULL) |
| 776 | ) |
| 777 | ORDER BY r.updated_at DESC, r.id DESC |
| 778 | LIMIT $1 |
| 779 | ` |
| 780 | |
| 781 | type ListPublicContributionReposRow struct { |
| 782 | Repo Repo |
| 783 | OwnerSlug string |
| 784 | } |
| 785 | |
| 786 | func (q *Queries) ListPublicContributionRepos(ctx context.Context, db DBTX, limit int32) ([]ListPublicContributionReposRow, error) { |
| 787 | rows, err := db.Query(ctx, listPublicContributionRepos, limit) |
| 788 | if err != nil { |
| 789 | return nil, err |
| 790 | } |
| 791 | defer rows.Close() |
| 792 | items := []ListPublicContributionReposRow{} |
| 793 | for rows.Next() { |
| 794 | var i ListPublicContributionReposRow |
| 795 | if err := rows.Scan( |
| 796 | &i.Repo.ID, |
| 797 | &i.Repo.OwnerUserID, |
| 798 | &i.Repo.OwnerOrgID, |
| 799 | &i.Repo.Name, |
| 800 | &i.Repo.Description, |
| 801 | &i.Repo.Visibility, |
| 802 | &i.Repo.DefaultBranch, |
| 803 | &i.Repo.IsArchived, |
| 804 | &i.Repo.ArchivedAt, |
| 805 | &i.Repo.DeletedAt, |
| 806 | &i.Repo.DiskUsedBytes, |
| 807 | &i.Repo.ForkOfRepoID, |
| 808 | &i.Repo.LicenseKey, |
| 809 | &i.Repo.PrimaryLanguage, |
| 810 | &i.Repo.HasIssues, |
| 811 | &i.Repo.HasPulls, |
| 812 | &i.Repo.CreatedAt, |
| 813 | &i.Repo.UpdatedAt, |
| 814 | &i.Repo.DefaultBranchOid, |
| 815 | &i.Repo.AllowSquashMerge, |
| 816 | &i.Repo.AllowRebaseMerge, |
| 817 | &i.Repo.AllowMergeCommit, |
| 818 | &i.Repo.DefaultMergeMethod, |
| 819 | &i.Repo.StarCount, |
| 820 | &i.Repo.WatcherCount, |
| 821 | &i.Repo.ForkCount, |
| 822 | &i.Repo.InitStatus, |
| 823 | &i.Repo.LastIndexedOid, |
| 824 | &i.OwnerSlug, |
| 825 | ); err != nil { |
| 826 | return nil, err |
| 827 | } |
| 828 | items = append(items, i) |
| 829 | } |
| 830 | if err := rows.Err(); err != nil { |
| 831 | return nil, err |
| 832 | } |
| 833 | return items, nil |
| 834 | } |
| 835 | |
| 836 | const listRepoTopics = `-- name: ListRepoTopics :many |
| 837 | |
| 838 | SELECT topic FROM repo_topics WHERE repo_id = $1 ORDER BY topic ASC |
| 839 | ` |
| 840 | |
| 841 | // ─── repo_topics (S32) ───────────────────────────────────────────── |
| 842 | func (q *Queries) ListRepoTopics(ctx context.Context, db DBTX, repoID int64) ([]string, error) { |
| 843 | rows, err := db.Query(ctx, listRepoTopics, repoID) |
| 844 | if err != nil { |
| 845 | return nil, err |
| 846 | } |
| 847 | defer rows.Close() |
| 848 | items := []string{} |
| 849 | for rows.Next() { |
| 850 | var topic string |
| 851 | if err := rows.Scan(&topic); err != nil { |
| 852 | return nil, err |
| 853 | } |
| 854 | items = append(items, topic) |
| 855 | } |
| 856 | if err := rows.Err(); err != nil { |
| 857 | return nil, err |
| 858 | } |
| 859 | return items, nil |
| 860 | } |
| 861 | |
| 862 | const listReposForOwnerOrg = `-- name: ListReposForOwnerOrg :many |
| 863 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 864 | default_branch, is_archived, archived_at, deleted_at, |
| 865 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 866 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 867 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 868 | star_count, watcher_count, fork_count, init_status, |
| 869 | last_indexed_oid |
| 870 | FROM repos |
| 871 | WHERE owner_org_id = $1 AND deleted_at IS NULL |
| 872 | ORDER BY updated_at DESC |
| 873 | ` |
| 874 | |
| 875 | func (q *Queries) ListReposForOwnerOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) ([]Repo, error) { |
| 876 | rows, err := db.Query(ctx, listReposForOwnerOrg, ownerOrgID) |
| 877 | if err != nil { |
| 878 | return nil, err |
| 879 | } |
| 880 | defer rows.Close() |
| 881 | items := []Repo{} |
| 882 | for rows.Next() { |
| 883 | var i Repo |
| 884 | if err := rows.Scan( |
| 885 | &i.ID, |
| 886 | &i.OwnerUserID, |
| 887 | &i.OwnerOrgID, |
| 888 | &i.Name, |
| 889 | &i.Description, |
| 890 | &i.Visibility, |
| 891 | &i.DefaultBranch, |
| 892 | &i.IsArchived, |
| 893 | &i.ArchivedAt, |
| 894 | &i.DeletedAt, |
| 895 | &i.DiskUsedBytes, |
| 896 | &i.ForkOfRepoID, |
| 897 | &i.LicenseKey, |
| 898 | &i.PrimaryLanguage, |
| 899 | &i.HasIssues, |
| 900 | &i.HasPulls, |
| 901 | &i.CreatedAt, |
| 902 | &i.UpdatedAt, |
| 903 | &i.DefaultBranchOid, |
| 904 | &i.AllowSquashMerge, |
| 905 | &i.AllowRebaseMerge, |
| 906 | &i.AllowMergeCommit, |
| 907 | &i.DefaultMergeMethod, |
| 908 | &i.StarCount, |
| 909 | &i.WatcherCount, |
| 910 | &i.ForkCount, |
| 911 | &i.InitStatus, |
| 912 | &i.LastIndexedOid, |
| 913 | ); err != nil { |
| 914 | return nil, err |
| 915 | } |
| 916 | items = append(items, i) |
| 917 | } |
| 918 | if err := rows.Err(); err != nil { |
| 919 | return nil, err |
| 920 | } |
| 921 | return items, nil |
| 922 | } |
| 923 | |
| 924 | const listReposForOwnerUser = `-- name: ListReposForOwnerUser :many |
| 925 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 926 | default_branch, is_archived, archived_at, deleted_at, |
| 927 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 928 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 929 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 930 | star_count, watcher_count, fork_count, init_status, |
| 931 | last_indexed_oid |
| 932 | FROM repos |
| 933 | WHERE owner_user_id = $1 AND deleted_at IS NULL |
| 934 | ORDER BY updated_at DESC |
| 935 | ` |
| 936 | |
| 937 | func (q *Queries) ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) ([]Repo, error) { |
| 938 | rows, err := db.Query(ctx, listReposForOwnerUser, ownerUserID) |
| 939 | if err != nil { |
| 940 | return nil, err |
| 941 | } |
| 942 | defer rows.Close() |
| 943 | items := []Repo{} |
| 944 | for rows.Next() { |
| 945 | var i Repo |
| 946 | if err := rows.Scan( |
| 947 | &i.ID, |
| 948 | &i.OwnerUserID, |
| 949 | &i.OwnerOrgID, |
| 950 | &i.Name, |
| 951 | &i.Description, |
| 952 | &i.Visibility, |
| 953 | &i.DefaultBranch, |
| 954 | &i.IsArchived, |
| 955 | &i.ArchivedAt, |
| 956 | &i.DeletedAt, |
| 957 | &i.DiskUsedBytes, |
| 958 | &i.ForkOfRepoID, |
| 959 | &i.LicenseKey, |
| 960 | &i.PrimaryLanguage, |
| 961 | &i.HasIssues, |
| 962 | &i.HasPulls, |
| 963 | &i.CreatedAt, |
| 964 | &i.UpdatedAt, |
| 965 | &i.DefaultBranchOid, |
| 966 | &i.AllowSquashMerge, |
| 967 | &i.AllowRebaseMerge, |
| 968 | &i.AllowMergeCommit, |
| 969 | &i.DefaultMergeMethod, |
| 970 | &i.StarCount, |
| 971 | &i.WatcherCount, |
| 972 | &i.ForkCount, |
| 973 | &i.InitStatus, |
| 974 | &i.LastIndexedOid, |
| 975 | ); err != nil { |
| 976 | return nil, err |
| 977 | } |
| 978 | items = append(items, i) |
| 979 | } |
| 980 | if err := rows.Err(); err != nil { |
| 981 | return nil, err |
| 982 | } |
| 983 | return items, nil |
| 984 | } |
| 985 | |
| 986 | const listReposNeedingReindex = `-- name: ListReposNeedingReindex :many |
| 987 | SELECT id, name, default_branch, default_branch_oid |
| 988 | FROM repos |
| 989 | WHERE deleted_at IS NULL |
| 990 | AND default_branch_oid IS NOT NULL |
| 991 | AND (last_indexed_oid IS NULL OR last_indexed_oid <> default_branch_oid) |
| 992 | ORDER BY id |
| 993 | LIMIT $1 |
| 994 | ` |
| 995 | |
| 996 | type ListReposNeedingReindexRow struct { |
| 997 | ID int64 |
| 998 | Name string |
| 999 | DefaultBranch string |
| 1000 | DefaultBranchOid pgtype.Text |
| 1001 | } |
| 1002 | |
| 1003 | // S28 code-search reconciler: returns repos whose default_branch_oid |
| 1004 | // has advanced past last_indexed_oid (or last_indexed_oid is NULL |
| 1005 | // and a default exists). Limited so a single tick of the cron |
| 1006 | // doesn't try to re-index the whole world. |
| 1007 | func (q *Queries) ListReposNeedingReindex(ctx context.Context, db DBTX, limit int32) ([]ListReposNeedingReindexRow, error) { |
| 1008 | rows, err := db.Query(ctx, listReposNeedingReindex, limit) |
| 1009 | if err != nil { |
| 1010 | return nil, err |
| 1011 | } |
| 1012 | defer rows.Close() |
| 1013 | items := []ListReposNeedingReindexRow{} |
| 1014 | for rows.Next() { |
| 1015 | var i ListReposNeedingReindexRow |
| 1016 | if err := rows.Scan( |
| 1017 | &i.ID, |
| 1018 | &i.Name, |
| 1019 | &i.DefaultBranch, |
| 1020 | &i.DefaultBranchOid, |
| 1021 | ); err != nil { |
| 1022 | return nil, err |
| 1023 | } |
| 1024 | items = append(items, i) |
| 1025 | } |
| 1026 | if err := rows.Err(); err != nil { |
| 1027 | return nil, err |
| 1028 | } |
| 1029 | return items, nil |
| 1030 | } |
| 1031 | |
| 1032 | const lockRepoOwnerName = `-- name: LockRepoOwnerName :exec |
| 1033 | SELECT pg_advisory_xact_lock(hashtextextended($1, 0)) |
| 1034 | ` |
| 1035 | |
| 1036 | // Serializes DB + filesystem operations for one logical owner/name |
| 1037 | // pair. Create, soft-delete, restore, and hard-delete all touch the |
| 1038 | // canonical bare path; a transaction-scoped advisory lock keeps those |
| 1039 | // cross-resource moves from racing. |
| 1040 | func (q *Queries) LockRepoOwnerName(ctx context.Context, db DBTX, hashtextextended string) error { |
| 1041 | _, err := db.Exec(ctx, lockRepoOwnerName, hashtextextended) |
| 1042 | return err |
| 1043 | } |
| 1044 | |
| 1045 | const replaceRepoTopics = `-- name: ReplaceRepoTopics :exec |
| 1046 | DELETE FROM repo_topics WHERE repo_id = $1 |
| 1047 | ` |
| 1048 | |
| 1049 | // Atomic full-replace: callers compose the new topic set in Go, |
| 1050 | // then replace the existing rows in one tx (DELETE + INSERT). The |
| 1051 | // caller's tx wraps both calls for atomicity. |
| 1052 | func (q *Queries) ReplaceRepoTopics(ctx context.Context, db DBTX, repoID int64) error { |
| 1053 | _, err := db.Exec(ctx, replaceRepoTopics, repoID) |
| 1054 | return err |
| 1055 | } |
| 1056 | |
| 1057 | const setLastIndexedOID = `-- name: SetLastIndexedOID :exec |
| 1058 | UPDATE repos SET last_indexed_oid = $2::text WHERE id = $1 |
| 1059 | ` |
| 1060 | |
| 1061 | type SetLastIndexedOIDParams struct { |
| 1062 | ID int64 |
| 1063 | LastIndexedOid pgtype.Text |
| 1064 | } |
| 1065 | |
| 1066 | // S28 code-search: the worker writes the OID it finished indexing |
| 1067 | // so the reconciler can detect drift (default_branch_oid moved but |
| 1068 | // last_indexed_oid lagged). |
| 1069 | func (q *Queries) SetLastIndexedOID(ctx context.Context, db DBTX, arg SetLastIndexedOIDParams) error { |
| 1070 | _, err := db.Exec(ctx, setLastIndexedOID, arg.ID, arg.LastIndexedOid) |
| 1071 | return err |
| 1072 | } |
| 1073 | |
| 1074 | const setRepoInitStatus = `-- name: SetRepoInitStatus :exec |
| 1075 | UPDATE repos SET init_status = $2 WHERE id = $1 |
| 1076 | ` |
| 1077 | |
| 1078 | type SetRepoInitStatusParams struct { |
| 1079 | ID int64 |
| 1080 | InitStatus RepoInitStatus |
| 1081 | } |
| 1082 | |
| 1083 | // Promotes a fork from init_pending to initialized (or init_failed). |
| 1084 | // The DB row is created up-front so the URL resolves immediately and |
| 1085 | // the user sees a "preparing your fork" placeholder while the worker |
| 1086 | // runs `git clone --bare --shared`. |
| 1087 | func (q *Queries) SetRepoInitStatus(ctx context.Context, db DBTX, arg SetRepoInitStatusParams) error { |
| 1088 | _, err := db.Exec(ctx, setRepoInitStatus, arg.ID, arg.InitStatus) |
| 1089 | return err |
| 1090 | } |
| 1091 | |
| 1092 | const softDeleteRepo = `-- name: SoftDeleteRepo :exec |
| 1093 | UPDATE repos SET deleted_at = now() WHERE id = $1 |
| 1094 | ` |
| 1095 | |
| 1096 | func (q *Queries) SoftDeleteRepo(ctx context.Context, db DBTX, id int64) error { |
| 1097 | _, err := db.Exec(ctx, softDeleteRepo, id) |
| 1098 | return err |
| 1099 | } |
| 1100 | |
| 1101 | const updateRepoDefaultBranchOID = `-- name: UpdateRepoDefaultBranchOID :exec |
| 1102 | UPDATE repos SET default_branch_oid = $2::text WHERE id = $1 |
| 1103 | ` |
| 1104 | |
| 1105 | type UpdateRepoDefaultBranchOIDParams struct { |
| 1106 | ID int64 |
| 1107 | DefaultBranchOid pgtype.Text |
| 1108 | } |
| 1109 | |
| 1110 | // Set when push:process detects a commit on the repo's default branch. |
| 1111 | // Pass NULL to clear (e.g. when the branch is force-deleted in a future |
| 1112 | // sprint). The repo home view reads this to decide between empty and |
| 1113 | // populated layouts. |
| 1114 | func (q *Queries) UpdateRepoDefaultBranchOID(ctx context.Context, db DBTX, arg UpdateRepoDefaultBranchOIDParams) error { |
| 1115 | _, err := db.Exec(ctx, updateRepoDefaultBranchOID, arg.ID, arg.DefaultBranchOid) |
| 1116 | return err |
| 1117 | } |
| 1118 | |
| 1119 | const updateRepoDiskUsed = `-- name: UpdateRepoDiskUsed :exec |
| 1120 | UPDATE repos SET disk_used_bytes = $2 WHERE id = $1 |
| 1121 | ` |
| 1122 | |
| 1123 | type UpdateRepoDiskUsedParams struct { |
| 1124 | ID int64 |
| 1125 | DiskUsedBytes int64 |
| 1126 | } |
| 1127 | |
| 1128 | func (q *Queries) UpdateRepoDiskUsed(ctx context.Context, db DBTX, arg UpdateRepoDiskUsedParams) error { |
| 1129 | _, err := db.Exec(ctx, updateRepoDiskUsed, arg.ID, arg.DiskUsedBytes) |
| 1130 | return err |
| 1131 | } |
| 1132 | |
| 1133 | const updateRepoGeneralSettings = `-- name: UpdateRepoGeneralSettings :exec |
| 1134 | UPDATE repos |
| 1135 | SET description = $2, |
| 1136 | has_issues = $3, |
| 1137 | has_pulls = $4, |
| 1138 | updated_at = now() |
| 1139 | WHERE id = $1 |
| 1140 | ` |
| 1141 | |
| 1142 | type UpdateRepoGeneralSettingsParams struct { |
| 1143 | ID int64 |
| 1144 | Description string |
| 1145 | HasIssues bool |
| 1146 | HasPulls bool |
| 1147 | } |
| 1148 | |
| 1149 | // S32: General-tab settings persist via this single query so each |
| 1150 | // form post is one round-trip. The merge-method toggles are kept |
| 1151 | // separate from the repo create flow because they're admin-only. |
| 1152 | func (q *Queries) UpdateRepoGeneralSettings(ctx context.Context, db DBTX, arg UpdateRepoGeneralSettingsParams) error { |
| 1153 | _, err := db.Exec(ctx, updateRepoGeneralSettings, |
| 1154 | arg.ID, |
| 1155 | arg.Description, |
| 1156 | arg.HasIssues, |
| 1157 | arg.HasPulls, |
| 1158 | ) |
| 1159 | return err |
| 1160 | } |
| 1161 | |
| 1162 | const updateRepoMergeSettings = `-- name: UpdateRepoMergeSettings :exec |
| 1163 | UPDATE repos |
| 1164 | SET allow_merge_commit = $2, |
| 1165 | allow_squash_merge = $3, |
| 1166 | allow_rebase_merge = $4, |
| 1167 | default_merge_method = $5, |
| 1168 | updated_at = now() |
| 1169 | WHERE id = $1 |
| 1170 | ` |
| 1171 | |
| 1172 | type UpdateRepoMergeSettingsParams struct { |
| 1173 | ID int64 |
| 1174 | AllowMergeCommit bool |
| 1175 | AllowSquashMerge bool |
| 1176 | AllowRebaseMerge bool |
| 1177 | DefaultMergeMethod PrMergeMethod |
| 1178 | } |
| 1179 | |
| 1180 | func (q *Queries) UpdateRepoMergeSettings(ctx context.Context, db DBTX, arg UpdateRepoMergeSettingsParams) error { |
| 1181 | _, err := db.Exec(ctx, updateRepoMergeSettings, |
| 1182 | arg.ID, |
| 1183 | arg.AllowMergeCommit, |
| 1184 | arg.AllowSquashMerge, |
| 1185 | arg.AllowRebaseMerge, |
| 1186 | arg.DefaultMergeMethod, |
| 1187 | ) |
| 1188 | return err |
| 1189 | } |
| 1190 | |
| 1191 | const upsertProfilePinSetForOrg = `-- name: UpsertProfilePinSetForOrg :one |
| 1192 | INSERT INTO profile_pin_sets (owner_org_id) |
| 1193 | VALUES ($1) |
| 1194 | ON CONFLICT (owner_org_id) WHERE owner_org_id IS NOT NULL |
| 1195 | DO UPDATE SET updated_at = now() |
| 1196 | RETURNING id |
| 1197 | ` |
| 1198 | |
| 1199 | func (q *Queries) UpsertProfilePinSetForOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) (int64, error) { |
| 1200 | row := db.QueryRow(ctx, upsertProfilePinSetForOrg, ownerOrgID) |
| 1201 | var id int64 |
| 1202 | err := row.Scan(&id) |
| 1203 | return id, err |
| 1204 | } |
| 1205 | |
| 1206 | const upsertProfilePinSetForUser = `-- name: UpsertProfilePinSetForUser :one |
| 1207 | INSERT INTO profile_pin_sets (owner_user_id) |
| 1208 | VALUES ($1) |
| 1209 | ON CONFLICT (owner_user_id) WHERE owner_user_id IS NOT NULL |
| 1210 | DO UPDATE SET updated_at = now() |
| 1211 | RETURNING id |
| 1212 | ` |
| 1213 | |
| 1214 | func (q *Queries) UpsertProfilePinSetForUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) (int64, error) { |
| 1215 | row := db.QueryRow(ctx, upsertProfilePinSetForUser, ownerUserID) |
| 1216 | var id int64 |
| 1217 | err := row.Scan(&id) |
| 1218 | return id, err |
| 1219 | } |
| 1220 |