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

fix(migrations) stop depending on the order as recorded #2869

Merged
merged 1 commit into from
Sep 8, 2017
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
10 changes: 7 additions & 3 deletions kong/dao/factory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,14 @@ end

local function migrate(self, identifier, migrations_modules, cur_migrations, on_migrate, on_success)
local migrations = migrations_modules[identifier]
local recorded = cur_migrations[identifier] or {}
local recorded = {}
for _, name in ipairs(cur_migrations[identifier] or {}) do
recorded[name] = true
end

local to_run = {}
for i, mig in ipairs(migrations) do
if mig.name ~= recorded[i] then
for _, mig in ipairs(migrations) do
if not recorded[mig.name] then
to_run[#to_run + 1] = mig
end
end
Expand Down
23 changes: 23 additions & 0 deletions spec/02-integration/03-dao/02-migrations_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ helpers.for_each_dao(function(kong_config)
assert.falsy(err)
assert.True(ok)

assert.spy(on_migration).was_not_called()
assert.spy(on_success).was_not_called()
end)
it("should not depend on order of the migration entries", function()
local old_fetcher = factory.current_migrations
finally(function()
factory.current_migrations = old_fetcher
end)

factory.current_migrations = function(...)
local mig = old_fetcher(...)
local core = mig.core
core[#core], core[#core-1] = core[#core-1], core[#core]
return mig
end

local on_migration = spy.new(function() end)
local on_success = spy.new(function() end)

local ok, err = factory:run_migrations(on_migration, on_success)
assert.falsy(err)
assert.True(ok)

assert.spy(on_migration).was_not_called()
assert.spy(on_success).was_not_called()
end)
Expand Down