feat: add schema for key rotation (#14662)

This commit is contained in:
Jon Ayers
2024-09-17 18:08:18 +01:00
committed by GitHub
parent 45420b95f3
commit 45160c7679
29 changed files with 977 additions and 2 deletions
+43
View File
@@ -0,0 +1,43 @@
-- name: GetCryptoKeys :many
SELECT *
FROM crypto_keys
WHERE secret IS NOT NULL;
-- name: GetLatestCryptoKeyByFeature :one
SELECT *
FROM crypto_keys
WHERE feature = $1
ORDER BY sequence DESC
LIMIT 1;
-- name: GetCryptoKeyByFeatureAndSequence :one
SELECT *
FROM crypto_keys
WHERE feature = $1
AND sequence = $2
AND secret IS NOT NULL;
-- name: DeleteCryptoKey :one
UPDATE crypto_keys
SET secret = NULL, secret_key_id = NULL
WHERE feature = $1 AND sequence = $2 RETURNING *;
-- name: InsertCryptoKey :one
INSERT INTO crypto_keys (
feature,
sequence,
secret,
starts_at,
secret_key_id
) VALUES (
$1,
$2,
$3,
$4,
$5
) RETURNING *;
-- name: UpdateCryptoKeyDeletesAt :one
UPDATE crypto_keys
SET deletes_at = $3
WHERE feature = $1 AND sequence = $2 RETURNING *;