| 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 insertProfilePin = `-- name: InsertProfilePin :exec |
| 452 | INSERT INTO profile_pins (set_id, repo_id, position) |
| 453 | VALUES ($1, $2, $3) |
| 454 | ` |
| 455 | |
| 456 | type InsertProfilePinParams struct { |
| 457 | SetID int64 |
| 458 | RepoID int64 |
| 459 | Position int32 |
| 460 | } |
| 461 | |
| 462 | func (q *Queries) InsertProfilePin(ctx context.Context, db DBTX, arg InsertProfilePinParams) error { |
| 463 | _, err := db.Exec(ctx, insertProfilePin, arg.SetID, arg.RepoID, arg.Position) |
| 464 | return err |
| 465 | } |
| 466 | |
| 467 | const insertRepoTopic = `-- name: InsertRepoTopic :exec |
| 468 | INSERT INTO repo_topics (repo_id, topic) |
| 469 | VALUES ($1, $2) |
| 470 | ON CONFLICT DO NOTHING |
| 471 | ` |
| 472 | |
| 473 | type InsertRepoTopicParams struct { |
| 474 | RepoID int64 |
| 475 | Topic string |
| 476 | } |
| 477 | |
| 478 | func (q *Queries) InsertRepoTopic(ctx context.Context, db DBTX, arg InsertRepoTopicParams) error { |
| 479 | _, err := db.Exec(ctx, insertRepoTopic, arg.RepoID, arg.Topic) |
| 480 | return err |
| 481 | } |
| 482 | |
| 483 | const listAllRepoFullNames = `-- name: ListAllRepoFullNames :many |
| 484 | SELECT |
| 485 | r.id, |
| 486 | r.name, |
| 487 | u.username AS owner_username |
| 488 | FROM repos r |
| 489 | JOIN users u ON u.id = r.owner_user_id |
| 490 | WHERE r.deleted_at IS NULL |
| 491 | ORDER BY r.id |
| 492 | ` |
| 493 | |
| 494 | type ListAllRepoFullNamesRow struct { |
| 495 | ID int64 |
| 496 | Name string |
| 497 | OwnerUsername string |
| 498 | } |
| 499 | |
| 500 | // Used by `shithubd hooks reinstall --all` to enumerate every active |
| 501 | // bare repo on disk and re-link its hooks. |
| 502 | func (q *Queries) ListAllRepoFullNames(ctx context.Context, db DBTX) ([]ListAllRepoFullNamesRow, error) { |
| 503 | rows, err := db.Query(ctx, listAllRepoFullNames) |
| 504 | if err != nil { |
| 505 | return nil, err |
| 506 | } |
| 507 | defer rows.Close() |
| 508 | items := []ListAllRepoFullNamesRow{} |
| 509 | for rows.Next() { |
| 510 | var i ListAllRepoFullNamesRow |
| 511 | if err := rows.Scan(&i.ID, &i.Name, &i.OwnerUsername); err != nil { |
| 512 | return nil, err |
| 513 | } |
| 514 | items = append(items, i) |
| 515 | } |
| 516 | if err := rows.Err(); err != nil { |
| 517 | return nil, err |
| 518 | } |
| 519 | return items, nil |
| 520 | } |
| 521 | |
| 522 | const listForksOfRepo = `-- name: ListForksOfRepo :many |
| 523 | SELECT r.id, r.name, r.description, r.visibility, r.created_at, |
| 524 | r.star_count, r.fork_count, r.init_status, |
| 525 | u.username AS owner_username, u.display_name AS owner_display_name |
| 526 | FROM repos r |
| 527 | JOIN users u ON u.id = r.owner_user_id |
| 528 | WHERE r.fork_of_repo_id = $1 |
| 529 | AND r.deleted_at IS NULL |
| 530 | ORDER BY r.created_at DESC |
| 531 | LIMIT $2 OFFSET $3 |
| 532 | ` |
| 533 | |
| 534 | type ListForksOfRepoParams struct { |
| 535 | ForkOfRepoID pgtype.Int8 |
| 536 | Limit int32 |
| 537 | Offset int32 |
| 538 | } |
| 539 | |
| 540 | type ListForksOfRepoRow struct { |
| 541 | ID int64 |
| 542 | Name string |
| 543 | Description string |
| 544 | Visibility RepoVisibility |
| 545 | CreatedAt pgtype.Timestamptz |
| 546 | StarCount int64 |
| 547 | ForkCount int64 |
| 548 | InitStatus RepoInitStatus |
| 549 | OwnerUsername string |
| 550 | OwnerDisplayName string |
| 551 | } |
| 552 | |
| 553 | // Forks of a given source repo, paginated, recency-sorted. Joined |
| 554 | // with users for the owner display name. Excludes soft-deleted. |
| 555 | func (q *Queries) ListForksOfRepo(ctx context.Context, db DBTX, arg ListForksOfRepoParams) ([]ListForksOfRepoRow, error) { |
| 556 | rows, err := db.Query(ctx, listForksOfRepo, arg.ForkOfRepoID, arg.Limit, arg.Offset) |
| 557 | if err != nil { |
| 558 | return nil, err |
| 559 | } |
| 560 | defer rows.Close() |
| 561 | items := []ListForksOfRepoRow{} |
| 562 | for rows.Next() { |
| 563 | var i ListForksOfRepoRow |
| 564 | if err := rows.Scan( |
| 565 | &i.ID, |
| 566 | &i.Name, |
| 567 | &i.Description, |
| 568 | &i.Visibility, |
| 569 | &i.CreatedAt, |
| 570 | &i.StarCount, |
| 571 | &i.ForkCount, |
| 572 | &i.InitStatus, |
| 573 | &i.OwnerUsername, |
| 574 | &i.OwnerDisplayName, |
| 575 | ); err != nil { |
| 576 | return nil, err |
| 577 | } |
| 578 | items = append(items, i) |
| 579 | } |
| 580 | if err := rows.Err(); err != nil { |
| 581 | return nil, err |
| 582 | } |
| 583 | return items, nil |
| 584 | } |
| 585 | |
| 586 | const listForksOfRepoForRepack = `-- name: ListForksOfRepoForRepack :many |
| 587 | SELECT r.id, r.name, u.username AS owner_username |
| 588 | FROM repos r |
| 589 | JOIN users u ON u.id = r.owner_user_id |
| 590 | WHERE r.fork_of_repo_id = $1 |
| 591 | AND r.deleted_at IS NULL |
| 592 | ` |
| 593 | |
| 594 | type ListForksOfRepoForRepackRow struct { |
| 595 | ID int64 |
| 596 | Name string |
| 597 | OwnerUsername string |
| 598 | } |
| 599 | |
| 600 | // Used by S16's hard-delete cascade (S27 amendment): before deleting |
| 601 | // a source repo, every fork must `git repack -a -d --no-shared` so |
| 602 | // it has its own copy of the objects. Returns just enough to locate |
| 603 | // the bare repo on disk. |
| 604 | func (q *Queries) ListForksOfRepoForRepack(ctx context.Context, db DBTX, forkOfRepoID pgtype.Int8) ([]ListForksOfRepoForRepackRow, error) { |
| 605 | rows, err := db.Query(ctx, listForksOfRepoForRepack, forkOfRepoID) |
| 606 | if err != nil { |
| 607 | return nil, err |
| 608 | } |
| 609 | defer rows.Close() |
| 610 | items := []ListForksOfRepoForRepackRow{} |
| 611 | for rows.Next() { |
| 612 | var i ListForksOfRepoForRepackRow |
| 613 | if err := rows.Scan(&i.ID, &i.Name, &i.OwnerUsername); err != nil { |
| 614 | return nil, err |
| 615 | } |
| 616 | items = append(items, i) |
| 617 | } |
| 618 | if err := rows.Err(); err != nil { |
| 619 | return nil, err |
| 620 | } |
| 621 | return items, nil |
| 622 | } |
| 623 | |
| 624 | const listProfilePinsForSet = `-- name: ListProfilePinsForSet :many |
| 625 | SELECT repo_id, position |
| 626 | FROM profile_pins |
| 627 | WHERE set_id = $1 |
| 628 | ORDER BY position ASC |
| 629 | ` |
| 630 | |
| 631 | type ListProfilePinsForSetRow struct { |
| 632 | RepoID int64 |
| 633 | Position int32 |
| 634 | } |
| 635 | |
| 636 | func (q *Queries) ListProfilePinsForSet(ctx context.Context, db DBTX, setID int64) ([]ListProfilePinsForSetRow, error) { |
| 637 | rows, err := db.Query(ctx, listProfilePinsForSet, setID) |
| 638 | if err != nil { |
| 639 | return nil, err |
| 640 | } |
| 641 | defer rows.Close() |
| 642 | items := []ListProfilePinsForSetRow{} |
| 643 | for rows.Next() { |
| 644 | var i ListProfilePinsForSetRow |
| 645 | if err := rows.Scan(&i.RepoID, &i.Position); err != nil { |
| 646 | return nil, err |
| 647 | } |
| 648 | items = append(items, i) |
| 649 | } |
| 650 | if err := rows.Err(); err != nil { |
| 651 | return nil, err |
| 652 | } |
| 653 | return items, nil |
| 654 | } |
| 655 | |
| 656 | const listPublicContributionRepos = `-- name: ListPublicContributionRepos :many |
| 657 | 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 |
| 658 | FROM repos r |
| 659 | LEFT JOIN users u ON u.id = r.owner_user_id |
| 660 | LEFT JOIN orgs o ON o.id = r.owner_org_id |
| 661 | WHERE r.deleted_at IS NULL |
| 662 | AND r.visibility = 'public' |
| 663 | AND ( |
| 664 | (r.owner_user_id IS NOT NULL AND u.deleted_at IS NULL AND u.suspended_at IS NULL) |
| 665 | OR (r.owner_org_id IS NOT NULL AND o.deleted_at IS NULL) |
| 666 | ) |
| 667 | ORDER BY r.updated_at DESC, r.id DESC |
| 668 | LIMIT $1 |
| 669 | ` |
| 670 | |
| 671 | type ListPublicContributionReposRow struct { |
| 672 | Repo Repo |
| 673 | OwnerSlug string |
| 674 | } |
| 675 | |
| 676 | func (q *Queries) ListPublicContributionRepos(ctx context.Context, db DBTX, limit int32) ([]ListPublicContributionReposRow, error) { |
| 677 | rows, err := db.Query(ctx, listPublicContributionRepos, limit) |
| 678 | if err != nil { |
| 679 | return nil, err |
| 680 | } |
| 681 | defer rows.Close() |
| 682 | items := []ListPublicContributionReposRow{} |
| 683 | for rows.Next() { |
| 684 | var i ListPublicContributionReposRow |
| 685 | if err := rows.Scan( |
| 686 | &i.Repo.ID, |
| 687 | &i.Repo.OwnerUserID, |
| 688 | &i.Repo.OwnerOrgID, |
| 689 | &i.Repo.Name, |
| 690 | &i.Repo.Description, |
| 691 | &i.Repo.Visibility, |
| 692 | &i.Repo.DefaultBranch, |
| 693 | &i.Repo.IsArchived, |
| 694 | &i.Repo.ArchivedAt, |
| 695 | &i.Repo.DeletedAt, |
| 696 | &i.Repo.DiskUsedBytes, |
| 697 | &i.Repo.ForkOfRepoID, |
| 698 | &i.Repo.LicenseKey, |
| 699 | &i.Repo.PrimaryLanguage, |
| 700 | &i.Repo.HasIssues, |
| 701 | &i.Repo.HasPulls, |
| 702 | &i.Repo.CreatedAt, |
| 703 | &i.Repo.UpdatedAt, |
| 704 | &i.Repo.DefaultBranchOid, |
| 705 | &i.Repo.AllowSquashMerge, |
| 706 | &i.Repo.AllowRebaseMerge, |
| 707 | &i.Repo.AllowMergeCommit, |
| 708 | &i.Repo.DefaultMergeMethod, |
| 709 | &i.Repo.StarCount, |
| 710 | &i.Repo.WatcherCount, |
| 711 | &i.Repo.ForkCount, |
| 712 | &i.Repo.InitStatus, |
| 713 | &i.Repo.LastIndexedOid, |
| 714 | &i.OwnerSlug, |
| 715 | ); err != nil { |
| 716 | return nil, err |
| 717 | } |
| 718 | items = append(items, i) |
| 719 | } |
| 720 | if err := rows.Err(); err != nil { |
| 721 | return nil, err |
| 722 | } |
| 723 | return items, nil |
| 724 | } |
| 725 | |
| 726 | const listRepoTopics = `-- name: ListRepoTopics :many |
| 727 | |
| 728 | SELECT topic FROM repo_topics WHERE repo_id = $1 ORDER BY topic ASC |
| 729 | ` |
| 730 | |
| 731 | // ─── repo_topics (S32) ───────────────────────────────────────────── |
| 732 | func (q *Queries) ListRepoTopics(ctx context.Context, db DBTX, repoID int64) ([]string, error) { |
| 733 | rows, err := db.Query(ctx, listRepoTopics, repoID) |
| 734 | if err != nil { |
| 735 | return nil, err |
| 736 | } |
| 737 | defer rows.Close() |
| 738 | items := []string{} |
| 739 | for rows.Next() { |
| 740 | var topic string |
| 741 | if err := rows.Scan(&topic); err != nil { |
| 742 | return nil, err |
| 743 | } |
| 744 | items = append(items, topic) |
| 745 | } |
| 746 | if err := rows.Err(); err != nil { |
| 747 | return nil, err |
| 748 | } |
| 749 | return items, nil |
| 750 | } |
| 751 | |
| 752 | const listReposForOwnerOrg = `-- name: ListReposForOwnerOrg :many |
| 753 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 754 | default_branch, is_archived, archived_at, deleted_at, |
| 755 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 756 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 757 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 758 | star_count, watcher_count, fork_count, init_status, |
| 759 | last_indexed_oid |
| 760 | FROM repos |
| 761 | WHERE owner_org_id = $1 AND deleted_at IS NULL |
| 762 | ORDER BY updated_at DESC |
| 763 | ` |
| 764 | |
| 765 | func (q *Queries) ListReposForOwnerOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) ([]Repo, error) { |
| 766 | rows, err := db.Query(ctx, listReposForOwnerOrg, ownerOrgID) |
| 767 | if err != nil { |
| 768 | return nil, err |
| 769 | } |
| 770 | defer rows.Close() |
| 771 | items := []Repo{} |
| 772 | for rows.Next() { |
| 773 | var i Repo |
| 774 | if err := rows.Scan( |
| 775 | &i.ID, |
| 776 | &i.OwnerUserID, |
| 777 | &i.OwnerOrgID, |
| 778 | &i.Name, |
| 779 | &i.Description, |
| 780 | &i.Visibility, |
| 781 | &i.DefaultBranch, |
| 782 | &i.IsArchived, |
| 783 | &i.ArchivedAt, |
| 784 | &i.DeletedAt, |
| 785 | &i.DiskUsedBytes, |
| 786 | &i.ForkOfRepoID, |
| 787 | &i.LicenseKey, |
| 788 | &i.PrimaryLanguage, |
| 789 | &i.HasIssues, |
| 790 | &i.HasPulls, |
| 791 | &i.CreatedAt, |
| 792 | &i.UpdatedAt, |
| 793 | &i.DefaultBranchOid, |
| 794 | &i.AllowSquashMerge, |
| 795 | &i.AllowRebaseMerge, |
| 796 | &i.AllowMergeCommit, |
| 797 | &i.DefaultMergeMethod, |
| 798 | &i.StarCount, |
| 799 | &i.WatcherCount, |
| 800 | &i.ForkCount, |
| 801 | &i.InitStatus, |
| 802 | &i.LastIndexedOid, |
| 803 | ); err != nil { |
| 804 | return nil, err |
| 805 | } |
| 806 | items = append(items, i) |
| 807 | } |
| 808 | if err := rows.Err(); err != nil { |
| 809 | return nil, err |
| 810 | } |
| 811 | return items, nil |
| 812 | } |
| 813 | |
| 814 | const listReposForOwnerUser = `-- name: ListReposForOwnerUser :many |
| 815 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 816 | default_branch, is_archived, archived_at, deleted_at, |
| 817 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 818 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 819 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 820 | star_count, watcher_count, fork_count, init_status, |
| 821 | last_indexed_oid |
| 822 | FROM repos |
| 823 | WHERE owner_user_id = $1 AND deleted_at IS NULL |
| 824 | ORDER BY updated_at DESC |
| 825 | ` |
| 826 | |
| 827 | func (q *Queries) ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) ([]Repo, error) { |
| 828 | rows, err := db.Query(ctx, listReposForOwnerUser, ownerUserID) |
| 829 | if err != nil { |
| 830 | return nil, err |
| 831 | } |
| 832 | defer rows.Close() |
| 833 | items := []Repo{} |
| 834 | for rows.Next() { |
| 835 | var i Repo |
| 836 | if err := rows.Scan( |
| 837 | &i.ID, |
| 838 | &i.OwnerUserID, |
| 839 | &i.OwnerOrgID, |
| 840 | &i.Name, |
| 841 | &i.Description, |
| 842 | &i.Visibility, |
| 843 | &i.DefaultBranch, |
| 844 | &i.IsArchived, |
| 845 | &i.ArchivedAt, |
| 846 | &i.DeletedAt, |
| 847 | &i.DiskUsedBytes, |
| 848 | &i.ForkOfRepoID, |
| 849 | &i.LicenseKey, |
| 850 | &i.PrimaryLanguage, |
| 851 | &i.HasIssues, |
| 852 | &i.HasPulls, |
| 853 | &i.CreatedAt, |
| 854 | &i.UpdatedAt, |
| 855 | &i.DefaultBranchOid, |
| 856 | &i.AllowSquashMerge, |
| 857 | &i.AllowRebaseMerge, |
| 858 | &i.AllowMergeCommit, |
| 859 | &i.DefaultMergeMethod, |
| 860 | &i.StarCount, |
| 861 | &i.WatcherCount, |
| 862 | &i.ForkCount, |
| 863 | &i.InitStatus, |
| 864 | &i.LastIndexedOid, |
| 865 | ); err != nil { |
| 866 | return nil, err |
| 867 | } |
| 868 | items = append(items, i) |
| 869 | } |
| 870 | if err := rows.Err(); err != nil { |
| 871 | return nil, err |
| 872 | } |
| 873 | return items, nil |
| 874 | } |
| 875 | |
| 876 | const listReposNeedingReindex = `-- name: ListReposNeedingReindex :many |
| 877 | SELECT id, name, default_branch, default_branch_oid |
| 878 | FROM repos |
| 879 | WHERE deleted_at IS NULL |
| 880 | AND default_branch_oid IS NOT NULL |
| 881 | AND (last_indexed_oid IS NULL OR last_indexed_oid <> default_branch_oid) |
| 882 | ORDER BY id |
| 883 | LIMIT $1 |
| 884 | ` |
| 885 | |
| 886 | type ListReposNeedingReindexRow struct { |
| 887 | ID int64 |
| 888 | Name string |
| 889 | DefaultBranch string |
| 890 | DefaultBranchOid pgtype.Text |
| 891 | } |
| 892 | |
| 893 | // S28 code-search reconciler: returns repos whose default_branch_oid |
| 894 | // has advanced past last_indexed_oid (or last_indexed_oid is NULL |
| 895 | // and a default exists). Limited so a single tick of the cron |
| 896 | // doesn't try to re-index the whole world. |
| 897 | func (q *Queries) ListReposNeedingReindex(ctx context.Context, db DBTX, limit int32) ([]ListReposNeedingReindexRow, error) { |
| 898 | rows, err := db.Query(ctx, listReposNeedingReindex, limit) |
| 899 | if err != nil { |
| 900 | return nil, err |
| 901 | } |
| 902 | defer rows.Close() |
| 903 | items := []ListReposNeedingReindexRow{} |
| 904 | for rows.Next() { |
| 905 | var i ListReposNeedingReindexRow |
| 906 | if err := rows.Scan( |
| 907 | &i.ID, |
| 908 | &i.Name, |
| 909 | &i.DefaultBranch, |
| 910 | &i.DefaultBranchOid, |
| 911 | ); err != nil { |
| 912 | return nil, err |
| 913 | } |
| 914 | items = append(items, i) |
| 915 | } |
| 916 | if err := rows.Err(); err != nil { |
| 917 | return nil, err |
| 918 | } |
| 919 | return items, nil |
| 920 | } |
| 921 | |
| 922 | const replaceRepoTopics = `-- name: ReplaceRepoTopics :exec |
| 923 | DELETE FROM repo_topics WHERE repo_id = $1 |
| 924 | ` |
| 925 | |
| 926 | // Atomic full-replace: callers compose the new topic set in Go, |
| 927 | // then replace the existing rows in one tx (DELETE + INSERT). The |
| 928 | // caller's tx wraps both calls for atomicity. |
| 929 | func (q *Queries) ReplaceRepoTopics(ctx context.Context, db DBTX, repoID int64) error { |
| 930 | _, err := db.Exec(ctx, replaceRepoTopics, repoID) |
| 931 | return err |
| 932 | } |
| 933 | |
| 934 | const setLastIndexedOID = `-- name: SetLastIndexedOID :exec |
| 935 | UPDATE repos SET last_indexed_oid = $2::text WHERE id = $1 |
| 936 | ` |
| 937 | |
| 938 | type SetLastIndexedOIDParams struct { |
| 939 | ID int64 |
| 940 | LastIndexedOid pgtype.Text |
| 941 | } |
| 942 | |
| 943 | // S28 code-search: the worker writes the OID it finished indexing |
| 944 | // so the reconciler can detect drift (default_branch_oid moved but |
| 945 | // last_indexed_oid lagged). |
| 946 | func (q *Queries) SetLastIndexedOID(ctx context.Context, db DBTX, arg SetLastIndexedOIDParams) error { |
| 947 | _, err := db.Exec(ctx, setLastIndexedOID, arg.ID, arg.LastIndexedOid) |
| 948 | return err |
| 949 | } |
| 950 | |
| 951 | const setRepoInitStatus = `-- name: SetRepoInitStatus :exec |
| 952 | UPDATE repos SET init_status = $2 WHERE id = $1 |
| 953 | ` |
| 954 | |
| 955 | type SetRepoInitStatusParams struct { |
| 956 | ID int64 |
| 957 | InitStatus RepoInitStatus |
| 958 | } |
| 959 | |
| 960 | // Promotes a fork from init_pending to initialized (or init_failed). |
| 961 | // The DB row is created up-front so the URL resolves immediately and |
| 962 | // the user sees a "preparing your fork" placeholder while the worker |
| 963 | // runs `git clone --bare --shared`. |
| 964 | func (q *Queries) SetRepoInitStatus(ctx context.Context, db DBTX, arg SetRepoInitStatusParams) error { |
| 965 | _, err := db.Exec(ctx, setRepoInitStatus, arg.ID, arg.InitStatus) |
| 966 | return err |
| 967 | } |
| 968 | |
| 969 | const softDeleteRepo = `-- name: SoftDeleteRepo :exec |
| 970 | UPDATE repos SET deleted_at = now() WHERE id = $1 |
| 971 | ` |
| 972 | |
| 973 | func (q *Queries) SoftDeleteRepo(ctx context.Context, db DBTX, id int64) error { |
| 974 | _, err := db.Exec(ctx, softDeleteRepo, id) |
| 975 | return err |
| 976 | } |
| 977 | |
| 978 | const updateRepoDefaultBranchOID = `-- name: UpdateRepoDefaultBranchOID :exec |
| 979 | UPDATE repos SET default_branch_oid = $2::text WHERE id = $1 |
| 980 | ` |
| 981 | |
| 982 | type UpdateRepoDefaultBranchOIDParams struct { |
| 983 | ID int64 |
| 984 | DefaultBranchOid pgtype.Text |
| 985 | } |
| 986 | |
| 987 | // Set when push:process detects a commit on the repo's default branch. |
| 988 | // Pass NULL to clear (e.g. when the branch is force-deleted in a future |
| 989 | // sprint). The repo home view reads this to decide between empty and |
| 990 | // populated layouts. |
| 991 | func (q *Queries) UpdateRepoDefaultBranchOID(ctx context.Context, db DBTX, arg UpdateRepoDefaultBranchOIDParams) error { |
| 992 | _, err := db.Exec(ctx, updateRepoDefaultBranchOID, arg.ID, arg.DefaultBranchOid) |
| 993 | return err |
| 994 | } |
| 995 | |
| 996 | const updateRepoDiskUsed = `-- name: UpdateRepoDiskUsed :exec |
| 997 | UPDATE repos SET disk_used_bytes = $2 WHERE id = $1 |
| 998 | ` |
| 999 | |
| 1000 | type UpdateRepoDiskUsedParams struct { |
| 1001 | ID int64 |
| 1002 | DiskUsedBytes int64 |
| 1003 | } |
| 1004 | |
| 1005 | func (q *Queries) UpdateRepoDiskUsed(ctx context.Context, db DBTX, arg UpdateRepoDiskUsedParams) error { |
| 1006 | _, err := db.Exec(ctx, updateRepoDiskUsed, arg.ID, arg.DiskUsedBytes) |
| 1007 | return err |
| 1008 | } |
| 1009 | |
| 1010 | const updateRepoGeneralSettings = `-- name: UpdateRepoGeneralSettings :exec |
| 1011 | UPDATE repos |
| 1012 | SET description = $2, |
| 1013 | has_issues = $3, |
| 1014 | has_pulls = $4, |
| 1015 | updated_at = now() |
| 1016 | WHERE id = $1 |
| 1017 | ` |
| 1018 | |
| 1019 | type UpdateRepoGeneralSettingsParams struct { |
| 1020 | ID int64 |
| 1021 | Description string |
| 1022 | HasIssues bool |
| 1023 | HasPulls bool |
| 1024 | } |
| 1025 | |
| 1026 | // S32: General-tab settings persist via this single query so each |
| 1027 | // form post is one round-trip. The merge-method toggles are kept |
| 1028 | // separate from the repo create flow because they're admin-only. |
| 1029 | func (q *Queries) UpdateRepoGeneralSettings(ctx context.Context, db DBTX, arg UpdateRepoGeneralSettingsParams) error { |
| 1030 | _, err := db.Exec(ctx, updateRepoGeneralSettings, |
| 1031 | arg.ID, |
| 1032 | arg.Description, |
| 1033 | arg.HasIssues, |
| 1034 | arg.HasPulls, |
| 1035 | ) |
| 1036 | return err |
| 1037 | } |
| 1038 | |
| 1039 | const updateRepoMergeSettings = `-- name: UpdateRepoMergeSettings :exec |
| 1040 | UPDATE repos |
| 1041 | SET allow_merge_commit = $2, |
| 1042 | allow_squash_merge = $3, |
| 1043 | allow_rebase_merge = $4, |
| 1044 | default_merge_method = $5, |
| 1045 | updated_at = now() |
| 1046 | WHERE id = $1 |
| 1047 | ` |
| 1048 | |
| 1049 | type UpdateRepoMergeSettingsParams struct { |
| 1050 | ID int64 |
| 1051 | AllowMergeCommit bool |
| 1052 | AllowSquashMerge bool |
| 1053 | AllowRebaseMerge bool |
| 1054 | DefaultMergeMethod PrMergeMethod |
| 1055 | } |
| 1056 | |
| 1057 | func (q *Queries) UpdateRepoMergeSettings(ctx context.Context, db DBTX, arg UpdateRepoMergeSettingsParams) error { |
| 1058 | _, err := db.Exec(ctx, updateRepoMergeSettings, |
| 1059 | arg.ID, |
| 1060 | arg.AllowMergeCommit, |
| 1061 | arg.AllowSquashMerge, |
| 1062 | arg.AllowRebaseMerge, |
| 1063 | arg.DefaultMergeMethod, |
| 1064 | ) |
| 1065 | return err |
| 1066 | } |
| 1067 | |
| 1068 | const upsertProfilePinSetForOrg = `-- name: UpsertProfilePinSetForOrg :one |
| 1069 | INSERT INTO profile_pin_sets (owner_org_id) |
| 1070 | VALUES ($1) |
| 1071 | ON CONFLICT (owner_org_id) WHERE owner_org_id IS NOT NULL |
| 1072 | DO UPDATE SET updated_at = now() |
| 1073 | RETURNING id |
| 1074 | ` |
| 1075 | |
| 1076 | func (q *Queries) UpsertProfilePinSetForOrg(ctx context.Context, db DBTX, ownerOrgID pgtype.Int8) (int64, error) { |
| 1077 | row := db.QueryRow(ctx, upsertProfilePinSetForOrg, ownerOrgID) |
| 1078 | var id int64 |
| 1079 | err := row.Scan(&id) |
| 1080 | return id, err |
| 1081 | } |
| 1082 | |
| 1083 | const upsertProfilePinSetForUser = `-- name: UpsertProfilePinSetForUser :one |
| 1084 | INSERT INTO profile_pin_sets (owner_user_id) |
| 1085 | VALUES ($1) |
| 1086 | ON CONFLICT (owner_user_id) WHERE owner_user_id IS NOT NULL |
| 1087 | DO UPDATE SET updated_at = now() |
| 1088 | RETURNING id |
| 1089 | ` |
| 1090 | |
| 1091 | func (q *Queries) UpsertProfilePinSetForUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) (int64, error) { |
| 1092 | row := db.QueryRow(ctx, upsertProfilePinSetForUser, ownerUserID) |
| 1093 | var id int64 |
| 1094 | err := row.Scan(&id) |
| 1095 | return id, err |
| 1096 | } |
| 1097 |