Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(migrations): split redis migrations into up and teardown #12983

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**ACME**: Fixed migration of redis configuration."
type: bugfix
scope: Plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**Response-RateLimiting**: Fixed migration of redis configuration."
type: bugfix
scope: Plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**Rate-Limiting**: Fixed migration of redis configuration."
type: bugfix
scope: Plugin
51 changes: 28 additions & 23 deletions kong/plugins/acme/migrations/003_350_to_360.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
)
)
)
Expand All @@ -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,
},
}
34 changes: 25 additions & 9 deletions kong/plugins/rate-limiting/migrations/006_350_to_360.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
},
}
34 changes: 25 additions & 9 deletions kong/plugins/response-ratelimiting/migrations/001_350_to_360.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading