Skip to content

Commit a8da90d

Browse files
no1semanTotktonada
authored andcommitted
Add datetime support for 2.10+
1 parent f63b291 commit a8da90d

File tree

9 files changed

+81
-3
lines changed

9 files changed

+81
-3
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@
66
.idea
77
luacov.report.out
88
luacov.stats.out
9+
.history
10+
CMakeCache.txt
11+
CMakeFiles
12+
cmake_install.cmake
13+
CTestTestfile.cmake
14+
Makefile
15+
/Testing
16+
*.all.rock
17+
*.src.rock

.luacheckrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
redefined = false
22
include_files = {"**/*.lua", "*.rockspec", "*.luacheckrc"}
3-
exclude_files = {".rocks/", "tmp/"}
3+
exclude_files = {".rocks/", "tmp/", ".history/"}
44
max_line_length = 120

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
- Added support of `datetime` type for Tarantool 2.10+
10+
911
## [1.6.0] - 2022-02-01
1012

1113
### Added

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ format = {
112112
type = 'unsigned' | 'string' | 'varbinary' |
113113
'integer' | 'number' | 'boolean' |
114114
'array' | 'scalar' | 'any' | 'map' |
115-
'decimal' | 'double' | 'uuid'
115+
'decimal' | 'double' | 'uuid' | 'datetime'
116116
},
117117
...
118118
},
@@ -131,7 +131,7 @@ format = {
131131
-- may be multipath if '[*]' is used,
132132
type = 'unsigned' | 'string' | 'varbinary' |
133133
'integer' | 'number' | 'boolean' | 'scalar' |
134-
'decimal' | 'double' | 'uuid',
134+
'decimal' | 'double' | 'uuid' | 'datetime',
135135
is_nullable = true | false,
136136
collation = nil | 'none' |
137137
'unicode' | 'unicode_ci' | '...',

ddl/check.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ local function check_field(i, field, space)
5353
decimal = true,
5454
double = true,
5555
uuid = true,
56+
datetime = true,
5657
}
5758

5859
if known_field_types[field.type] == nil then
@@ -68,6 +69,13 @@ local function check_field(i, field, space)
6869
space.name, field.name, _TARANTOOL
6970
)
7071
end
72+
73+
if not db.datetime_allowed() and field.type == 'datetime' then
74+
return nil, string.format(
75+
"spaces[%q].format[%q].type: datetime type isn't allowed in your Tarantool version (%s)",
76+
space.name, field.name, _TARANTOOL
77+
)
78+
end
7179
end
7280

7381

@@ -192,6 +200,7 @@ local function check_index_part_type(part_type, index_type)
192200
decimal = true,
193201
double = true,
194202
uuid = true,
203+
datetime = true,
195204
}
196205

197206
if not known_part_types[part_type] then
@@ -208,6 +217,13 @@ local function check_index_part_type(part_type, index_type)
208217
)
209218
end
210219

220+
if not db.datetime_allowed() and part_type == 'datetime' then
221+
return nil, string.format(
222+
"datetime type isn't allowed in your Tarantool version (%s)",
223+
_TARANTOOL
224+
)
225+
end
226+
211227
local err_template = "%s field type is unsupported in %s index type"
212228

213229
if index_type == 'TREE' or index_type == 'HASH' then
@@ -287,6 +303,7 @@ local function check_index_part(i, index, space)
287303
varbinary = true,
288304
double = true,
289305
decimal = true,
306+
datetime = true,
290307
}
291308

292309
do -- check index.part.type equals format.field.type

ddl/db.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ local function varbinary_allowed()
2626
return check_version(2, 2)
2727
end
2828

29+
local function datetime_allowed()
30+
return check_version(2, 10)
31+
end
32+
33+
2934
-- https://github.com/tarantool/tarantool/issues/4083
3035
local function transactional_ddl_allowed()
3136
return check_version(2, 2)
@@ -68,6 +73,7 @@ return {
6873
varbinary_allowed = varbinary_allowed,
6974
multikey_path_allowed = multikey_path_allowed,
7075
transactional_ddl_allowed = transactional_ddl_allowed,
76+
datetime_allowed = datetime_allowed,
7177

7278
call_atomic = call_atomic,
7379
call_dry_run = call_dry_run,

deps.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
# Call this script to install test dependencies
3+
4+
set -e
5+
6+
# Test dependencies:
7+
tarantoolctl rocks install luatest 0.5.7
8+
tarantoolctl rocks install luacov 0.13.0
9+
tarantoolctl rocks install luacheck 0.26.0

test/check_schema_test.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ function g.test_varbinaty_index_part_type()
183183
end
184184
end
185185

186+
function g.test_datetime_index_part_type()
187+
if db.v(2, 10) then
188+
local ok, err = ddl_check.check_index_part_type('datetime', 'TREE')
189+
t.assert(ok)
190+
t.assert_not(err)
191+
else
192+
local ok, err = ddl_check.check_index_part_type('datetime', 'TREE')
193+
t.assert_not(ok)
194+
t.assert_equals(err, string.format(
195+
"datetime type isn't allowed in your Tarantool version (%s)",
196+
_TARANTOOL
197+
))
198+
end
199+
end
200+
186201
function g.test_index_part_path()
187202
local index_info = {type = 'HASH'}
188203

@@ -1129,6 +1144,21 @@ function g.test_field()
11291144
_TARANTOOL
11301145
))
11311146
end
1147+
1148+
local ok, err = ddl_check.check_field(
1149+
1, {name = 'x', type = 'datetime', is_nullable = false}, space_info
1150+
)
1151+
if db.v(2, 10) then
1152+
t.assert(ok)
1153+
t.assert_not(err)
1154+
else
1155+
t.assert_not(ok)
1156+
t.assert_equals(err, string.format(
1157+
[[spaces["space"].format["x"].type: datetime type ]] ..
1158+
[[isn't allowed in your Tarantool version (%s)]],
1159+
_TARANTOOL
1160+
))
1161+
end
11321162
end
11331163

11341164
function g.test_scalar_types()

test/helper.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ function helpers.test_space_format()
4949
table.insert(space_format, {name = 'varbinary_nullable', type = 'varbinary', is_nullable = true})
5050
end
5151

52+
if db.v(2, 10) then
53+
table.insert(space_format, {name = 'datetime_nonnull', type = 'datetime', is_nullable = false})
54+
table.insert(space_format, {name = 'datetime_nullable', type = 'datetime', is_nullable = true})
55+
end
56+
5257
return table.deepcopy(space_format)
5358
end
5459

0 commit comments

Comments
 (0)