test_run = require('test_run').new()
---
...
engine = test_run:get_cfg('engine')
---
...
_ = box.space._session_settings:update('sql_default_engine', {{'=', 2, engine}})
---
...
work_dir = 'sql/upgrade/1.10/'
---
...
test_run:cmd('create server upgrade with script="sql/upgrade/upgrade.lua", workdir="' .. work_dir .. '"')
---
- true
...
test_run:cmd('start server upgrade')
---
- true
...
test_run:switch('upgrade')
---
- true
...
-- test system tables
box.space._space.index['name']:get('_trigger')
---
- [328, 1, '_trigger', 'memtx', 0, {}, [{'name': 'name', 'type': 'string'}, {'name': 'space_id',
      'type': 'unsigned'}, {'name': 'opts', 'type': 'map'}]]
...
box.space._index:get({box.space._space.index['name']:get('_trigger').id, 0})
---
- [328, 0, 'primary', 'tree', {'unique': true}, [[0, 'string']]]
...
box.space._schema:format()
---
- [{'type': 'string', 'name': 'key'}, {'type': 'any', 'name': 'value', 'is_nullable': true}]
...
-- test data migration
box.space._space.index['name']:get('T1')
---
- [512, 1, 'T1', 'memtx', 0, {}, [{'name': 'x', 'type': 'unsigned'}]]
...
box.space._index:get({box.space._space.index['name']:get('T1').id, 0})
---
- [512, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]]
...
-- test system tables functionality
box.execute("CREATE TABLE t(x INTEGER PRIMARY KEY);")
---
- row_count: 1
...
box.execute("CREATE TABLE t_out(x INTEGER PRIMARY KEY);")
---
- row_count: 1
...
box.execute("CREATE TRIGGER t1t AFTER INSERT ON t FOR EACH ROW BEGIN INSERT INTO t_out VALUES(1); END;")
---
- row_count: 1
...
box.execute("CREATE TRIGGER t2t AFTER INSERT ON t FOR EACH ROW BEGIN INSERT INTO t_out VALUES(2); END;")
---
- row_count: 1
...
box.space._space.index['name']:get('T')
---
- [513, 1, 'T', 'memtx', 1, {}, [{'type': 'integer', 'nullable_action': 'abort', 'name': 'X',
      'is_nullable': false}]]
...
box.space._space.index['name']:get('T_OUT')
---
- [514, 1, 'T_OUT', 'memtx', 1, {}, [{'type': 'integer', 'nullable_action': 'abort',
      'name': 'X', 'is_nullable': false}]]
...
t1t = box.space._trigger:get('T1T')
---
...
t2t = box.space._trigger:get('T2T')
---
...
t1t.name
---
- T1T
...
t1t.opts
---
- {'sql': 'CREATE TRIGGER t1t AFTER INSERT ON t FOR EACH ROW BEGIN INSERT INTO t_out
    VALUES(1); END;'}
...
t2t.name
---
- T2T
...
t2t.opts
---
- {'sql': 'CREATE TRIGGER t2t AFTER INSERT ON t FOR EACH ROW BEGIN INSERT INTO t_out
    VALUES(2); END;'}
...
assert(t1t.space_id == t2t.space_id)
---
- true
...
assert(t1t.space_id == box.space.T.id)
---
- true
...
box.execute("INSERT INTO T VALUES(1);")
---
- row_count: 1
...
box.space.T:select()
---
- - [1]
...
box.space.T_OUT:select()
---
- - [1]
  - [2]
...
box.execute("SELECT * FROM T")
---
- metadata:
  - name: X
    type: integer
  rows:
  - [1]
...
box.execute("SELECT * FROM T")
---
- metadata:
  - name: X
    type: integer
  rows:
  - [1]
...
box.execute("DROP TABLE T;")
---
- row_count: 1
...
box.execute("DROP TABLE T_OUT;")
---
- row_count: 1
...
test_run:switch('default')
---
- true
...
test_run:cmd('stop server upgrade')
---
- true
...
test_run:cmd('cleanup server upgrade')
---
- true
...
-- Test Tarantool 2.1.0 to 2.1.1 migration.
work_dir = 'sql/upgrade/2.1.0/'
---
...
test_run:cmd('create server upgrade210 with script="sql/upgrade/upgrade.lua", workdir="' .. work_dir .. '"')
---
- true
...
test_run:cmd('start server upgrade210')
---
- true
...
test_run:switch('upgrade210')
---
- true
...
s = box.space.T5
---
...
s ~= nil
---
- true
...
i = box.space._index:select(s.id)
---
...
i ~= nil
---
- true
...
i[1].opts.sql == nil
---
- true
...
box.space._space:get(s.id).flags.checks == nil
---
- true
...
check = box.space._ck_constraint:select()[1]
---
...
check ~= nil
---
- true
...
check.name
---
- CK_CONSTRAINT_1_T5
...
check.code
---
- x < 2
...
s:drop()
---
...
test_run:switch('default')
---
- true
...
test_run:cmd('stop server upgrade210')
---
- true
...
test_run:cmd('cleanup server upgrade210')
---
- true
...
