From a8da90dc67dbb07ea6499f0950f40d2d6376f91d Mon Sep 17 00:00:00 2001 From: Yaroslav Shumakov Date: Tue, 21 Jun 2022 10:52:20 +0300 Subject: [PATCH] Add datetime support for 2.10+ --- .gitignore | 9 +++++++++ .luacheckrc | 2 +- CHANGELOG.md | 2 ++ README.md | 4 ++-- ddl/check.lua | 17 +++++++++++++++++ ddl/db.lua | 6 ++++++ deps.sh | 9 +++++++++ test/check_schema_test.lua | 30 ++++++++++++++++++++++++++++++ test/helper.lua | 5 +++++ 9 files changed, 81 insertions(+), 3 deletions(-) create mode 100755 deps.sh diff --git a/.gitignore b/.gitignore index 02eb216..d356227 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,12 @@ .idea luacov.report.out luacov.stats.out +.history +CMakeCache.txt +CMakeFiles +cmake_install.cmake +CTestTestfile.cmake +Makefile +/Testing +*.all.rock +*.src.rock diff --git a/.luacheckrc b/.luacheckrc index d98a3aa..c4bc116 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,4 +1,4 @@ redefined = false include_files = {"**/*.lua", "*.rockspec", "*.luacheckrc"} -exclude_files = {".rocks/", "tmp/"} +exclude_files = {".rocks/", "tmp/", ".history/"} max_line_length = 120 diff --git a/CHANGELOG.md b/CHANGELOG.md index ffbca52..23f0432 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +- Added support of `datetime` type for Tarantool 2.10+ + ## [1.6.0] - 2022-02-01 ### Added diff --git a/README.md b/README.md index 6aae842..2a7ee5d 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ format = { type = 'unsigned' | 'string' | 'varbinary' | 'integer' | 'number' | 'boolean' | 'array' | 'scalar' | 'any' | 'map' | - 'decimal' | 'double' | 'uuid' + 'decimal' | 'double' | 'uuid' | 'datetime' }, ... }, @@ -131,7 +131,7 @@ format = { -- may be multipath if '[*]' is used, type = 'unsigned' | 'string' | 'varbinary' | 'integer' | 'number' | 'boolean' | 'scalar' | - 'decimal' | 'double' | 'uuid', + 'decimal' | 'double' | 'uuid' | 'datetime', is_nullable = true | false, collation = nil | 'none' | 'unicode' | 'unicode_ci' | '...', diff --git a/ddl/check.lua b/ddl/check.lua index cc9465e..95f5bc0 100644 --- a/ddl/check.lua +++ b/ddl/check.lua @@ -53,6 +53,7 @@ local function check_field(i, field, space) decimal = true, double = true, uuid = true, + datetime = true, } if known_field_types[field.type] == nil then @@ -68,6 +69,13 @@ local function check_field(i, field, space) space.name, field.name, _TARANTOOL ) end + + if not db.datetime_allowed() and field.type == 'datetime' then + return nil, string.format( + "spaces[%q].format[%q].type: datetime type isn't allowed in your Tarantool version (%s)", + space.name, field.name, _TARANTOOL + ) + end end @@ -192,6 +200,7 @@ local function check_index_part_type(part_type, index_type) decimal = true, double = true, uuid = true, + datetime = true, } if not known_part_types[part_type] then @@ -208,6 +217,13 @@ local function check_index_part_type(part_type, index_type) ) end + if not db.datetime_allowed() and part_type == 'datetime' then + return nil, string.format( + "datetime type isn't allowed in your Tarantool version (%s)", + _TARANTOOL + ) + end + local err_template = "%s field type is unsupported in %s index type" if index_type == 'TREE' or index_type == 'HASH' then @@ -287,6 +303,7 @@ local function check_index_part(i, index, space) varbinary = true, double = true, decimal = true, + datetime = true, } do -- check index.part.type equals format.field.type diff --git a/ddl/db.lua b/ddl/db.lua index f7c2f30..aec3f68 100644 --- a/ddl/db.lua +++ b/ddl/db.lua @@ -26,6 +26,11 @@ local function varbinary_allowed() return check_version(2, 2) end +local function datetime_allowed() + return check_version(2, 10) +end + + -- https://github.com/tarantool/tarantool/issues/4083 local function transactional_ddl_allowed() return check_version(2, 2) @@ -68,6 +73,7 @@ return { varbinary_allowed = varbinary_allowed, multikey_path_allowed = multikey_path_allowed, transactional_ddl_allowed = transactional_ddl_allowed, + datetime_allowed = datetime_allowed, call_atomic = call_atomic, call_dry_run = call_dry_run, diff --git a/deps.sh b/deps.sh new file mode 100755 index 0000000..9d35bf3 --- /dev/null +++ b/deps.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# Call this script to install test dependencies + +set -e + +# Test dependencies: +tarantoolctl rocks install luatest 0.5.7 +tarantoolctl rocks install luacov 0.13.0 +tarantoolctl rocks install luacheck 0.26.0 diff --git a/test/check_schema_test.lua b/test/check_schema_test.lua index e4b4d34..26d3a21 100644 --- a/test/check_schema_test.lua +++ b/test/check_schema_test.lua @@ -183,6 +183,21 @@ function g.test_varbinaty_index_part_type() end end +function g.test_datetime_index_part_type() + if db.v(2, 10) then + local ok, err = ddl_check.check_index_part_type('datetime', 'TREE') + t.assert(ok) + t.assert_not(err) + else + local ok, err = ddl_check.check_index_part_type('datetime', 'TREE') + t.assert_not(ok) + t.assert_equals(err, string.format( + "datetime type isn't allowed in your Tarantool version (%s)", + _TARANTOOL + )) + end +end + function g.test_index_part_path() local index_info = {type = 'HASH'} @@ -1129,6 +1144,21 @@ function g.test_field() _TARANTOOL )) end + + local ok, err = ddl_check.check_field( + 1, {name = 'x', type = 'datetime', 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: datetime 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 b729f20..cf785b3 100644 --- a/test/helper.lua +++ b/test/helper.lua @@ -49,6 +49,11 @@ function helpers.test_space_format() table.insert(space_format, {name = 'varbinary_nullable', type = 'varbinary', is_nullable = true}) end + if db.v(2, 10) then + table.insert(space_format, {name = 'datetime_nonnull', type = 'datetime', is_nullable = false}) + table.insert(space_format, {name = 'datetime_nullable', type = 'datetime', is_nullable = true}) + end + return table.deepcopy(space_format) end