diff --git a/CHANGELOG.md b/CHANGELOG.md index 0805a8d..1674e60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- Added support of `interval` type for Tarantool 2.10+ space format. + ## [1.6.4] - 2023-07-05 ### Added diff --git a/README.md b/README.md index d8b6de8..7392ec1 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,8 @@ format = { type = 'unsigned' | 'string' | 'varbinary' | 'integer' | 'number' | 'boolean' | 'array' | 'scalar' | 'any' | 'map' | - 'decimal' | 'double' | 'uuid' | 'datetime' + 'decimal' | 'double' | 'uuid' | 'datetime' | + 'interval' }, ... }, diff --git a/ddl/check.lua b/ddl/check.lua index 45c2b1c..73ec848 100644 --- a/ddl/check.lua +++ b/ddl/check.lua @@ -59,6 +59,7 @@ local function check_field(i, field, space) double = true, uuid = true, datetime = true, + interval = true, } if known_field_types[field.type] == nil then @@ -81,6 +82,13 @@ local function check_field(i, field, space) space.name, field.name, _TARANTOOL ) end + + if not db.interval_allowed() and field.type == 'interval' then + return nil, string.format( + "spaces[%q].format[%q].type: interval type isn't allowed in your Tarantool version (%s)", + space.name, field.name, _TARANTOOL + ) + end end diff --git a/ddl/db.lua b/ddl/db.lua index 4bc9a2a..fcd2fe0 100644 --- a/ddl/db.lua +++ b/ddl/db.lua @@ -107,6 +107,10 @@ local function datetime_allowed() return tarantool_version_at_least(2, 10) end +local function interval_allowed() + return tarantool_version_at_least(2, 10) +end + -- https://github.com/tarantool/tarantool/issues/4083 local function transactional_ddl_allowed() return tarantool_version_at_least(2, 2) @@ -155,6 +159,7 @@ return { multikey_path_allowed = multikey_path_allowed, transactional_ddl_allowed = transactional_ddl_allowed, datetime_allowed = datetime_allowed, + interval_allowed = interval_allowed, exclude_null_allowed = exclude_null_allowed, call_atomic = call_atomic, diff --git a/test/check_schema_test.lua b/test/check_schema_test.lua index 8c854d5..94d32da 100644 --- a/test/check_schema_test.lua +++ b/test/check_schema_test.lua @@ -199,6 +199,12 @@ function g.test_datetime_index_part_type() end end +function g.test_interval_index_part_type() + local ok, err = ddl_check.check_index_part_type('interval', 'TREE') + t.assert_not(ok) + t.assert_equals(err, "interval field type is unsupported in TREE index type") +end + function g.test_index_part_path() local index_info = {type = 'HASH'} @@ -1156,6 +1162,21 @@ function g.test_field() _TARANTOOL )) end + + local ok, err = ddl_check.check_field( + 1, {name = 'x', type = 'interval', is_nullable = false}, space_info + ) + if db.v(2, 10) then + t.assert(ok) + t.assert_not(err) + else + t.assert_not(ok) + t.assert_equals(err, string.format( + [[spaces["space"].format["x"].type: interval type ]] .. + [[isn't allowed in your Tarantool version (%s)]], + _TARANTOOL + )) + end end function g.test_scalar_types() diff --git a/test/helper.lua b/test/helper.lua index 2eb76c6..bce3a09 100644 --- a/test/helper.lua +++ b/test/helper.lua @@ -54,6 +54,11 @@ function helpers.test_space_format() table.insert(space_format, {name = 'datetime_nullable', type = 'datetime', is_nullable = true}) end + if db.v(2, 10) then + table.insert(space_format, {name = 'interval_nonnull', type = 'interval', is_nullable = false}) + table.insert(space_format, {name = 'interval_nullable', type = 'interval', is_nullable = true}) + end + return table.deepcopy(space_format) end