Skip to content

Commit

Permalink
chore(db) drop support for deprecated dbs
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito committed May 28, 2018
1 parent 6263443 commit 6c4f3f2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- redis-server

addons:
postgresql: "9.4"
postgresql: "9.5"
apt:
packages:
- net-tools
Expand Down
4 changes: 2 additions & 2 deletions kong/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ return {
DATABASE = {
POSTGRES = {
MIN = "9.5",
DEPRECATED = "9.4",
-- also accepts a DEPRECATED key, i.e. DEPRECATED = "9.4"
},
CASSANDRA = {
MIN = "2.2",
DEPRECATED = "2.1",
-- also accepts a DEPRECATED key
}
}
}
30 changes: 0 additions & 30 deletions kong/db/strategies/postgres/connector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ local pgmoon = require "pgmoon"


local setmetatable = setmetatable
local tonumber = tonumber
local tostring = tostring
local concat = table.concat
local floor = math.floor
local fmt = string.format
--local pairs = pairs
--local type = type
local ngx = ngx
Expand Down Expand Up @@ -173,32 +169,6 @@ local _mt = {}
_mt.__index = _mt


function _mt:init()
local res, err = self:query("SHOW server_version_num;")
local ver = tonumber(res and res[1] and res[1].server_version_num)
if not ver then
return nil, err or "postgres version not detected"
end

self.version_num = ver


local major = floor(ver / 10000)
if major < 10 then
self.major_version = fmt("%u.%u", major, floor(ver / 100 % 100))
self.minor_version = tostring(ver % 100)

else
self.major_version = tostring(major)
self.minor_version = tostring(ver % 100)
end

self.version = fmt("%s.%s", self.major_version, self.minor_version)

return true
end


function _mt:connect()
if self.connection and self.connection.sock then
return true
Expand Down
95 changes: 17 additions & 78 deletions kong/db/strategies/postgres/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -719,46 +719,16 @@ end
function _mt:upsert(primary_key, entity)
local collapsed_entity = self.collapse(entity, primary_key)

if self.connector.version_num >= 90500 then
local res, err = execute(self, "upsert", collapsed_entity)
if res then
local row = res[1]
if row then
return self.expand(row), nil
end
return nil, self.errors:not_found(primary_key)
local res, err = execute(self, "upsert", collapsed_entity)
if res then
local row = res[1]
if row then
return self.expand(row), nil
end

return toerror(self, err, primary_key, entity)
return nil, self.errors:not_found(primary_key)
end

while true do
local res, err = execute(self, "insert", collapsed_entity)
if res then
local row = res[1]
if row then
return self.expand(row), nil
end

return nil, nil
end

local _, err_t = toerror(self, err, nil, entity)
if err_t.code ~= self.errors.codes.PRIMARY_KEY_VIOLATION then
return _, err_t
end

res, err = execute(self, "update", collapsed_entity, true)
if res then
local row = res[1]
if row then
return self.expand(row), nil
end

else
return toerror(self, err, primary_key, entity)
end
end
return toerror(self, err, primary_key, entity)
end


Expand All @@ -767,50 +737,19 @@ function _mt:upsert_by_field(field_name, unique_value, entity)
[field_name] = unique_value
})

if self.connector.version_num >= 90500 then
local statement_name = "upsert_by_" .. field_name
local res, err = execute(self, statement_name, collapsed_entity)
if res then
local row = res[1]
if row then
return self.expand(row), nil
end
return nil, self.errors:not_found_by_field {
[field_name] = unique_value,
}
local statement_name = "upsert_by_" .. field_name
local res, err = execute(self, statement_name, collapsed_entity)
if res then
local row = res[1]
if row then
return self.expand(row), nil
end

return toerror(self, err, { [field_name] = unique_value }, entity)
return nil, self.errors:not_found_by_field {
[field_name] = unique_value,
}
end

while true do
local res, err = execute(self, "insert", collapsed_entity)
if res then
local row = res[1]
if row then
return self.expand(row), nil
end

return nil, nil
end

local _, err_t = toerror(self, err, nil, entity)
if err_t.code ~= self.errors.codes.UNIQUE_VIOLATION then
return _, err_t
end

local statement_name = "update_by_" .. field_name
res, err = execute(self, statement_name, self.collapse({ [UNIQUE] = unique_value }, entity), true)
if res then
local row = res[1]
if row then
return self.expand(row), nil
end

else
return toerror(self, err, { [field_name] = unique_value }, entity)
end
end
return toerror(self, err, { [field_name] = unique_value }, entity)
end


Expand Down

0 comments on commit 6c4f3f2

Please sign in to comment.