From 766c36342f9bd13ab2ad8012b8c177ccf1fb0074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Nowak?= Date: Wed, 8 May 2024 11:02:31 +0200 Subject: [PATCH] fix(migration): make redis schema migrations reentrant (#12992) (cherry picked from commit 328097a1225dbbb802c121c028b094fc6763cb5f) --- .../plugins/acme/migrations/003_350_to_360.lua | 8 ++++---- .../migrations/006_350_to_360.lua | 18 +++++++++--------- .../migrations/001_350_to_360.lua | 18 +++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/kong/plugins/acme/migrations/003_350_to_360.lua b/kong/plugins/acme/migrations/003_350_to_360.lua index 47a2d6040b42..86891580cd94 100644 --- a/kong/plugins/acme/migrations/003_350_to_360.lua +++ b/kong/plugins/acme/migrations/003_350_to_360.lua @@ -10,11 +10,11 @@ return { '{storage_config,redis}', config #> '{storage_config, redis}' || jsonb_build_object( - 'password', config #> '{storage_config, redis, auth}', - 'server_name', config #> '{storage_config, redis, ssl_server_name}', + 'password', COALESCE(config #> '{storage_config, redis, auth}', config #> '{storage_config, redis, password}'), + 'server_name', COALESCE(config #> '{storage_config, redis, ssl_server_name}', config #> '{storage_config, redis, server_name}'), 'extra_options', jsonb_build_object( - 'scan_count', config #> '{storage_config, redis, scan_count}', - 'namespace', config #> '{storage_config, redis, namespace}' + 'scan_count', COALESCE(config #> '{storage_config, redis, scan_count}', config #> '{storage_config, redis, extra_options, scan_count}'), + 'namespace', COALESCE(config #> '{storage_config, redis, namespace}', config #> '{storage_config, redis, extra_options, namespace}') ) ) ) diff --git a/kong/plugins/rate-limiting/migrations/006_350_to_360.lua b/kong/plugins/rate-limiting/migrations/006_350_to_360.lua index 04e65cdbac5c..deb7e87fe4b9 100644 --- a/kong/plugins/rate-limiting/migrations/006_350_to_360.lua +++ b/kong/plugins/rate-limiting/migrations/006_350_to_360.lua @@ -9,15 +9,15 @@ return { || jsonb_build_object( 'redis', jsonb_build_object( - 'host', config->'redis_host', - 'port', config->'redis_port', - 'password', config->'redis_password', - 'username', config->'redis_username', - 'ssl', config->'redis_ssl', - 'ssl_verify', config->'redis_ssl_verify', - 'server_name', config->'redis_server_name', - 'timeout', config->'redis_timeout', - 'database', config->'redis_database' + 'host', COALESCE(config->'redis_host', config #> '{redis, host}'), + 'port', COALESCE(config->'redis_port', config #> '{redis, port}'), + 'password', COALESCE(config->'redis_password', config #> '{redis, password}'), + 'username', COALESCE(config->'redis_username', config #> '{redis, username}'), + 'ssl', COALESCE(config->'redis_ssl', config #> '{redis, ssl}'), + 'ssl_verify', COALESCE(config->'redis_ssl_verify', config #> '{redis, ssl_verify}'), + 'server_name', COALESCE(config->'redis_server_name', config #> '{redis, server_name}'), + 'timeout', COALESCE(config->'redis_timeout', config #> '{redis, timeout}'), + 'database', COALESCE(config->'redis_database', config #> '{redis, database}') ) ) WHERE name = 'rate-limiting'; diff --git a/kong/plugins/response-ratelimiting/migrations/001_350_to_360.lua b/kong/plugins/response-ratelimiting/migrations/001_350_to_360.lua index 418751cbe641..2203b3c8954c 100644 --- a/kong/plugins/response-ratelimiting/migrations/001_350_to_360.lua +++ b/kong/plugins/response-ratelimiting/migrations/001_350_to_360.lua @@ -9,15 +9,15 @@ return { || jsonb_build_object( 'redis', jsonb_build_object( - 'host', config->'redis_host', - 'port', config->'redis_port', - 'password', config->'redis_password', - 'username', config->'redis_username', - 'ssl', config->'redis_ssl', - 'ssl_verify', config->'redis_ssl_verify', - 'server_name', config->'redis_server_name', - 'timeout', config->'redis_timeout', - 'database', config->'redis_database' + 'host', COALESCE(config->'redis_host', config #> '{redis, host}'), + 'port', COALESCE(config->'redis_port', config #> '{redis, port}'), + 'password', COALESCE(config->'redis_password', config #> '{redis, password}'), + 'username', COALESCE(config->'redis_username', config #> '{redis, username}'), + 'ssl', COALESCE(config->'redis_ssl', config #> '{redis, ssl}'), + 'ssl_verify', COALESCE(config->'redis_ssl_verify', config #> '{redis, ssl_verify}'), + 'server_name', COALESCE(config->'redis_server_name', config #> '{redis, server_name}'), + 'timeout', COALESCE(config->'redis_timeout', config #> '{redis, timeout}'), + 'database', COALESCE(config->'redis_database', config #> '{redis, database}') ) ) WHERE name = 'response-ratelimiting';