Skip to content

Commit

Permalink
default ws_id if not exists in lmdb
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Oct 10, 2024
1 parent ecfdd07 commit d203a4b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions kong/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ local constants = {
PROTOCOLS = protocols,
PROTOCOLS_WITH_SUBSYSTEM = protocols_with_subsystem,

DECLARATIVE_DEFAULT_WORKSPACE_ID = "0dc6f45b-8f8d-40d2-a504-473544ee190b",

DECLARATIVE_LOAD_KEY = "declarative_config:loaded",
DECLARATIVE_HASH_KEY = "declarative_config:hash",
DECLARATIVE_DEFAULT_WORKSPACE_KEY = "declarative_config:default_workspace",
Expand Down
5 changes: 3 additions & 2 deletions kong/db/dao/workspaces.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local constants = require("kong.constants")
local lmdb = require("resty.lmdb")


local DECLARATIVE_DEFAULT_WORKSPACE_ID = constants.DECLARATIVE_DEFAULT_WORKSPACE_ID
local DECLARATIVE_DEFAULT_WORKSPACE_KEY = constants.DECLARATIVE_DEFAULT_WORKSPACE_KEY


Expand All @@ -28,8 +29,8 @@ end
function Workspaces:select_by_name(key, options)
if kong.configuration.database == "off" and key == "default" then
-- it should be a table, not a single string
local id = lmdb.get(DECLARATIVE_DEFAULT_WORKSPACE_KEY)
return id and { id = lmdb.get(DECLARATIVE_DEFAULT_WORKSPACE_KEY), } or nil
local id = lmdb.get(DECLARATIVE_DEFAULT_WORKSPACE_KEY) or DECLARATIVE_DEFAULT_WORKSPACE_ID
return { id = lmdb.get(DECLARATIVE_DEFAULT_WORKSPACE_KEY), }
end

return self.super.select_by_name(self, key, options)
Expand Down
2 changes: 1 addition & 1 deletion kong/db/schema/others/declarative_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ end


local function insert_default_workspace_if_not_given(_, entities)
local default_workspace = find_default_ws(entities) or "0dc6f45b-8f8d-40d2-a504-473544ee190b"
local default_workspace = find_default_ws(entities) or constants.DECLARATIVE_DEFAULT_WORKSPACE_ID

if not entities.workspaces then
entities.workspaces = {}
Expand Down

0 comments on commit d203a4b

Please sign in to comment.