• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tarantool / crud / 6493431653

12 Oct 2023 08:50AM UTC coverage: 89.162% (+0.02%) from 89.14%
6493431653

push

github

DifferentialOrange
schema: support cached schema

6 of 6 new or added lines in 1 file covered. (100.0%)

4615 of 5176 relevant lines covered (89.16%)

17856.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/crud/schema.lua
1
local checks = require('checks')
354✔
2
local errors = require('errors')
354✔
3

4
local SchemaError = errors.new_class('SchemaError', {capture_stack = false})
354✔
5

6
local schema_module = require('crud.common.schema')
354✔
7
local utils = require('crud.common.utils')
354✔
8

9
local schema = {}
354✔
10

11
schema.system_spaces = {
354✔
12
    -- https://github.com/tarantool/tarantool/blob/3240201a2f5bac3bddf8a74015db9b351954e0b5/src/box/schema_def.h#L77-L127
13
    ['_vinyl_deferred_delete'] = true,
14
    ['_schema'] = true,
15
    ['_collation'] = true,
16
    ['_vcollation'] = true,
17
    ['_space'] = true,
18
    ['_vspace'] = true,
19
    ['_sequence'] = true,
20
    ['_sequence_data'] = true,
21
    ['_vsequence'] = true,
22
    ['_index'] = true,
23
    ['_vindex'] = true,
24
    ['_func'] = true,
25
    ['_vfunc'] = true,
26
    ['_user'] = true,
27
    ['_vuser'] = true,
28
    ['_priv'] = true,
29
    ['_vpriv'] = true,
30
    ['_cluster'] = true,
31
    ['_trigger'] = true,
32
    ['_truncate'] = true,
33
    ['_space_sequence'] = true,
34
    ['_vspace_sequence'] = true,
35
    ['_fk_constraint'] = true,
36
    ['_ck_constraint'] = true,
37
    ['_func_index'] = true,
38
    ['_session_settings'] = true,
39
    -- https://github.com/tarantool/vshard/blob/b3c27b32637863e9a03503e641bb7c8c69779a00/vshard/storage/init.lua#L752
40
    ['_bucket'] = true,
41
    -- https://github.com/tarantool/ddl/blob/b55d0ff7409f32e4d527e2d25444d883bce4163b/test/set_sharding_metadata_test.lua#L92-L98
42
    ['_ddl_sharding_key'] = true,
43
    ['_ddl_sharding_func'] = true,
44
}
354✔
45

46
local function get_crud_schema(space)
47
    local sch = schema_module.get_normalized_space_schema(space)
46✔
48

49
    -- bucket_id is not nullable for a storage, yet
50
    -- it is optional for a crud user.
51
    for _, v in ipairs(sch.format) do
252✔
52
        if v.name == 'bucket_id' then
206✔
53
            v.is_nullable = true
46✔
54
        end
55
    end
56

57
    for id, v in pairs(sch.indexes) do
210✔
58
        -- There is no reason for a user to know about
59
        -- bucket_id index.
60
        if v.name == 'bucket_id' then
118✔
61
            sch.indexes[id] = nil
46✔
62
        end
63
    end
64

65
    return sch
46✔
66
end
67

68
schema.call = function(space_name, opts)
69
    checks('?string', {
32✔
70
        vshard_router = '?string|table',
71
        timeout = '?number',
72
        cached = '?boolean',
73
    })
74

75
    opts = opts or {}
32✔
76

77
    local vshard_router, err = utils.get_vshard_router_instance(opts.vshard_router)
32✔
78
    if err ~= nil then
32✔
79
        return nil, SchemaError:new(err)
×
80
    end
81

82
    if opts.cached ~= true then
32✔
83
        local _, err = schema_module.reload_schema(vshard_router)
30✔
84
        if err ~= nil then
30✔
85
            return nil, SchemaError:new(err)
×
86
        end
87
    end
88

89
    local spaces, err = utils.get_spaces(vshard_router, opts.timeout)
32✔
90
    if err ~= nil then
32✔
91
        return nil, SchemaError:new(err)
×
92
    end
93

94
    if space_name ~= nil then
32✔
95
        local space = spaces[space_name]
12✔
96
        if space == nil then
12✔
97
            return nil, SchemaError:new("Space %q doesn't exist", space_name)
12✔
98
        end
99
        return get_crud_schema(space)
6✔
100
    else
101
        local resp = {}
20✔
102

103
        for name, space in pairs(spaces) do
1,200✔
104
            -- Can be indexed by space id and space name,
105
            -- so we need to be careful with duplicates.
106
            if type(name) == 'string' and schema.system_spaces[name] == nil then
1,160✔
107
                resp[name] = get_crud_schema(space)
80✔
108
            end
109
        end
110

111
        return resp
20✔
112
    end
113
end
114

115
return schema
354✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc