From 994e1dd58fb523d6a0fa4fa5b38d70c3c858114c Mon Sep 17 00:00:00 2001 From: Will Assis <35489495+gassiss@users.noreply.github.com> Date: Thu, 4 Dec 2025 09:21:17 -0500 Subject: [PATCH] unified-storage: sqlkv migrations (#114790) * unified-storage: create resource_events table and add key_path column to resource_history * Update resource_history_insert template * update test snapshots * use latin encoding for key_path and bump size to 2048 --- .../unified/sql/data/resource_history_insert.sql | 6 ++++-- .../unified/sql/db/migrations/resource_mig.go | 13 +++++++++++++ pkg/storage/unified/sql/queries.go | 1 + ..._history_insert-insert into resource_history.sql | 6 ++++-- ..._history_insert-insert into resource_history.sql | 6 ++++-- ..._history_insert-insert into resource_history.sql | 6 ++++-- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/pkg/storage/unified/sql/data/resource_history_insert.sql b/pkg/storage/unified/sql/data/resource_history_insert.sql index 4ac3cc03547..5a968ef9033 100644 --- a/pkg/storage/unified/sql/data/resource_history_insert.sql +++ b/pkg/storage/unified/sql/data/resource_history_insert.sql @@ -12,7 +12,8 @@ INSERT INTO {{ .Ident "resource_history" }} {{ .Ident "previous_resource_version"}}, {{ .Ident "generation"}}, {{ .Ident "value" }}, - {{ .Ident "action" }} + {{ .Ident "action" }}, + {{ .Ident "key_path" }} ) VALUES ( @@ -28,6 +29,7 @@ INSERT INTO {{ .Ident "resource_history" }} {{ .Arg .WriteEvent.PreviousRV }}, {{ .Arg .Generation }}, {{ .Arg .WriteEvent.Value }}, - {{ .Arg .WriteEvent.Type }} + {{ .Arg .WriteEvent.Type }}, + {{ .Arg .KeyPath }} ) ; diff --git a/pkg/storage/unified/sql/db/migrations/resource_mig.go b/pkg/storage/unified/sql/db/migrations/resource_mig.go index 315ff2b5b40..c8a6d980104 100644 --- a/pkg/storage/unified/sql/db/migrations/resource_mig.go +++ b/pkg/storage/unified/sql/db/migrations/resource_mig.go @@ -185,5 +185,18 @@ func initResourceTables(mg *migrator.Migrator) string { Name: "UQE_resource_last_import_time_last_import_time", })) + mg.AddMigration("Add key_path column to resource_history", migrator.NewAddColumnMigration(resource_history_table, &migrator.Column{ + Name: "key_path", Type: migrator.DB_NVarchar, Length: 2048, Nullable: false, Default: "", IsLatin: true, + })) + + resource_events_table := migrator.Table{ + Name: "resource_events", + Columns: []*migrator.Column{ + {Name: "key_path", Type: migrator.DB_NVarchar, Length: 2048, Nullable: false, IsPrimaryKey: true, IsLatin: true}, + {Name: "value", Type: migrator.DB_MediumText, Nullable: false}, + }, + } + mg.AddMigration("create table "+resource_events_table.Name, migrator.NewAddTableMigration(resource_events_table)) + return marker } diff --git a/pkg/storage/unified/sql/queries.go b/pkg/storage/unified/sql/queries.go index e6b9b1615bf..e51cf943041 100644 --- a/pkg/storage/unified/sql/queries.go +++ b/pkg/storage/unified/sql/queries.go @@ -84,6 +84,7 @@ type sqlResourceRequest struct { WriteEvent resource.WriteEvent Generation int64 Folder string + KeyPath string // Useful when batch writing ResourceVersion int64 diff --git a/pkg/storage/unified/sql/testdata/mysql--resource_history_insert-insert into resource_history.sql b/pkg/storage/unified/sql/testdata/mysql--resource_history_insert-insert into resource_history.sql index 6eae2b07b7a..7b82bce294d 100755 --- a/pkg/storage/unified/sql/testdata/mysql--resource_history_insert-insert into resource_history.sql +++ b/pkg/storage/unified/sql/testdata/mysql--resource_history_insert-insert into resource_history.sql @@ -9,7 +9,8 @@ INSERT INTO `resource_history` `previous_resource_version`, `generation`, `value`, - `action` + `action`, + `key_path` ) VALUES ( '', @@ -21,6 +22,7 @@ INSERT INTO `resource_history` 1234, 789, '[]', - 'UNKNOWN' + 'UNKNOWN', + '' ) ; diff --git a/pkg/storage/unified/sql/testdata/postgres--resource_history_insert-insert into resource_history.sql b/pkg/storage/unified/sql/testdata/postgres--resource_history_insert-insert into resource_history.sql index 11f6b18c01b..6375c88407e 100755 --- a/pkg/storage/unified/sql/testdata/postgres--resource_history_insert-insert into resource_history.sql +++ b/pkg/storage/unified/sql/testdata/postgres--resource_history_insert-insert into resource_history.sql @@ -9,7 +9,8 @@ INSERT INTO "resource_history" "previous_resource_version", "generation", "value", - "action" + "action", + "key_path" ) VALUES ( '', @@ -21,6 +22,7 @@ INSERT INTO "resource_history" 1234, 789, '[]', - 'UNKNOWN' + 'UNKNOWN', + '' ) ; diff --git a/pkg/storage/unified/sql/testdata/sqlite--resource_history_insert-insert into resource_history.sql b/pkg/storage/unified/sql/testdata/sqlite--resource_history_insert-insert into resource_history.sql index 11f6b18c01b..6375c88407e 100755 --- a/pkg/storage/unified/sql/testdata/sqlite--resource_history_insert-insert into resource_history.sql +++ b/pkg/storage/unified/sql/testdata/sqlite--resource_history_insert-insert into resource_history.sql @@ -9,7 +9,8 @@ INSERT INTO "resource_history" "previous_resource_version", "generation", "value", - "action" + "action", + "key_path" ) VALUES ( '', @@ -21,6 +22,7 @@ INSERT INTO "resource_history" 1234, 789, '[]', - 'UNKNOWN' + 'UNKNOWN', + '' ) ;