-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(db/migration): do migration before validation (#10348)
Co-authored-by: Chrono <chrono_cpp@me.com> Co-authored-by: Aapo Talvensaari <aapo.talvensaari@gmail.com> Co-authored-by: Enrique García Cota <kikito@gmail.com> (cherry picked from commit 2f82ced)
- Loading branch information
1 parent
0f77a1d
commit c33859a
Showing
5 changed files
with
68 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,47 @@ | ||
local migrate_path = require "kong.db.migrations.migrate_path_280_300" | ||
local lyaml_null = require("lyaml").null | ||
local cjson_null = require("cjson").null | ||
|
||
local ngx_null = ngx.null | ||
local pairs = pairs | ||
local ipairs = ipairs | ||
local null = ngx.null | ||
|
||
return function(tbl, version) | ||
if not tbl or not (version == "1.1" or version == "2.1") then | ||
return | ||
end | ||
|
||
local routes = tbl.routes | ||
local EMPTY = {} | ||
|
||
if not routes then | ||
-- no need to migrate | ||
return | ||
local function ensure_table(val) | ||
if val == nil or val == ngx_null or val == lyaml_null or val == cjson_null or type(val) ~= "table" then | ||
return EMPTY | ||
end | ||
return val | ||
end | ||
|
||
local function migrate_routes(routes) | ||
for _, route in pairs(routes) do | ||
local paths = route.paths | ||
if not paths or paths == null then | ||
-- no need to migrate | ||
goto continue | ||
end | ||
local paths = ensure_table(route.paths) | ||
|
||
for idx, path in ipairs(paths) do | ||
paths[idx] = migrate_path(path) | ||
end | ||
end | ||
end | ||
|
||
return function(tbl) | ||
local version = tbl._format_version | ||
if not tbl or not (version == "1.1" or version == "2.1") then | ||
return | ||
end | ||
|
||
-- migrate top-level routes | ||
local routes = ensure_table(tbl.routes) | ||
migrate_routes(routes) | ||
|
||
::continue:: | ||
-- migrate routes nested in top-level services | ||
local services = ensure_table(tbl.services) | ||
for _, service in ipairs(services) do | ||
local nested_routes = ensure_table(service.routes) | ||
|
||
migrate_routes(nested_routes) | ||
end | ||
|
||
tbl._format_version = "3.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c33859a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bazel Build
Docker image available
kong/kong:c33859a83ea402e0b86460f8ea89f3997cc76b28
Artifacts available https://github.com/Kong/kong/actions/runs/4301751840