diff --git a/changelog/unreleased/kong/fix-migrations-for-redis-plugins-acme.yml b/changelog/unreleased/kong/fix-migrations-for-redis-plugins-acme.yml new file mode 100644 index 000000000000..51dba5031015 --- /dev/null +++ b/changelog/unreleased/kong/fix-migrations-for-redis-plugins-acme.yml @@ -0,0 +1,3 @@ +message: "**ACME**: Fixed migration of redis configuration." +type: bugfix +scope: Plugin diff --git a/changelog/unreleased/kong/fix-migrations-for-redis-plugins-response-rl.yml b/changelog/unreleased/kong/fix-migrations-for-redis-plugins-response-rl.yml new file mode 100644 index 000000000000..e2a6d2b694c9 --- /dev/null +++ b/changelog/unreleased/kong/fix-migrations-for-redis-plugins-response-rl.yml @@ -0,0 +1,3 @@ +message: "**Response-RateLimiting**: Fixed migration of redis configuration." +type: bugfix +scope: Plugin diff --git a/changelog/unreleased/kong/fix-migrations-for-redis-plugins-rl.yml b/changelog/unreleased/kong/fix-migrations-for-redis-plugins-rl.yml new file mode 100644 index 000000000000..ccfb4fe8ad7e --- /dev/null +++ b/changelog/unreleased/kong/fix-migrations-for-redis-plugins-rl.yml @@ -0,0 +1,3 @@ +message: "**Rate-Limiting**: Fixed migration of redis configuration." +type: bugfix +scope: Plugin diff --git a/kong/plugins/acme/migrations/003_350_to_360.lua b/kong/plugins/acme/migrations/003_350_to_360.lua index 084f772170c5..47a2d6040b42 100644 --- a/kong/plugins/acme/migrations/003_350_to_360.lua +++ b/kong/plugins/acme/migrations/003_350_to_360.lua @@ -5,30 +5,16 @@ return { BEGIN UPDATE plugins SET config = - config - #- '{storage_config,redis}' - - || jsonb_build_object( - 'storage_config', - (config -> 'storage_config') - 'redis' + jsonb_set( + config, + '{storage_config,redis}', + config #> '{storage_config, redis}' || jsonb_build_object( - 'redis', - jsonb_build_object( - 'host', config #> '{storage_config, redis, host}', - 'port', config #> '{storage_config, redis, port}', - 'password', config #> '{storage_config, redis, auth}', - 'username', config #> '{storage_config, redis, username}', - 'ssl', config #> '{storage_config, redis, ssl}', - 'ssl_verify', config #> '{storage_config, redis, ssl_verify}', - 'server_name', config #> '{storage_config, redis, ssl_server_name}', - 'timeout', config #> '{storage_config, redis, timeout}', - 'database', config #> '{storage_config, redis, database}' - ) || jsonb_build_object( - 'extra_options', - jsonb_build_object( - 'scan_count', config #> '{storage_config, redis, scan_count}', - 'namespace', config #> '{storage_config, redis, namespace}' - ) + 'password', config #> '{storage_config, redis, auth}', + 'server_name', config #> '{storage_config, redis, ssl_server_name}', + 'extra_options', jsonb_build_object( + 'scan_count', config #> '{storage_config, redis, scan_count}', + 'namespace', config #> '{storage_config, redis, namespace}' ) ) ) @@ -37,5 +23,24 @@ return { -- Do nothing, accept existing state END$$; ]], + teardown = function(connector, _) + local sql = [[ + DO $$ + BEGIN + UPDATE plugins + SET config = + config + #- '{storage_config,redis,auth}' + #- '{storage_config,redis,ssl_server_name}' + #- '{storage_config,redis,scan_count}' + #- '{storage_config,redis,namespace}' + WHERE name = 'acme'; + EXCEPTION WHEN UNDEFINED_COLUMN OR UNDEFINED_TABLE THEN + -- Do nothing, accept existing state + END$$; + ]] + assert(connector:query(sql)) + return true + end, }, } 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 cc697f7cbeba..04e65cdbac5c 100644 --- a/kong/plugins/rate-limiting/migrations/006_350_to_360.lua +++ b/kong/plugins/rate-limiting/migrations/006_350_to_360.lua @@ -6,15 +6,6 @@ return { UPDATE plugins SET config = config::jsonb - - 'redis_host' - - 'redis_port' - - 'redis_password' - - 'redis_username' - - 'redis_ssl' - - 'redis_ssl_verify' - - 'redis_server_name' - - 'redis_timeout' - - 'redis_database' || jsonb_build_object( 'redis', jsonb_build_object( @@ -34,5 +25,30 @@ return { -- Do nothing, accept existing state END$$; ]], + teardown = function(connector, _) + local sql = [[ + DO $$ + BEGIN + UPDATE plugins + SET config = + config::jsonb + - 'redis_host' + - 'redis_port' + - 'redis_password' + - 'redis_username' + - 'redis_ssl' + - 'redis_ssl_verify' + - 'redis_server_name' + - 'redis_timeout' + - 'redis_database' + WHERE name = 'rate-limiting'; + EXCEPTION WHEN UNDEFINED_COLUMN OR UNDEFINED_TABLE THEN + -- Do nothing, accept existing state + END$$; + ]] + assert(connector:query(sql)) + + return true + end, }, } 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 a67fe338e9e2..418751cbe641 100644 --- a/kong/plugins/response-ratelimiting/migrations/001_350_to_360.lua +++ b/kong/plugins/response-ratelimiting/migrations/001_350_to_360.lua @@ -6,15 +6,6 @@ return { UPDATE plugins SET config = config::jsonb - - 'redis_host' - - 'redis_port' - - 'redis_password' - - 'redis_username' - - 'redis_ssl' - - 'redis_ssl_verify' - - 'redis_server_name' - - 'redis_timeout' - - 'redis_database' || jsonb_build_object( 'redis', jsonb_build_object( @@ -34,5 +25,30 @@ return { -- Do nothing, accept existing state END$$; ]], + teardown = function(connector, _) + local sql = [[ + DO $$ + BEGIN + UPDATE plugins + SET config = + config::jsonb + - 'redis_host' + - 'redis_port' + - 'redis_password' + - 'redis_username' + - 'redis_ssl' + - 'redis_ssl_verify' + - 'redis_server_name' + - 'redis_timeout' + - 'redis_database' + WHERE name = 'response-ratelimiting'; + EXCEPTION WHEN UNDEFINED_COLUMN OR UNDEFINED_TABLE THEN + -- Do nothing, accept existing state + END$$; + ]] + assert(connector:query(sql)) + + return true + end, }, } diff --git a/spec/05-migration/plugins/acme/migrations/003_350_to_360_spec.lua b/spec/05-migration/plugins/acme/migrations/003_350_to_360_spec.lua index b0df35c13cff..c9b3605cdf7a 100644 --- a/spec/05-migration/plugins/acme/migrations/003_350_to_360_spec.lua +++ b/spec/05-migration/plugins/acme/migrations/003_350_to_360_spec.lua @@ -41,7 +41,7 @@ if uh.database_type() == 'postgres' then admin_client:close() end) - uh.new_after_up("has updated acme redis configuration", function () + uh.new_after_finish("has updated acme redis configuration", function () local admin_client = assert(uh.admin_client()) local res = assert(admin_client:send { method = "GET",