From 5c293d048788fda67f9955e1f178d03161ce9674 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Mon, 28 Oct 2024 10:57:07 +0800 Subject: [PATCH] change id to pk in Lua --- kong/clustering/services/sync/hooks.lua | 2 +- kong/clustering/services/sync/rpc.lua | 2 +- kong/clustering/services/sync/strategies/postgres.lua | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kong/clustering/services/sync/hooks.lua b/kong/clustering/services/sync/hooks.lua index 7a3a1402558d..685dfe8776d3 100644 --- a/kong/clustering/services/sync/hooks.lua +++ b/kong/clustering/services/sync/hooks.lua @@ -79,7 +79,7 @@ function _M:entity_delta_writer(row, name, options, ws_id, is_delete) local deltas = { { type = name, - id = row.id, + pk = row.id, ws_id = ws_id, row = is_delete and ngx_null or row, }, diff --git a/kong/clustering/services/sync/rpc.lua b/kong/clustering/services/sync/rpc.lua index 978a355fb1a2..ddfa74f4279f 100644 --- a/kong/clustering/services/sync/rpc.lua +++ b/kong/clustering/services/sync/rpc.lua @@ -274,7 +274,7 @@ local function do_sync() else -- delete the entity - local old_entity, err = kong.db[delta_type]:select({ id = delta.id, }) -- TODO: composite key + local old_entity, err = kong.db[delta_type]:select({ id = delta.pk, }) -- TODO: composite key if err then return nil, err end diff --git a/kong/clustering/services/sync/strategies/postgres.lua b/kong/clustering/services/sync/strategies/postgres.lua index 589b9f025047..bbe8654eae8a 100644 --- a/kong/clustering/services/sync/strategies/postgres.lua +++ b/kong/clustering/services/sync/strategies/postgres.lua @@ -67,21 +67,21 @@ local NEW_VERSION_QUERY = [[ new_version integer; BEGIN INSERT INTO clustering_sync_version DEFAULT VALUES RETURNING version INTO new_version; - INSERT INTO clustering_sync_delta (version, type, id, ws_id, row) VALUES %s; + INSERT INTO clustering_sync_delta (version, type, pk, ws_id, row) VALUES %s; END $$; ]] -- deltas: { --- { type = "service", "id" = "d78eb00f-8702-4d6a-bfd9-e005f904ae3e", "ws_id" = "73478cf6-964f-412d-b1c4-8ac88d9e85e9", row = "JSON", } --- { type = "route", "id" = "0a5bac5c-b795-4981-95d2-919ba3390b7e", "ws_id" = "73478cf6-964f-412d-b1c4-8ac88d9e85e9", row = "JSON", } +-- { type = "service", "pk" = "d78eb00f-8702-4d6a-bfd9-e005f904ae3e", "ws_id" = "73478cf6-964f-412d-b1c4-8ac88d9e85e9", row = "JSON", } +-- { type = "route", "pk" = "0a5bac5c-b795-4981-95d2-919ba3390b7e", "ws_id" = "73478cf6-964f-412d-b1c4-8ac88d9e85e9", row = "JSON", } -- } function _M:insert_delta(deltas) local buf = buffer.new() for _, d in ipairs(deltas) do buf:putf("(new_version, %s, %s, %s, %s)", self.connector:escape_literal(d.type), - self.connector:escape_literal(d.id), + self.connector:escape_literal(d.pk), self.connector:escape_literal(d.ws_id or kong.default_workspace), self.connector:escape_literal(cjson_encode(d.row))) end