1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
test_run = require('test_run').new()
---
...
engine = test_run:get_cfg('engine')
---
...
_ = box.space._session_settings:update('sql_default_engine', {{'=', 2, engine}})
---
...
-- box.cfg()
-- create space
box.execute("CREATE TABLE zzzoobar (c1 INT, c2 INT PRIMARY KEY, c3 TEXT, c4 INT)")
---
- row_count: 1
...
box.execute("CREATE INDEX zb ON zzzoobar(c1, c3)")
---
- row_count: 1
...
-- Dummy entry
box.execute("INSERT INTO zzzoobar VALUES (111, 222, 'c3', 444)")
---
- row_count: 1
...
box.execute("DROP TABLE zzzoobar")
---
- row_count: 1
...
-- Table does not exist anymore. Should error here.
box.execute("INSERT INTO zzzoobar VALUES (111, 222, 'c3', 444)")
---
- null
- Space 'ZZZOOBAR' does not exist
...
-- gh-3712: if space features sequence, data from _sequence_data
-- must be deleted before space is dropped.
--
box.execute("CREATE TABLE t1 (id INT PRIMARY KEY AUTOINCREMENT);")
---
- row_count: 1
...
box.execute("INSERT INTO t1 VALUES (NULL);")
---
- autoincrement_ids:
- 1
row_count: 1
...
box.snapshot()
---
- ok
...
test_run:cmd('restart server default')
box.execute("DROP TABLE t1;")
---
- row_count: 1
...
-- Cleanup
-- DROP TABLE should do the job
-- Debug
-- require("console").start()
--
-- gh-3592: clean-up garbage on failed CREATE TABLE statement.
--
-- Let user have enough rights to create space, but not enough to
-- create index.
--
box.schema.user.create('tmp')
---
...
box.schema.user.grant('tmp', 'create, read', 'universe')
---
...
box.schema.user.grant('tmp', 'write', 'space', '_space')
---
...
box.schema.user.grant('tmp', 'write', 'space', '_schema')
---
...
-- Number of records in _space, _index, _sequence:
space_count = #box.space._space:select()
---
...
index_count = #box.space._index:select()
---
...
sequence_count = #box.space._sequence:select()
---
...
box.session.su('tmp')
---
...
--
-- Error: user do not have rights to write in box.space._index.
-- Space that was already created should be automatically dropped.
--
box.execute('CREATE TABLE t1 (id INT PRIMARY KEY, a INT)')
---
- null
- Write access to space '_index' is denied for user 'tmp'
...
-- Error: no such table.
box.execute('DROP TABLE t1')
---
- null
- Space 'T1' does not exist
...
box.session.su('admin')
---
...
--
-- Check that _space, _index and _sequence have the same number of
-- records.
--
space_count == #box.space._space:select()
---
- true
...
index_count == #box.space._index:select()
---
- true
...
sequence_count == #box.space._sequence:select()
---
- true
...
--
-- Give user right to write in _index. Still have not enough
-- rights to write in _sequence.
--
box.schema.user.grant('tmp', 'write', 'space', '_index')
---
...
box.session.su('tmp')
---
...
--
-- Error: user do not have rights to write in _sequence.
--
box.execute('CREATE TABLE t2 (id INT PRIMARY KEY AUTOINCREMENT, a INT UNIQUE, b INT UNIQUE, c INT UNIQUE, d INT UNIQUE)')
---
- null
- Write access to space '_sequence' is denied for user 'tmp'
...
box.session.su('admin')
---
...
--
-- Check that _space, _index and _sequence have the same number of
-- records.
--
space_count == #box.space._space:select()
---
- true
...
index_count == #box.space._index:select()
---
- true
...
sequence_count == #box.space._sequence:select()
---
- true
...
fk_constraint_count = #box.space._fk_constraint:select()
---
...
--
-- Check that clean-up works fine after another error.
--
box.schema.user.grant('tmp', 'write', 'space')
---
...
box.session.su('tmp')
---
...
box.execute('CREATE TABLE t3(a INTEGER PRIMARY KEY);')
---
- row_count: 1
...
--
-- Error: Failed to create foreign key constraint.
--
box.execute('CREATE TABLE t4(x INTEGER PRIMARY KEY REFERENCES t3, a INT UNIQUE, c TEXT REFERENCES t3);')
---
- null
- 'Failed to create foreign key constraint ''fk_unnamed_T4_2'': field type mismatch'
...
box.execute('DROP TABLE t3;')
---
- row_count: 1
...
--
-- Check that _space, _index and _sequence have the same number of
-- records.
--
space_count == #box.space._space:select()
---
- true
...
index_count == #box.space._index:select()
---
- true
...
sequence_count == #box.space._sequence:select()
---
- true
...
fk_constraint_count == #box.space._fk_constraint:select()
---
- true
...
box.session.su('admin')
---
...
box.schema.user.drop('tmp')
---
...
|