Unistore: Add generation column (#102222)

This commit is contained in:
Ryan McKinley
2025-04-01 20:38:23 +03:00
committed by GitHub
parent cd30742616
commit 9c49c601f1
19 changed files with 194 additions and 87 deletions
@@ -10,6 +10,7 @@ INSERT INTO {{ .Ident "resource_history" }}
{{ .Ident "resource_version" }},
{{ end }}
{{ .Ident "previous_resource_version"}},
{{ .Ident "generation"}},
{{ .Ident "value" }},
{{ .Ident "action" }}
)
@@ -25,6 +26,7 @@ INSERT INTO {{ .Ident "resource_history" }}
{{ .Arg .ResourceVersion }},
{{ end }}
{{ .Arg .WriteEvent.PreviousRV }},
{{ .Arg .Generation }},
{{ .Arg .WriteEvent.Value }},
{{ .Arg .WriteEvent.Type }}
)
@@ -5,19 +5,23 @@ WHERE {{ .Ident "guid" }} IN (
SELECT
{{ .Ident "guid" }},
ROW_NUMBER() OVER (
PARTITION BY
{{ .Ident "namespace" }},
{{ .Ident "group" }},
{{ .Ident "resource" }},
{{ .Ident "name" }}
PARTITION BY {{ .Ident "namespace" }}
, {{ .Ident "group" }}
, {{ .Ident "resource" }}
, {{ .Ident "name" }}
{{ if .PartitionByGeneration }}
, {{ .Ident "generation" }}
{{ end }}
ORDER BY {{ .Ident "resource_version" }} DESC
) AS {{ .Ident "rn" }}
FROM {{ .Ident "resource_history" }}
WHERE
{{ .Ident "namespace" }} = {{ .Arg .Key.Namespace }}
WHERE {{ .Ident "namespace" }} = {{ .Arg .Key.Namespace }}
AND {{ .Ident "group" }} = {{ .Arg .Key.Group }}
AND {{ .Ident "resource" }} = {{ .Arg .Key.Resource }}
AND {{ .Ident "name" }} = {{ .Arg .Key.Name }}
{{ if .PartitionByGeneration }}
AND {{ .Ident "generation" }} > 0
{{ end }}
) AS {{ .Ident "ranked" }}
WHERE {{ .Ident "rn" }} > {{ .Arg .HistoryLimit }}
);