diff --git a/kong/dao/migrations/cassandra.lua b/kong/dao/migrations/cassandra.lua index 96657cbfd1b..524e1e8ebae 100644 --- a/kong/dao/migrations/cassandra.lua +++ b/kong/dao/migrations/cassandra.lua @@ -481,6 +481,15 @@ return { ]], down = function(_, _, dao) end -- not implemented }, + { + name = "2017-11-07-192000_upstream_healthchecks", + up = [[ + ALTER TABLE upstreams ADD healthchecks text; + ]], + down = [[ + ALTER TABLE upstreams DROP healthchecks; + ]] + }, { name = "2017-10-27-134100_consistent_hashing_1", up = [[ @@ -497,7 +506,7 @@ return { ]] }, { - name = "2017-10-27-134100_consistent_hashing_2", + name = "2017-11-07-192100_upstream_healthchecks_2", up = function(_, _, dao) local rows, err = dao.db:query([[ SELECT * FROM upstreams; @@ -506,54 +515,43 @@ return { return err end + local upstreams = require("kong.dao.schemas.upstreams") + local default = upstreams.fields.healthchecks.default + for _, row in ipairs(rows) do - if not row.hash_on or not row.hash_fallback then - row.hash_on = "none" - row.hash_fallback = "none" --- row.created_at = nil - local _, err = dao.upstreams:update(row, { id = row.id }) + if not row.healthchecks then + + local _, err = dao.upstreams:update({ + healthchecks = default, + }, { id = row.id }) if err then return err end end end end, - down = function(_, _, dao) end -- n.a. since the columns will be dropped - }, - { - name = "2017-11-07-192000_upstream_healthchecks", - up = [[ - ALTER TABLE upstreams ADD healthchecks text; - ]], - down = [[ - ALTER TABLE upstreams DROP healthchecks; - ]] + down = function(_, _, dao) end }, { - name = "2017-11-07-192100_upstream_healthchecks_2", + name = "2017-10-27-134100_consistent_hashing_2", up = function(_, _, dao) - local rows, err = dao.db:query([[ - SELECT * FROM upstreams; - ]]) + local rows, err = dao.upstreams:find_all() if err then return err end - local upstreams = require("kong.dao.schemas.upstreams") - local default = upstreams.fields.healthchecks.default - for _, row in ipairs(rows) do - if not row.healthchecks then - - local _, err = dao.upstreams:update({ - healthchecks = default, - }, { id = row.id }) + if not row.hash_on or not row.hash_fallback then + row.hash_on = "none" + row.hash_fallback = "none" +-- row.created_at = nil + local _, err = dao.upstreams:update(row, { id = row.id }) if err then return err end end end end, - down = function(_, _, dao) end + down = function(_, _, dao) end -- n.a. since the columns will be dropped }, } diff --git a/kong/dao/migrations/postgres.lua b/kong/dao/migrations/postgres.lua index aeb43d88a65..20c2049bb79 100644 --- a/kong/dao/migrations/postgres.lua +++ b/kong/dao/migrations/postgres.lua @@ -542,6 +542,21 @@ return { ALTER TABLE apis ALTER COLUMN created_at SET DEFAULT CURRENT_TIMESTAMP(0); ]] }, + { + name = "2017-11-07-192000_upstream_healthchecks", + up = [[ + DO $$ + BEGIN + ALTER TABLE upstreams ADD COLUMN healthchecks json; + EXCEPTION WHEN duplicate_column THEN + -- Do nothing, accept existing state + END$$; + + ]], + down = [[ + ALTER TABLE upstreams DROP COLUMN IF EXISTS healthchecks; + ]] + }, { name = "2017-10-27-134100_consistent_hashing_1", up = [[ @@ -558,7 +573,7 @@ return { ]] }, { - name = "2017-10-27-134100_consistent_hashing_2", + name = "2017-11-07-192100_upstream_healthchecks_2", up = function(_, _, dao) local rows, err = dao.db:query([[ SELECT * FROM upstreams; @@ -567,37 +582,25 @@ return { return err end + local upstreams = require("kong.dao.schemas.upstreams") + local default = upstreams.fields.healthchecks.default + for _, row in ipairs(rows) do - if not row.hash_on or not row.hash_fallback then - row.hash_on = "none" - row.hash_fallback = "none" - row.created_at = nil - local _, err = dao.upstreams:update(row, { id = row.id }) + if not row.healthchecks then + + local _, err = dao.upstreams:update({ + healthchecks = default, + }, { id = row.id }) if err then return err end end end end, - down = function(_, _, dao) end -- n.a. since the columns will be dropped - }, - { - name = "2017-11-07-192000_upstream_healthchecks", - up = [[ - DO $$ - BEGIN - ALTER TABLE upstreams ADD COLUMN healthchecks json; - EXCEPTION WHEN duplicate_column THEN - -- Do nothing, accept existing state - END$$; - - ]], - down = [[ - ALTER TABLE upstreams DROP COLUMN IF EXISTS healthchecks; - ]] + down = function(_, _, dao) end }, { - name = "2017-11-07-192100_upstream_healthchecks_2", + name = "2017-10-27-134100_consistent_hashing_2", up = function(_, _, dao) local rows, err = dao.db:query([[ SELECT * FROM upstreams; @@ -606,21 +609,18 @@ return { return err end - local upstreams = require("kong.dao.schemas.upstreams") - local default = upstreams.fields.healthchecks.default - for _, row in ipairs(rows) do - if not row.healthchecks then - - local _, err = dao.upstreams:update({ - healthchecks = default, - }, { id = row.id }) + if not row.hash_on or not row.hash_fallback then + row.hash_on = "none" + row.hash_fallback = "none" + row.created_at = nil + local _, err = dao.upstreams:update(row, { id = row.id }) if err then return err end end end end, - down = function(_, _, dao) end + down = function(_, _, dao) end -- n.a. since the columns will be dropped }, }