Files
lincodex/backend/internal/adapter/secondary/postgres/sqlc/querier.go
T

318 lines
22 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
type Querier interface {
// Adds recipients to the day and the month row. The caller holds their
// locks from LockMailQuotaRows and has checked both limits.
AddMailQuotaUsage(ctx context.Context, arg AddMailQuotaUsageParams) (int64, error)
// Cancels a job that has not finished. A job whose handler transaction is
// in progress holds its row lock, so the statement waits for it: after the
// handler committed the job is done and nothing is canceled; otherwise the
// worker finds its lease gone and does not run or complete the job.
CancelScheduledJob(ctx context.Context, arg CancelScheduledJobParams) (int64, error)
// Claims up to batch_limit jobs of the listed kinds in one statement: jobs
// whose available_at has passed, and running jobs whose lease expired
// because their worker stopped without finishing them. Rows that another
// worker locks are skipped without waiting. Each claimed job gets the lease
// of lease_owner and one more attempt, except a job whose expired attempt
// never started its handler: that attempt is reused, so a worker that was
// busy with other jobs of its batch costs the job nothing. A job whose
// started attempt was abandoned on its last allowed attempt becomes dead
// with lease_expired instead, so a job that keeps crashing its worker
// stops. now is the application clock.
//
// The kind filter applies after the index on available_at; when many waiting
// jobs belong to kinds without a handler in the claiming process, an index
// on (kind, available_at, id) is the next step.
ClaimScheduledJobs(ctx context.Context, arg ClaimScheduledJobsParams) ([]ClaimScheduledJobsRow, error)
// Completes a job in the transaction of its handler effect. The guard is
// the lease owner and the attempt, so a worker that lost its lease cannot
// complete the job.
CompleteScheduledJob(ctx context.Context, arg CompleteScheduledJobParams) (int64, error)
// Consumes a token in one statement. Concurrent callers queue on the token
// row lock; under READ COMMITTED each waiter re-checks the WHERE clause
// against the committed row, so exactly one of them updates it. The join
// compares the registration version with the account row as the statement
// reads it, without locking that row, so it rejects a token from an earlier
// registration that already committed but not one that commits afterwards.
// The confirmation guarantee therefore needs MarkUserEmailVerified with the
// returned registration version in the same transaction, rolled back when it
// matches no row.
ConsumeEmailToken(ctx context.Context, arg ConsumeEmailTokenParams) (EmailToken, error)
DeleteMailRequest(ctx context.Context, id pgtype.UUID) (int64, error)
// Deletes one batch of accounts that stayed unverified since before cutoff,
// oldest first, with their tokens, sessions, mail requests, mail deliveries
// (and through the deliveries their attempts), and consent records. The
// consent records reference the account with ON DELETE RESTRICT, so they are
// deleted explicitly in the same statement: a registration never confirmed
// by its email owner is not kept as consent evidence. Every lock is taken
// with SKIP LOCKED, so the statement never waits: an account whose row is
// locked, for example by a re-registration, a token insert, a delivery
// insert, or a consent insert, is skipped, and so is an account with any
// token, session, mail request, delivery, or consent row locked, for example
// by a confirmation that consumed a token, the delivery consumer, or a
// worker recording an attempt. Skipped accounts stay for the next run.
// Taking the account lock before the token locks is the reverse of the
// documented order, which is safe only because no lock here waits.
// An account qualifies only when every token, session, mail request,
// delivery, and consent row visible to the statement was locked above.
// The restricting foreign key is checked at the end of the statement, after
// these rows are gone.
DeleteUnverifiedUsersRegisteredBefore(ctx context.Context, arg DeleteUnverifiedUsersRegisteredBeforeParams) (int64, error)
// Lock order. Every transaction that writes mail_quota_usage first creates
// and locks all the usage rows it will touch with EnsureMailQuotaRows and
// LockMailQuotaRows, which both work in (period_kind, period_start) order,
// and only then writes them or a mail_quota_reservations row. Later UPDATE
// statements of the same transaction find their rows locked already, so the
// scan order of an UPDATE never decides the lock order.
// Creates the listed window rows of a provider account with no usage when
// they do not exist yet, in (period_kind, period_start) order. A window key
// is "<period_kind>/<YYYY-MM-DD>". A concurrent insert of the same row waits
// for the first transaction and then inserts nothing. Existing rows are
// neither changed nor locked here.
EnsureMailQuotaRows(ctx context.Context, arg EnsureMailQuotaRowsParams) error
// Records a failed attempt after its handler transaction rolled back: the
// job waits for its retry at retry_at (status failed) or is dead, with a
// NULL retry_at. due_at keeps the deadline. The same guard as the
// completion applies.
FailScheduledJob(ctx context.Context, arg FailScheduledJobParams) (int64, error)
// Returns the newest open reservation of a delivery under a provider account
// made at or after reserved_since. A retry of the delivery inside the
// provider's idempotency window reuses it instead of counting again.
FindOpenMailQuotaReservation(ctx context.Context, arg FindOpenMailQuotaReservationParams) (FindOpenMailQuotaReservationRow, error)
GetActiveSessionByTokenHash(ctx context.Context, arg GetActiveSessionByTokenHashParams) (Session, error)
GetConsentText(ctx context.Context, arg GetConsentTextParams) (ConsentText, error)
GetContactConsentRecordByInvitation(ctx context.Context, arg GetContactConsentRecordByInvitationParams) (GetContactConsentRecordByInvitationRow, error)
// The newest unrevoked record of a purpose other than C4.
GetCurrentConsentRecord(ctx context.Context, arg GetCurrentConsentRecordParams) (GetCurrentConsentRecordRow, error)
// The text of a purpose that applies at a time: the latest publication not
// after it.
GetCurrentConsentText(ctx context.Context, arg GetCurrentConsentTextParams) (ConsentText, error)
GetDeliveryByID(ctx context.Context, id pgtype.UUID) (Delivery, error)
// Among the versions of a family already effective at a time, the newest
// publication wins. A version scheduled for later therefore never undoes a
// version published after it. The unique (policy_key, version) index serves
// the backward scan.
GetEffectivePolicyVersion(ctx context.Context, arg GetEffectivePolicyVersionParams) (PolicyVersion, error)
// Explains why ConsumeEmailToken matched no row.
GetEmailTokenState(ctx context.Context, arg GetEmailTokenStateParams) (GetEmailTokenStateRow, error)
// Reads the status of the newest delivery of a kind addressed to an account,
// for the account's own view of its mail. It selects no address and no
// content. The recipient index narrows the scan to the account's rows.
GetLatestDeliveryStatus(ctx context.Context, arg GetLatestDeliveryStatusParams) (GetLatestDeliveryStatusRow, error)
GetLatestPolicyVersion(ctx context.Context, policyKey string) (PolicyVersion, error)
// Reads the usage of the day and the month window without locking.
GetMailQuotaUsage(ctx context.Context, arg GetMailQuotaUsageParams) ([]GetMailQuotaUsageRow, error)
// Reads the relay backlog for metrics without locking. Both subqueries use
// the partial index on unpublished positions, so the cost follows the backlog
// size, not the table size. The age comes from the database clock, the same
// clock that set occurred_at.
GetOutboxBacklog(ctx context.Context) (GetOutboxBacklogRow, error)
GetPolicyVersionByID(ctx context.Context, id pgtype.UUID) (PolicyVersion, error)
// Reads the backlog for metrics without locking: jobs that a worker may
// claim at now, how long the earliest of them has waited, and the dead
// jobs. The
// partial indexes keep the cost proportional to those rows. now is the
// application clock.
GetScheduledJobBacklog(ctx context.Context, now pgtype.Timestamptz) (GetScheduledJobBacklogRow, error)
// Reads the status of a job whose completion found it changed, inside
// the handler transaction that holds its row lock: only that transaction
// can have changed it, for example by canceling its own job.
GetScheduledJobStatus(ctx context.Context, id int64) (string, error)
GetUnrevokedConsentRecordByVersion(ctx context.Context, arg GetUnrevokedConsentRecordByVersionParams) (GetUnrevokedConsentRecordByVersionRow, error)
GetUserByEmailNormalized(ctx context.Context, emailNormalized string) (User, error)
GetUserByID(ctx context.Context, id pgtype.UUID) (User, error)
// Records a grant of C1, C2, C3, or C5. An unrevoked record of the same
// subject, purpose, and text version already exists when no row returns;
// the insert then changes nothing and does not abort the transaction.
InsertConsentRecord(ctx context.Context, arg InsertConsentRecordParams) (InsertConsentRecordRow, error)
// Stores a record that a consumer could not apply. A second delivery of the
// same record (same position and value) refreshes the outcome of its row:
// after a rewind the handler may fail differently. A different value at a
// reused position, after the topic was recreated, gets its own row.
InsertConsumerDeadLetter(ctx context.Context, arg InsertConsumerDeadLetterParams) error
// Records a C4 grant with its scope. The invitation already has a C4 record
// when no row returns; the insert then changes nothing and does not abort
// the transaction.
InsertContactConsentRecord(ctx context.Context, arg InsertContactConsentRecordParams) (InsertContactConsentRecordRow, error)
// Stores a new delivery. A delivery with the same ID already exists when the
// same request is handled again; the statement then inserts nothing and
// returns 0 rows, and the stored content stays as it was. While another
// transaction holds an uncommitted row with the same ID, the insert waits
// for it.
InsertDelivery(ctx context.Context, arg InsertDeliveryParams) (int64, error)
InsertEmailToken(ctx context.Context, arg InsertEmailTokenParams) error
InsertMailQuotaReservation(ctx context.Context, arg InsertMailQuotaReservationParams) error
InsertMailRequest(ctx context.Context, arg InsertMailRequestParams) error
InsertOutboxEvent(ctx context.Context, arg InsertOutboxEventParams) error
// Stores a version and returns the stored row with the publication time and
// effective time set by the stamp trigger. A taken ID or version number
// returns no row instead of an error, so a conflict does not abort the
// surrounding transaction. created_at is never taken from the caller, and a
// NULL effective_at means "at publication".
InsertPolicyVersion(ctx context.Context, arg InsertPolicyVersionParams) (PolicyVersion, error)
// Records that a consumer applies an event, in the transaction of the effect.
// It returns 0 rows when the marker exists. While another transaction holds
// an uncommitted marker for the same key, the insert waits for it: after a
// commit it returns 0, after a rollback it inserts. So a concurrent duplicate
// never runs the effect at the same time as the first delivery.
InsertProcessedEventMarker(ctx context.Context, arg InsertProcessedEventMarkerParams) (int64, error)
// Lock order. A job handler runs while its transaction holds the row lock
// of the job, and may then lock product rows. A business transaction that
// cancels a job should cancel it before it locks the product rows the
// handler touches, so both take the locks in the same order.
// Schedules a job in the caller's transaction. The first schedule of a
// (kind, dedup_key) wins: a repeat, also after the job finished or was
// canceled, inserts nothing and reports 0 rows, so a repeated command never
// moves a deadline. A concurrent insert of the same key waits for the first
// transaction and then inserts nothing, or inserts after its rollback.
InsertScheduledJob(ctx context.Context, arg InsertScheduledJobParams) (int64, error)
InsertSession(ctx context.Context, arg InsertSessionParams) error
InsertUser(ctx context.Context, arg InsertUserParams) error
InvalidateActiveEmailTokens(ctx context.Context, arg InvalidateActiveEmailTokensParams) (int64, error)
// One page of the subject's ledger, newest grant first, optionally limited
// to one state. Every record query is scoped by the subject, so a caller
// never reads or revokes another subject's consent. The state is computed,
// never stored: revoked once revoked_at is set; superseded when a newer
// unrevoked record of the same subject and purpose exists (never for C4,
// whose records are scoped by invitation); active otherwise. The page continues after the (granted_at, id) position of
// the last record of the previous page.
ListConsentRecords(ctx context.Context, arg ListConsentRecordsParams) ([]ListConsentRecordsRow, error)
ListCurrentContactConsentRecords(ctx context.Context, arg ListCurrentContactConsentRecordsParams) ([]ListCurrentContactConsentRecordsRow, error)
ListDeliveryAttempts(ctx context.Context, deliveryID pgtype.UUID) ([]DeliveryAttempt, error)
// Lists the other accounts of a provider that have usage in a month, so
// startup can warn about a renamed EMAIL_ACCOUNT.
ListOtherMailQuotaAccounts(ctx context.Context, arg ListOtherMailQuotaAccountsParams) ([]string, error)
// Locks a claimed job for its handler transaction and checks that the lease
// still belongs to this attempt. It returns no row when the job was
// canceled, or reclaimed after the lease expired. While the lock is held,
// other workers skip the row, so the handler never runs twice at once.
LockClaimedScheduledJob(ctx context.Context, arg LockClaimedScheduledJobParams) (int64, error)
// Locks the listed window rows until the transaction ends, in
// (period_kind, period_start) order, the same order for every caller, and
// returns their usage. Under READ COMMITTED a waiting caller reads the usage
// the first caller committed. period_starts narrows the index scan;
// window_keys selects the exact rows.
LockMailQuotaRows(ctx context.Context, arg LockMailQuotaRowsParams) ([]LockMailQuotaRowsRow, error)
// Locks a request for the consumer transaction that turns it into a
// delivery. A concurrent consumer of the same request waits here and then
// finds the row deleted. The account cleanup and the cascade from users take
// the same row lock, so a request is never converted for an account whose
// deletion is in progress without one of the two transactions waiting.
LockMailRequest(ctx context.Context, id pgtype.UUID) (MailRequest, error)
// Locks the next relay batch. For each aggregate only its earliest unpublished
// event (lowest aggregate_version, then position) qualifies, so a relay never
// holds a later version while an earlier one is still pending, whether that
// earlier row is locked by another relay or was just rolled back. Rows locked
// by another relay are skipped without waiting. The statement snapshot can
// only see a later version after the earlier version's transaction committed,
// because aggregate writers check the expected version, so scanning without a
// position watermark cannot overtake an earlier version.
LockPendingOutboxEvents(ctx context.Context, batchLimit int32) ([]LockPendingOutboxEventsRow, error)
// Records that the provider refused a send because the quota of a window is
// used up: the usage rises to at least the configured limit, so the local
// gate stops admitting sends until the window resets or an operator raises
// the limit. The caller holds the row lock.
MarkMailQuotaExhausted(ctx context.Context, arg MarkMailQuotaExhaustedParams) (int64, error)
// Marks the events that the broker acknowledged. The relay passes only IDs
// whose rows its own transaction locked, so the statement never waits and the
// count equals the number of distinct IDs.
MarkOutboxEventsPublished(ctx context.Context, eventIds []pgtype.UUID) (int64, error)
// Verifies the email only for the registration version the consumed token
// was issued for.
MarkUserEmailVerified(ctx context.Context, arg MarkUserEmailVerifiedParams) (User, error)
Ping(ctx context.Context) (int32, error)
// Reports whether a family has any version without reading a document, so a
// caller that only needs presence never depends on decoding.
PolicyVersionExists(ctx context.Context, policyKey string) (bool, error)
// Advances a delivery past one attempt and appends the attempt in one
// statement, so both happen or neither does, inside or outside a
// transaction. The update applies only while the stored version still
// equals expected_version; otherwise nothing is written and the statement
// returns 0 rows. Two workers that record the same attempt number therefore
// cannot both succeed. Content columns are not touched; a trigger refuses
// any change to them.
RecordDeliveryAttempt(ctx context.Context, arg RecordDeliveryAttemptParams) (int64, error)
// Records the latest settled outcome of a send under the reservation.
RecordMailQuotaOutcome(ctx context.Context, arg RecordMailQuotaOutcomeParams) (int64, error)
// Marks a reservation released. It matches only an open reservation, so a
// repeated release changes nothing and returns 0 rows.
ReleaseMailQuotaReservation(ctx context.Context, arg ReleaseMailQuotaReservationParams) (int64, error)
// Gives back recipients of a released reservation. The caller holds the row
// locks. A window that the provider reported exhausted keeps its usage: the
// provider's answer outranks the local count until the window resets. The
// count never drops below zero.
ReleaseMailQuotaUsage(ctx context.Context, arg ReleaseMailQuotaUsageParams) (int64, error)
// Returns claimed jobs that did not finish, at shutdown or after a database
// failure outside the handler, so another worker can run them at once
// instead of after the lease expires. The attempt is not counted, because
// the job did not cause the failure. The same guard as the completion
// applies, one (id, attempt) pair per job. It returns the IDs it released.
ReleaseScheduledJobs(ctx context.Context, arg ReleaseScheduledJobsParams) ([]int64, error)
// Revokes every unrevoked record of a purpose other than C4, superseded ones
// included, and returns them. A revocation time before the grant time, from
// clock skew between instances, is stamped at the grant time instead.
RevokeConsentRecords(ctx context.Context, arg RevokeConsentRecordsParams) ([]RevokeConsentRecordsRow, error)
// Revokes every unrevoked C4 record of the subject for one organization and
// returns them, with the same clamp of the revocation time as above.
RevokeContactConsentRecords(ctx context.Context, arg RevokeContactConsentRecordsParams) ([]RevokeContactConsentRecordsRow, error)
RevokeSession(ctx context.Context, arg RevokeSessionParams) (int64, error)
RevokeUserSessions(ctx context.Context, arg RevokeUserSessionsParams) (int64, error)
// Bounds a consumer transaction on the server, local to the transaction.
// statement_timeout stops a slow statement; idle_in_transaction_session_timeout
// ends the session of a process that froze or lost the network inside the
// handler, which releases the processed-event marker that a concurrent
// duplicate waits for.
SetConsumerTransactionTimeouts(ctx context.Context, arg SetConsumerTransactionTimeoutsParams) error
// Bounds the claim transaction on the server. statement_timeout stops a
// statement that runs too long; idle_in_transaction_session_timeout ends the
// session, and with it the transaction and its row locks, when the client
// stays silent longer than a publish may take, for example after the process
// froze or lost the network without closing the connection. Both settings
// are local to the transaction.
SetRelayTransactionTimeouts(ctx context.Context, arg SetRelayTransactionTimeoutsParams) error
// Bounds a handler transaction on the server, local to the transaction.
// statement_timeout stops a slow statement; idle_in_transaction_session_timeout
// ends the session of a worker that froze or lost the network inside the
// handler, which releases the job row lock so the job can be reclaimed once
// its lease expires.
SetScheduledJobTransactionTimeouts(ctx context.Context, arg SetScheduledJobTransactionTimeoutsParams) error
// Starts a claimed attempt right before its handler transaction: it renews
// the lease from now and records the start, committed on its own. It
// changes nothing when the lease already expired by now or no longer
// belongs to this attempt, so a job whose turn in the batch came too late is
// never started on a lease that another worker may take over. now is the
// application clock.
StartScheduledJob(ctx context.Context, arg StartScheduledJobParams) (int64, error)
// Records activity on an active session and reports whether it is active.
// The row is written only when last_seen_at is older than touch_cutoff, so
// frequent requests do not rewrite it. last_seen_at never moves back, and a
// revoked, expired, or idle session is not revived; the update re-checks
// those conditions against a concurrent change.
TouchSession(ctx context.Context, arg TouchSessionParams) (TouchSessionRow, error)
// Stores a change of the delivery state that is not an attempt: a quota wait
// or a new provider account before the first attempt. It applies only while
// the stored version still equals expected_version and returns 0 rows
// otherwise. The trigger refuses a provider change after an attempt.
UpdateDeliveryState(ctx context.Context, arg UpdateDeliveryStateParams) (int64, error)
// Replaces the registration of an unverified account and advances the
// registration version in the same statement, so no caller can choose it.
// The version check rejects a writer that read an older row; a verified
// account never changes. The same statement deletes the C1 that the earlier
// registration of this account recorded, so the consent of an earlier
// registrant never stands for the new one; the new registration records its
// own C1 in the same transaction. A version conflict deletes nothing.
UpdateUserRegistration(ctx context.Context, arg UpdateUserRegistrationParams) (UpdateUserRegistrationRow, error)
}
var _ Querier = (*Queries)(nil)