Secrets: Fix MariaDB syntax error due to unsupported CTE syntax (#111610) (#113690)

* Secrets: fix MariaDB syntax error due to unsupported CTE syntax (#111610)

* parametrize guid/created columns and re-generate test fixtures

---------

Co-authored-by: Matheus Macabu <macabu.matheus@gmail.com>
This commit is contained in:
Mike
2025-11-12 15:15:43 +01:00
committed by GitHub
co-authored by Matheus Macabu
parent 3e2dccb544
commit 6c512dabdc
4 changed files with 49 additions and 53 deletions
@@ -1,20 +1,19 @@
WITH to_update AS (
SELECT guid FROM (
SELECT
guid,
ROW_NUMBER() OVER (ORDER BY created ASC) AS rn
FROM {{ .Ident "secret_secure_value" }}
WHERE
UPDATE
{{ .Ident "secret_secure_value" }}
SET
{{ .Ident "lease_token" }} = {{ .Arg .LeaseToken }},
{{ .Ident "lease_created" }} = {{ .Arg .Now }}
WHERE {{ .Ident "guid" }} IN (
SELECT {{ .Ident "guid" }} FROM (
SELECT
{{ .Ident "guid" }},
ROW_NUMBER() OVER (ORDER BY {{ .Ident "created" }} ASC) AS rn
FROM {{ .Ident "secret_secure_value" }}
WHERE
{{ .Ident "active" }} = FALSE AND
{{ .Arg .Now }} - {{ .Ident "created" }} > {{ .Arg .MinAge }} AND
{{ .Arg .Now }} - {{ .Ident "lease_created" }} > {{ .Arg .LeaseTTL }}
) AS sub
WHERE rn <= {{ .Arg .MaxBatchSize }}
)
UPDATE
{{ .Ident "secret_secure_value" }}
SET
{{ .Ident "lease_token" }} = {{ .Arg .LeaseToken }},
{{ .Ident "lease_created" }} = {{ .Arg .Now }}
WHERE guid IN (SELECT guid FROM to_update)
;
;