Skip to content

Commit

Permalink
wip - cleanup after using legacy attribute for uuids. merge with feat
Browse files Browse the repository at this point in the history
  • Loading branch information
kikito committed Oct 4, 2018
1 parent d38c9f5 commit df89f46
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions kong/db/schema/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@ Schema.validators = {
end,

uuid = function(value)
if value == "" then
return true
end
if #value ~= 36 then
return nil
end
Expand Down Expand Up @@ -1256,13 +1253,22 @@ function Schema:process_auto_fields(input, context, nulls)
--]]

for key, field in self:each_field(input) do

if field.legacy and field.uuid and output[key] == "" then
output[key] = null
end

if field.auto then
if field.uuid then
if (context == "insert" or context == "upsert") and
output[key] == nil or output[key] == "" then
if (context == "insert" or context == "upsert") and output[key] == nil then
output[key] = utils.uuid()
end

elseif field.type == "string" then
if (context == "insert" or context == "upsert") and output[key] == nil then
output[key] = utils.random_string()
end

elseif (key == "created_at" and (context == "insert" or
context == "upsert")) or
(key == "updated_at" and (context == "insert" or
Expand All @@ -1274,16 +1280,6 @@ function Schema:process_auto_fields(input, context, nulls)
elseif field.type == "integer" then
output[key] = now_s
end

elseif field.type == "string" and
(context == "insert" or context == "upsert") and
(output[key] == nil or output[key] == "") then
output[key] = utils.random_string()
end

else
if field.legacy and field.uuid and output[key] == "" then
output[key] = null
end
end

Expand Down

0 comments on commit df89f46

Please sign in to comment.