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

chore(db) drop support for deprecated dbs #3490

Merged
merged 1 commit into from
May 29, 2018
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
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