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

tarantool / crud / 21364862659

26 Jan 2026 04:13PM UTC coverage: 73.492% (-15.0%) from 88.463%
21364862659

push

github

web-flow
Merge f981517ee into a84e19f3e

4253 of 5787 relevant lines covered (73.49%)

55.69 hits per line

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

80.36
/crud/schema.lua
1
local checks = require('checks')
19✔
2
local errors = require('errors')
19✔
3
local fiber = require('fiber')
19✔
4

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

7
local schema_module = require('crud.common.schema')
19✔
8
local utils = require('crud.common.utils')
19✔
9

10
local SETTINGS_SPACE = '_crud_settings_local'
19✔
11

12
local schema = {}
19✔
13

14
schema.system_spaces = {
19✔
15
    -- https://github.com/tarantool/tarantool/blob/3240201a2f5bac3bddf8a74015db9b351954e0b5/src/box/schema_def.h#L77-L127
16
    ['_vinyl_deferred_delete'] = true,
17
    ['_schema'] = true,
18
    ['_collation'] = true,
19
    ['_vcollation'] = true,
20
    ['_space'] = true,
21
    ['_vspace'] = true,
22
    ['_sequence'] = true,
23
    ['_sequence_data'] = true,
24
    ['_vsequence'] = true,
25
    ['_index'] = true,
26
    ['_vindex'] = true,
27
    ['_func'] = true,
28
    ['_vfunc'] = true,
29
    ['_user'] = true,
30
    ['_vuser'] = true,
31
    ['_priv'] = true,
32
    ['_vpriv'] = true,
33
    ['_cluster'] = true,
34
    ['_trigger'] = true,
35
    ['_truncate'] = true,
36
    ['_space_sequence'] = true,
37
    ['_vspace_sequence'] = true,
38
    ['_fk_constraint'] = true,
39
    ['_ck_constraint'] = true,
40
    ['_func_index'] = true,
41
    ['_session_settings'] = true,
42
    ['_gc_consumers'] = true,
43
    -- https://github.com/tarantool/vshard/blob/b3c27b32637863e9a03503e641bb7c8c69779a00/vshard/storage/init.lua#L752
44
    ['_bucket'] = true,
45
    -- https://github.com/tarantool/ddl/blob/b55d0ff7409f32e4d527e2d25444d883bce4163b/test/set_sharding_metadata_test.lua#L92-L98
46
    ['_ddl_sharding_key'] = true,
47
    ['_ddl_sharding_func'] = true,
48
    -- https://github.com/tarantool/tt-ee/blob/6045cd6f4f9b10fbba7e2c6abeecb8f856fee9b0/lib/migrations/internal/eval/body/lua/status_api.lua
49
    ['_tt_migrations'] = true,
50
    -- https://github.com/tarantool/cluster-federation/blob/01738cafa0dc7a3138e64f93c4e84cb323653257/src/internal/utils/utils.go#L17
51
    ['_cdc_state'] = true,
52
    [SETTINGS_SPACE] = true,
19✔
53
}
19✔
54

55
local function get_crud_schema(space)
56
    local sch = schema_module.get_normalized_space_schema(space)
2✔
57

58
    -- bucket_id is not nullable for a storage, yet
59
    -- it is optional for a crud user.
60
    for _, v in ipairs(sch.format) do
10✔
61
        if v.name == 'bucket_id' then
8✔
62
            v.is_nullable = true
2✔
63
        end
64
    end
65

66
    for id, v in pairs(sch.indexes) do
10✔
67
        -- There is no reason for a user to know about
68
        -- bucket_id index.
69
        if v.name == 'bucket_id' then
6✔
70
            sch.indexes[id] = nil
2✔
71
        end
72
    end
73

74
    return sch
2✔
75
end
76

77
schema.call = function(space_name, opts)
78
    checks('?string', {
4✔
79
        vshard_router = '?string|table',
80
        timeout = '?number',
81
        cached = '?boolean',
82
    })
83

84
    opts = opts or {}
4✔
85

86
    local vshard_router, err = utils.get_vshard_router_instance(opts.vshard_router)
4✔
87
    if err ~= nil then
4✔
88
        return nil, SchemaError:new(err)
×
89
    end
90

91
    if opts.cached ~= true then
4✔
92
        local _, err = schema_module.reload_schema(vshard_router)
4✔
93
        if err ~= nil then
4✔
94
            return nil, SchemaError:new(err)
×
95
        end
96
    end
97

98
    local spaces, err = utils.get_spaces(vshard_router, opts.timeout)
4✔
99
    if err ~= nil then
4✔
100
        return nil, SchemaError:new(err)
×
101
    end
102

103
    if space_name ~= nil then
4✔
104
        local space = spaces[space_name]
4✔
105
        if space == nil then
4✔
106
            return nil, SchemaError:new("Space %q doesn't exist", space_name)
4✔
107
        end
108
        return get_crud_schema(space)
2✔
109
    else
110
        local resp = {}
×
111

112
        for name, space in pairs(spaces) do
×
113
            -- Can be indexed by space id and space name,
114
            -- so we need to be careful with duplicates.
115
            if type(name) == 'string' and schema.system_spaces[name] == nil then
×
116
                resp[name] = get_crud_schema(space)
×
117
            end
118
        end
119

120
        return resp
×
121
    end
122
end
123

124
schema.init = function()
125
    ::init_start::
126
    if not box.info.ro then
14✔
127
        if box.space[SETTINGS_SPACE] == nil then
12✔
128
            box.schema.space.create(SETTINGS_SPACE, {
22✔
129
                engine = 'memtx',
130
                format = {
11✔
131
                    { name = 'key', type = 'string' },
11✔
132
                    { name = 'value', type = 'any' },
11✔
133
                },
11✔
134
                is_local = true,
135
                if_not_exists = true,
136
            })
137
        end
138
        if box.space[SETTINGS_SPACE].index[0] == nil then
12✔
139
            box.space[SETTINGS_SPACE]:create_index('primary', { parts = { 'key' }, if_not_exists = true })
11✔
140
        end
141
    else
142
        while box.space[SETTINGS_SPACE] == nil or box.space[SETTINGS_SPACE].index[0] == nil do
2✔
143
            fiber.sleep(0.05)
×
144
            if not box.info.ro then
×
145
                goto init_start
×
146
            end
147
        end
148
    end
149

150
    schema.settings_space = box.space[SETTINGS_SPACE]
14✔
151
end
152

153
return schema
19✔
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