Merged in jmathison/v2-upload-batch (pull request #224)
Implement v2 upload batch cleanup * Implement v2 upload batch cleanup * Merge remote-tracking branch 'origin/main' into jmathison/v2-upload-batch * Address upload batch review feedback * Raise batch worker coverage * Fix batch cleanup review issues Approved-by: Jay Brown
This commit is contained in:
@@ -12,6 +12,60 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const activateLocalDevEulaVersion = `-- name: ActivateLocalDevEulaVersion :one
|
||||
WITH cleared AS (
|
||||
UPDATE eulaVersions
|
||||
SET isCurrent = FALSE
|
||||
WHERE isCurrent = TRUE
|
||||
),
|
||||
upserted AS (
|
||||
INSERT INTO eulaVersions (version, title, content, effectiveDate, createdBy, isCurrent, activatedAt, activatedBy)
|
||||
VALUES ($1, $2, $3, NOW(), 'local-dev', TRUE, NOW(), 'local-dev')
|
||||
ON CONFLICT (version) DO UPDATE
|
||||
SET title = EXCLUDED.title,
|
||||
content = EXCLUDED.content,
|
||||
effectiveDate = EXCLUDED.effectiveDate,
|
||||
isCurrent = TRUE,
|
||||
activatedAt = NOW(),
|
||||
activatedBy = EXCLUDED.activatedBy
|
||||
RETURNING id
|
||||
)
|
||||
SELECT id FROM upserted
|
||||
`
|
||||
|
||||
type ActivateLocalDevEulaVersionParams struct {
|
||||
Version string `db:"version"`
|
||||
Title string `db:"title"`
|
||||
Content string `db:"content"`
|
||||
}
|
||||
|
||||
// Activates or updates the local development EULA version and makes it current.
|
||||
//
|
||||
// WITH cleared AS (
|
||||
// UPDATE eulaVersions
|
||||
// SET isCurrent = FALSE
|
||||
// WHERE isCurrent = TRUE
|
||||
// ),
|
||||
// upserted AS (
|
||||
// INSERT INTO eulaVersions (version, title, content, effectiveDate, createdBy, isCurrent, activatedAt, activatedBy)
|
||||
// VALUES ($1, $2, $3, NOW(), 'local-dev', TRUE, NOW(), 'local-dev')
|
||||
// ON CONFLICT (version) DO UPDATE
|
||||
// SET title = EXCLUDED.title,
|
||||
// content = EXCLUDED.content,
|
||||
// effectiveDate = EXCLUDED.effectiveDate,
|
||||
// isCurrent = TRUE,
|
||||
// activatedAt = NOW(),
|
||||
// activatedBy = EXCLUDED.activatedBy
|
||||
// RETURNING id
|
||||
// )
|
||||
// SELECT id FROM upserted
|
||||
func (q *Queries) ActivateLocalDevEulaVersion(ctx context.Context, arg *ActivateLocalDevEulaVersionParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, activateLocalDevEulaVersion, arg.Version, arg.Title, arg.Content)
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const clearCurrentEulaVersions = `-- name: ClearCurrentEulaVersions :exec
|
||||
UPDATE eulaVersions
|
||||
SET isCurrent = FALSE
|
||||
@@ -167,6 +221,28 @@ func (q *Queries) CreateEulaVersion(ctx context.Context, arg *CreateEulaVersionP
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const createLocalDevEulaAgreement = `-- name: CreateLocalDevEulaAgreement :exec
|
||||
INSERT INTO eulaAgreements (cognitoSubjectId, userEmail, eulaVersionId, agreedFromIp)
|
||||
VALUES ($1, $2, $3, '127.0.0.1')
|
||||
ON CONFLICT (cognitoSubjectId, eulaVersionId) DO NOTHING
|
||||
`
|
||||
|
||||
type CreateLocalDevEulaAgreementParams struct {
|
||||
CognitoSubjectID string `db:"cognito_subject_id"`
|
||||
UserEmail string `db:"user_email"`
|
||||
EulaVersionID uuid.UUID `db:"eula_version_id"`
|
||||
}
|
||||
|
||||
// Records an idempotent local development EULA agreement.
|
||||
//
|
||||
// INSERT INTO eulaAgreements (cognitoSubjectId, userEmail, eulaVersionId, agreedFromIp)
|
||||
// VALUES ($1, $2, $3, '127.0.0.1')
|
||||
// ON CONFLICT (cognitoSubjectId, eulaVersionId) DO NOTHING
|
||||
func (q *Queries) CreateLocalDevEulaAgreement(ctx context.Context, arg *CreateLocalDevEulaAgreementParams) error {
|
||||
_, err := q.db.Exec(ctx, createLocalDevEulaAgreement, arg.CognitoSubjectID, arg.UserEmail, arg.EulaVersionID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getCurrentEulaVersion = `-- name: GetCurrentEulaVersion :one
|
||||
SELECT id, version, title, content, effectiveDate, createdAt, createdBy, isCurrent, activatedAt, activatedBy
|
||||
FROM eulaVersions
|
||||
|
||||
Reference in New Issue
Block a user