| 1 | // Code generated by sqlc. DO NOT EDIT. |
| 2 | // versions: |
| 3 | // sqlc v1.31.1 |
| 4 | // source: commit_verification_cache.sql |
| 5 | |
| 6 | package reposdb |
| 7 | |
| 8 | import ( |
| 9 | "context" |
| 10 | |
| 11 | "github.com/jackc/pgx/v5/pgtype" |
| 12 | ) |
| 13 | |
| 14 | const deleteCommitVerification = `-- name: DeleteCommitVerification :exec |
| 15 | DELETE FROM commit_verification_cache |
| 16 | WHERE repo_id = $1 AND commit_oid = $2 |
| 17 | ` |
| 18 | |
| 19 | type DeleteCommitVerificationParams struct { |
| 20 | RepoID int64 |
| 21 | CommitOid string |
| 22 | } |
| 23 | |
| 24 | // Used by tests to reset cache state between cases. Not called from |
| 25 | // production code paths. |
| 26 | func (q *Queries) DeleteCommitVerification(ctx context.Context, db DBTX, arg DeleteCommitVerificationParams) error { |
| 27 | _, err := db.Exec(ctx, deleteCommitVerification, arg.RepoID, arg.CommitOid) |
| 28 | return err |
| 29 | } |
| 30 | |
| 31 | const getCommitVerification = `-- name: GetCommitVerification :one |
| 32 | SELECT repo_id, commit_oid, reason, verified, |
| 33 | signer_user_id, signer_subkey_id, kind, |
| 34 | signature_armored, payload, verified_at, invalidated_at |
| 35 | FROM commit_verification_cache |
| 36 | WHERE repo_id = $1 AND commit_oid = $2 |
| 37 | ` |
| 38 | |
| 39 | type GetCommitVerificationParams struct { |
| 40 | RepoID int64 |
| 41 | CommitOid string |
| 42 | } |
| 43 | |
| 44 | // Single-commit read. Used by the single-commit page renderer and the |
| 45 | // REST commits/{sha} response. Returns no row when the commit hasn't |
| 46 | // been verified yet; caller treats that as "compute on demand". |
| 47 | func (q *Queries) GetCommitVerification(ctx context.Context, db DBTX, arg GetCommitVerificationParams) (CommitVerificationCache, error) { |
| 48 | row := db.QueryRow(ctx, getCommitVerification, arg.RepoID, arg.CommitOid) |
| 49 | var i CommitVerificationCache |
| 50 | err := row.Scan( |
| 51 | &i.RepoID, |
| 52 | &i.CommitOid, |
| 53 | &i.Reason, |
| 54 | &i.Verified, |
| 55 | &i.SignerUserID, |
| 56 | &i.SignerSubkeyID, |
| 57 | &i.Kind, |
| 58 | &i.SignatureArmored, |
| 59 | &i.Payload, |
| 60 | &i.VerifiedAt, |
| 61 | &i.InvalidatedAt, |
| 62 | ) |
| 63 | return i, err |
| 64 | } |
| 65 | |
| 66 | const getCommitVerificationsForOIDs = `-- name: GetCommitVerificationsForOIDs :many |
| 67 | SELECT repo_id, commit_oid, reason, verified, |
| 68 | signer_user_id, signer_subkey_id, kind, |
| 69 | signature_armored, payload, verified_at, invalidated_at |
| 70 | FROM commit_verification_cache |
| 71 | WHERE repo_id = $1 AND commit_oid = ANY($2::text[]) |
| 72 | ` |
| 73 | |
| 74 | type GetCommitVerificationsForOIDsParams struct { |
| 75 | RepoID int64 |
| 76 | Oids []string |
| 77 | } |
| 78 | |
| 79 | // Batch read for the commit-list page. Takes an array of OIDs and |
| 80 | // returns existing rows; missing OIDs are absent from the result and |
| 81 | // the renderer treats them as "not yet verified". |
| 82 | func (q *Queries) GetCommitVerificationsForOIDs(ctx context.Context, db DBTX, arg GetCommitVerificationsForOIDsParams) ([]CommitVerificationCache, error) { |
| 83 | rows, err := db.Query(ctx, getCommitVerificationsForOIDs, arg.RepoID, arg.Oids) |
| 84 | if err != nil { |
| 85 | return nil, err |
| 86 | } |
| 87 | defer rows.Close() |
| 88 | items := []CommitVerificationCache{} |
| 89 | for rows.Next() { |
| 90 | var i CommitVerificationCache |
| 91 | if err := rows.Scan( |
| 92 | &i.RepoID, |
| 93 | &i.CommitOid, |
| 94 | &i.Reason, |
| 95 | &i.Verified, |
| 96 | &i.SignerUserID, |
| 97 | &i.SignerSubkeyID, |
| 98 | &i.Kind, |
| 99 | &i.SignatureArmored, |
| 100 | &i.Payload, |
| 101 | &i.VerifiedAt, |
| 102 | &i.InvalidatedAt, |
| 103 | ); err != nil { |
| 104 | return nil, err |
| 105 | } |
| 106 | items = append(items, i) |
| 107 | } |
| 108 | if err := rows.Err(); err != nil { |
| 109 | return nil, err |
| 110 | } |
| 111 | return items, nil |
| 112 | } |
| 113 | |
| 114 | const invalidateVerificationsForSubkey = `-- name: InvalidateVerificationsForSubkey :exec |
| 115 | UPDATE commit_verification_cache |
| 116 | SET invalidated_at = now() |
| 117 | WHERE signer_subkey_id = $1 AND invalidated_at IS NULL |
| 118 | ` |
| 119 | |
| 120 | // Stamps invalidated_at on every cache row whose signer_subkey_id |
| 121 | // matches. Called from the GPG-key soft-delete path in the same tx as |
| 122 | // SoftDeleteSubkeysForGPGKey so the cache and the keyring stay in |
| 123 | // sync. The next read of an invalidated row triggers a re-verify. |
| 124 | func (q *Queries) InvalidateVerificationsForSubkey(ctx context.Context, db DBTX, signerSubkeyID pgtype.Int8) error { |
| 125 | _, err := db.Exec(ctx, invalidateVerificationsForSubkey, signerSubkeyID) |
| 126 | return err |
| 127 | } |
| 128 | |
| 129 | const upsertCommitVerification = `-- name: UpsertCommitVerification :exec |
| 130 | |
| 131 | INSERT INTO commit_verification_cache ( |
| 132 | repo_id, commit_oid, reason, verified, |
| 133 | signer_user_id, signer_subkey_id, kind, |
| 134 | signature_armored, payload, verified_at |
| 135 | ) |
| 136 | VALUES ( |
| 137 | $1, $2, $3, $4, |
| 138 | $5, $6, $7, |
| 139 | $8, $9, now() |
| 140 | ) |
| 141 | ON CONFLICT (repo_id, commit_oid) DO UPDATE SET |
| 142 | reason = EXCLUDED.reason, |
| 143 | verified = EXCLUDED.verified, |
| 144 | signer_user_id = EXCLUDED.signer_user_id, |
| 145 | signer_subkey_id = EXCLUDED.signer_subkey_id, |
| 146 | kind = EXCLUDED.kind, |
| 147 | signature_armored = EXCLUDED.signature_armored, |
| 148 | payload = EXCLUDED.payload, |
| 149 | verified_at = now(), |
| 150 | invalidated_at = NULL |
| 151 | ` |
| 152 | |
| 153 | type UpsertCommitVerificationParams struct { |
| 154 | RepoID int64 |
| 155 | CommitOid string |
| 156 | Reason string |
| 157 | Verified bool |
| 158 | SignerUserID pgtype.Int8 |
| 159 | SignerSubkeyID pgtype.Int8 |
| 160 | Kind string |
| 161 | SignatureArmored pgtype.Text |
| 162 | Payload []byte |
| 163 | } |
| 164 | |
| 165 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 166 | // Idempotent upsert. The verification orchestrator + backfill worker |
| 167 | // both write through this query; both can safely run concurrently |
| 168 | // against the same (repo_id, commit_oid) without losing data thanks |
| 169 | // to the (repo_id, commit_oid) primary key + ON CONFLICT clause. |
| 170 | func (q *Queries) UpsertCommitVerification(ctx context.Context, db DBTX, arg UpsertCommitVerificationParams) error { |
| 171 | _, err := db.Exec(ctx, upsertCommitVerification, |
| 172 | arg.RepoID, |
| 173 | arg.CommitOid, |
| 174 | arg.Reason, |
| 175 | arg.Verified, |
| 176 | arg.SignerUserID, |
| 177 | arg.SignerSubkeyID, |
| 178 | arg.Kind, |
| 179 | arg.SignatureArmored, |
| 180 | arg.Payload, |
| 181 | ) |
| 182 | return err |
| 183 | } |
| 184 |