Skip to content

Commit

Permalink
test: support ddl 1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DifferentialOrange committed Apr 17, 2024
1 parent 855d4b3 commit 0fc97de
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
41 changes: 41 additions & 0 deletions test/helper/utils.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local t = require('luatest')
local luatest_utils = require('luatest.utils')

local function set_sections(g, sections)
return g.cluster.main_server:graphql({ query = [[
Expand Down Expand Up @@ -83,7 +84,47 @@ local function cleanup(g)
end)
end

local function parse_module_version(str)
-- https://github.com/tarantool/luatest/blob/f37b353b77be50a1f1ce87c1ff2edf0c1b96d5d1/luatest/utils.lua#L166-L173
local splitstr = str:split('.')
local major = tonumber(splitstr[1]:match('%d+'))
local minor = tonumber(splitstr[2]:match('%d+'))
local patch = tonumber(splitstr[3]:match('%d+'))
return luatest_utils.version(major, minor, patch)
end

local function is_ddl_supports_sequences()
local ddl = require('ddl')

if ddl._VERSION == nil then
return false
end

local parsed_ddl_version = parse_module_version(ddl._VERSION)
local are_sequences_supported = luatest_utils.version_ge(
parsed_ddl_version,
luatest_utils.version(1, 7, 0)
)

return are_sequences_supported
end

local function downgrade_ddl_schema_if_required(ddl_schema)
if not is_ddl_supports_sequences then
for _, space in pairs(ddl_schema.spaces) do
for _, index in ipairs(space.indexes) do
index.sequence = nil
end
end

ddl_schema.sequences = nil
end

return ddl_schema
end

return {
set_sections = set_sections,
cleanup = cleanup,
downgrade_ddl_schema_if_required = downgrade_ddl_schema_if_required,
}
20 changes: 17 additions & 3 deletions test/integration/basic_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ for k, configure_func in pairs(cases) do
t.assert_equals(result.json, { applied = expected_applied })

local config = main:download_config()
t.assert_covers(config, {

local expected_schema = {
schema = {
spaces = {
_migrations = {
Expand All @@ -120,6 +121,7 @@ for k, configure_func in pairs(cases) do
{
name = "primary",
parts = {{is_nullable = false, path = "id", type = "unsigned"}},
sequence = "_migrations_id_seq",
type = "TREE",
unique = true,
},
Expand Down Expand Up @@ -175,10 +177,22 @@ for k, configure_func in pairs(cases) do
sharding_key = { "key" },
temporary = false,
},

},
sequences = {
_migrations_id_seq = {
cache = 0,
cycle = false,
max = 9223372036854775807ULL,
min = 1,
start = 1,
step = 1,
},
},
},
})
}

expected_schema = utils.downgrade_ddl_schema_if_required(expected_schema)
t.assert_covers(config, expected_schema)

result = main:http_request('post', '/migrations/up', { json = {} })
t.assert_equals(result.json, { applied = {} })
Expand Down

0 comments on commit 0fc97de

Please sign in to comment.