diff --git a/extra/schema_fill.lua b/extra/schema_fill.lua index b884748334b667caeef9e183e24d8695bfc1a2e6..4f1e661966254df2d19cd2f6f6ce626751ef2717 100644 --- a/extra/schema_fill.lua +++ b/extra/schema_fill.lua @@ -20,42 +20,79 @@ _schema:insert{'version', 1, 6} -- -- _schema -- -_space:insert{_schema.id, ADMIN, '_schema', 'memtx', 0, ''} +_space:insert{_schema.id, ADMIN, '_schema', 'memtx', 0, '', {}} -- -- _space -- -_space:insert{_space.id, ADMIN, '_space', 'memtx', 0, ''} +_space:insert{_space.id, ADMIN, '_space', 'memtx', 0, '', {}} -- -- _index -- -_space:insert{_index.id, ADMIN, '_index', 'memtx', 0, ''} +_space:insert{_index.id, ADMIN, '_index', 'memtx', 0, '', {}} -- -- _func -- -_space:insert{_func.id, ADMIN, '_func', 'memtx', 0, ''} +_space:insert{_func.id, ADMIN, '_func', 'memtx', 0, '', {}} -- -- _user -- -_space:insert{_user.id, ADMIN, '_user', 'memtx', 0, ''} +_space:insert{_user.id, ADMIN, '_user', 'memtx', 0, '', {}} -- -- _priv -- -_space:insert{_priv.id, ADMIN, '_priv', 'memtx', 0, ''} +_space:insert{_priv.id, ADMIN, '_priv', 'memtx', 0, '', {}} -- -- _cluster -- _space:insert{_cluster.id, ADMIN, '_cluster', 'memtx', 0, ''} +-- define formats. +-- stick to the following convention: +-- prefer user id (owner id) in field #2 (base-1) +-- prefer object name in field #3 (base-1) +-- +format={} +format[1] = {type='str', name='key'} +_schema:format(format) +format={} +format[1] = {name='id', type='num'} +format[2] = {name='owner', type='num'} +format[3] = {name='name', type='str'} +format[4] = {name='engine', type='str'} +format[5] = {name='field_count', type='num'} +format[6] = {name='flags', type='str'} +format[7] = {name='format', type='*'} +_space:format(format) +format={} +format[1] = {name='id', type='num'} +format[2] = {name='owner', type='num'} +format[3] = {name='name', type='str'} +format[4] = {name='setuid', type='num'} +_func:format(format) +format={} +format[1] = {name='id', type='num'} +format[2] = {name='owner', type='num'} +format[3] = {name='name', type='str'} +format[4] = {name='type', type='str'} +format[5] = {name='auth', type='*'} +_user:format(format) +format={} +format[1] = {name='grantor', type='num'} +format[2] = {name='grantee', type='num'} +format[3] = {name='object_type', type='str'} +format[4] = {name='object_id', type='num'} +format[5] = {name='privilege', type='num'} +_priv:format(format) +format = {} +format[1] = {name='id', type='num'} +format[2] = {name='uuid', type='str'} +_cluster:format(format) -- define indexes -_index:insert{_schema.id, 0, 'primary', 'tree', 1, 1, 0, 'str'} - -- stick to the following convention: --- prefer user id (owner id) in field #1 --- prefer object name in field #2 --- index on owner id is index #1 --- index on object name is index #2 --- +-- index on owner id is index #1 (base-0) +-- index on object name is index #2 (base-0) -- space name is unique +_index:insert{_schema.id, 0, 'primary', 'tree', 1, 1, 0, 'str'} _index:insert{_space.id, 0, 'primary', 'tree', 1, 1, 0, 'num'} _index:insert{_space.id, 1, 'owner', 'tree', 0, 1, 1, 'num'} _index:insert{_space.id, 2, 'name', 'tree', 1, 1, 2, 'str'} diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap index 2c0715d7f83f7d0ccf0dffc4361941fe70b46dd6..0ba0e769ecb83b49117c389e1b8454930de62b8e 100644 Binary files a/src/box/bootstrap.snap and b/src/box/bootstrap.snap differ diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index 6df1b9b413c6d78fa283f8c6edda40a81d8011fd..eb61e5b8e9781e91bed83787541f8f1b3c7481ba 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -189,6 +189,7 @@ box.schema.space.create = function(name, options) id = 'number', field_count = 'number', user = 'string, number', + format = 'table' } local options_defaults = { engine = 'memtx', @@ -222,10 +223,23 @@ box.schema.space.create = function(name, options) uid = session.uid() end local temporary = options.temporary and "temporary" or "" - _space:insert{id, uid, name, options.engine, options.field_count, temporary} + local format = options.format and options.format or {} + _space:insert{id, uid, name, options.engine, options.field_count, temporary, format} return box.space[id], "created" end +-- space format - the metadata about space fields +function box.schema.space.format(id, format) + _space = box.space._space + check_param(id, 'id', 'number') + check_param(format, 'format', 'table') + if format == nil then + return _space:get(id)[7] + else + _space:update(id, {{'=', 7, format}}) + end +end + box.schema.create_space = box.schema.space.create box.schema.space.drop = function(space_id) @@ -809,6 +823,9 @@ function box.schema.space.bless(space) _index:insert(keys[i]) end end + space_mt.format = function(space, format) + return box.schema.space.format(space.id, format) + end space_mt.drop = function(space) return box.schema.space.drop(space.id) end diff --git a/test/box/access_misc.result b/test/box/access_misc.result index 7318cc5abead6d50997f5257ca6482cc074162d1..52e788ab82c63a65cb52272990db158e47bc9738 100644 --- a/test/box/access_misc.result +++ b/test/box/access_misc.result @@ -253,7 +253,10 @@ box.space._user:select(1) ... box.space._space:select(280) --- -- - [280, 1, '_space', 'memtx', 0, ''] +- - [280, 1, '_space', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner', + 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'engine', 'type': 'str'}, + {'name': 'field_count', 'type': 'num'}, {'name': 'flags', 'type': 'str'}, { + 'name': 'format', 'type': '*'}]] ... us = box.schema.create_space('uniuser_space') --- @@ -577,13 +580,22 @@ box.space._user:select() ... box.space._space:select() --- -- - [272, 1, '_schema', 'memtx', 0, ''] - - [280, 1, '_space', 'memtx', 0, ''] +- - [272, 1, '_schema', 'memtx', 0, '', [{'type': 'str', 'name': 'key'}]] + - [280, 1, '_space', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner', + 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'engine', 'type': 'str'}, + {'name': 'field_count', 'type': 'num'}, {'name': 'flags', 'type': 'str'}, { + 'name': 'format', 'type': '*'}]] - [288, 1, '_index', 'memtx', 0, ''] - - [296, 1, '_func', 'memtx', 0, ''] - - [304, 1, '_user', 'memtx', 0, ''] - - [312, 1, '_priv', 'memtx', 0, ''] - - [320, 1, '_cluster', 'memtx', 0, ''] + - [296, 1, '_func', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner', + 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'setuid', 'type': 'num'}]] + - [304, 1, '_user', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner', + 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'type', 'type': 'str'}, + {'name': 'auth', 'type': '*'}]] + - [312, 1, '_priv', 'memtx', 0, '', [{'name': 'grantor', 'type': 'num'}, {'name': 'grantee', + 'type': 'num'}, {'name': 'object_type', 'type': 'str'}, {'name': 'object_id', + 'type': 'num'}, {'name': 'privilege', 'type': 'num'}]] + - [320, 1, '_cluster', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'uuid', + 'type': 'str'}]] ... box.space._func:select() --- diff --git a/test/box/alter_limits.result b/test/box/alter_limits.result index be2884b36cff06e39de1cdfbb8afff875b6a6569..f89e5d14deda8fc4bd691b071d61da760a75eca7 100644 --- a/test/box/alter_limits.result +++ b/test/box/alter_limits.result @@ -273,7 +273,7 @@ box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 1}}) -- remove field_count - ok box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 0}}) --- -- [512, 1, 'test', 'memtx', 0, ''] +- [512, 1, 'test', 'memtx', 0, '', []] ... s:select{} --- @@ -294,7 +294,7 @@ s:select{} -- set field_count of an empty space box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) --- -- [512, 1, 'test', 'memtx', 3, ''] +- [512, 1, 'test', 'memtx', 3, '', []] ... s:select{} --- diff --git a/test/box/bootstrap.result b/test/box/bootstrap.result index 60ff3b25bba8d0e8e0a750aada9ad3a90b9e4d60..8e55683e96d180ea8546658ce7c730aef9531af6 100644 --- a/test/box/bootstrap.result +++ b/test/box/bootstrap.result @@ -47,13 +47,22 @@ box.space._cluster:select{} ... box.space._space:select{} --- -- - [272, 1, '_schema', 'memtx', 0, ''] - - [280, 1, '_space', 'memtx', 0, ''] - - [288, 1, '_index', 'memtx', 0, ''] - - [296, 1, '_func', 'memtx', 0, ''] - - [304, 1, '_user', 'memtx', 0, ''] - - [312, 1, '_priv', 'memtx', 0, ''] - - [320, 1, '_cluster', 'memtx', 0, ''] +- - [272, 1, '_schema', 'memtx', 0, '', [{'type': 'str', 'name': 'key'}]] + - [280, 1, '_space', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner', + 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'engine', 'type': 'str'}, + {'name': 'field_count', 'type': 'num'}, {'name': 'flags', 'type': 'str'}, { + 'name': 'format', 'type': '*'}]] + - [288, 1, '_index', 'memtx', 0, '', []] + - [296, 1, '_func', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner', + 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'setuid', 'type': 'num'}]] + - [304, 1, '_user', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner', + 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'type', 'type': 'str'}, + {'name': 'auth', 'type': '*'}]] + - [312, 1, '_priv', 'memtx', 0, '', [{'name': 'grantor', 'type': 'num'}, {'name': 'grantee', + 'type': 'num'}, {'name': 'object_type', 'type': 'str'}, {'name': 'object_id', + 'type': 'num'}, {'name': 'privilege', 'type': 'num'}]] + - [320, 1, '_cluster', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'uuid', + 'type': 'str'}]] ... box.space._index:select{} --- diff --git a/test/box/temp_spaces.result b/test/box/temp_spaces.result index 16b1a4b8677257ea3486e3c5ec461e2d31347aa3..548fb8cbddc76e3bd753a2ff3b7142ca23fbd415 100644 --- a/test/box/temp_spaces.result +++ b/test/box/temp_spaces.result @@ -55,7 +55,7 @@ s:len() ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'temporary'}}) --- -- [512, 1, 't', 'memtx', 0, 'temporary'] +- [512, 1, 't', 'memtx', 0, 'temporary', []] ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, ''}}) --- @@ -79,7 +79,7 @@ s.temporary ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}}) --- -- [512, 1, 't', 'memtx', 0, 'no-temporary'] +- [512, 1, 't', 'memtx', 0, 'no-temporary', []] ... s.temporary --- @@ -87,7 +87,7 @@ s.temporary ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, ',:asfda:temporary'}}) --- -- [512, 1, 't', 'memtx', 0, ',:asfda:temporary'] +- [512, 1, 't', 'memtx', 0, ',:asfda:temporary', []] ... s.temporary --- @@ -95,7 +95,7 @@ s.temporary ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'a,b,c,d,e'}}) --- -- [512, 1, 't', 'memtx', 0, 'a,b,c,d,e'] +- [512, 1, 't', 'memtx', 0, 'a,b,c,d,e', []] ... s.temporary --- @@ -103,7 +103,7 @@ s.temporary ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'temporary'}}) --- -- [512, 1, 't', 'memtx', 0, 'temporary'] +- [512, 1, 't', 'memtx', 0, 'temporary', []] ... s.temporary --- @@ -118,7 +118,7 @@ s:insert{1, 2, 3} ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'temporary'}}) --- -- [512, 1, 't', 'memtx', 0, 'temporary'] +- [512, 1, 't', 'memtx', 0, 'temporary', []] ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}}) --- @@ -130,7 +130,7 @@ s:delete{1} ... box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}}) --- -- [512, 1, 't', 'memtx', 0, 'no-temporary'] +- [512, 1, 't', 'memtx', 0, 'no-temporary', []] ... s:drop() ---