Skip to content
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
redefined = false
include_files = {"**/*.lua", "*.rockspec", "*.luacheckrc"}
exclude_files = {".rocks/", "tmp/"}
exclude_files = {".rocks/", "tmp/", ".history/"}
max_line_length = 120
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ format = {
type = 'unsigned' | 'string' | 'varbinary' |
'integer' | 'number' | 'boolean' |
'array' | 'scalar' | 'any' | 'map' |
'decimal' | 'double' | 'uuid'
'decimal' | 'double' | 'uuid' | 'datetime'
},
...
},
Expand All @@ -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' | '...',
Expand Down
17 changes: 17 additions & 0 deletions ddl/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions ddl/db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions deps.sh
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions test/check_schema_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'}

Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down