Repository navigation
Expand file tree
/
Copy pathschema.cpp
More file actions
722 lines (685 loc) · 27 KB
/
Copy pathschema.cpp
File metadata and controls
722 lines (685 loc) · 27 KB
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
#include <teaql/provider_sqlite/detail/schema.hpp>
#include <teaql/provider_sqlite/detail/decoding.hpp>
#include <teaql/runtime/context.hpp>
#include <teaql/runtime/event.hpp>
#include <teaql/core/detail/debug.hpp>
#include <teaql/sql/inheritance.hpp>
#include <sqlite3.h>
#include <algorithm>
#include <charconv>
namespace teaql::detail {
namespace {
void number(String& out, std::int64_t value) {
char b[32];
auto end = std::to_chars(b, b + sizeof(b), value).ptr;
out.append(b, end);
}
bool ascii_equal(std::string_view a, std::string_view b) {
if (a.size() != b.size()) {
return false;
}
for (std::size_t i = 0; i < a.size(); ++i) {
auto lower = [](char c) {
return c >= 'A' && c <= 'Z' ? char(c + 32) : c;
};
if (lower(a[i]) != lower(b[i])) {
return false;
}
}
return true;
}
MutationExecutorError error(Memory r, sqlite3& db, int code) {
return MutationExecutorError::sqlite(
r, code, sqlite3_errcode(&db) == code ? sqlite3_errmsg(&db) : sqlite3_errstr(code));
}
MutationExecutorError prepare_error(Memory r, sqlite3& db, int code, std::string_view sql) {
#if SQLITE_VERSION_NUMBER >= 3038000
if ((code & 255) == SQLITE_ERROR && sqlite3_error_offset(&db) >= 0) {
return MutationExecutorError::sqlite(
r,
SqliteDriverError::sql_input(
r, code, sqlite3_errmsg(&db), sql, sqlite3_error_offset(&db)));
}
#else
(void)sql;
#endif
return error(r, db, code);
}
struct Statement {
Memory r;
sqlite3& db;
sqlite3_stmt* stmt = nullptr;
Statement(Memory r, sqlite3& db, std::string_view sql) : r(r), db(db) {
if (sql.size() > INT32_MAX) {
throw MutationExecutorError::sqlite(r, SQLITE_TOOBIG, "string or blob too big");
}
const char* tail = nullptr;
auto code = sqlite3_prepare_v2(&db, sql.data(), int(sql.size()), &stmt, &tail);
if (code != SQLITE_OK) {
throw prepare_error(r, db, code, sql);
}
try {
bool extra = false;
auto rest = sql;
while (tail && tail > rest.data() && tail < rest.data() + rest.size()) {
rest.remove_prefix(std::size_t(tail - rest.data()));
sqlite3_stmt* next = nullptr;
code = sqlite3_prepare_v2(&db, rest.data(), int(rest.size()), &next, &tail);
if (code != SQLITE_OK) {
throw prepare_error(r, db, code, rest);
}
extra |= next != nullptr;
sqlite3_finalize(next);
}
if (extra) {
throw MutationExecutorError::sqlite(r, SqliteDriverError::multiple_statement(r));
}
} catch (...) {
sqlite3_finalize(stmt);
stmt = nullptr;
throw;
}
}
~Statement() {
sqlite3_finalize(stmt);
}
Statement(const Statement&) = delete;
void bind(std::string_view text) {
auto code =
sqlite3_bind_text64(stmt, 1, text.data(), text.size(), SQLITE_TRANSIENT, SQLITE_UTF8);
if (code != SQLITE_OK) {
throw error(r, db, code);
}
}
bool next() {
auto code = sqlite3_step(stmt);
if (code == SQLITE_ROW) {
return true;
}
if (code == SQLITE_DONE) {
return false;
}
throw error(r, db, code);
}
void exec() {
if (next()) {
throw MutationExecutorError::sqlite(r, SqliteDriverError::execute_returned_results(r));
}
}
void require_type(int index, int expected) {
auto type = sqlite3_column_type(stmt, index);
if (type == expected) {
return;
}
auto native_type = type == SQLITE_INTEGER ? SqliteValueType::Integer
: type == SQLITE_FLOAT ? SqliteValueType::Real
: type == SQLITE_TEXT ? SqliteValueType::Text
: type == SQLITE_BLOB ? SqliteValueType::Blob
: SqliteValueType::Null;
throw MutationExecutorError::sqlite(
r,
SqliteDriverError::invalid_column_type(
r, std::size_t(index), sqlite3_column_name(stmt, index), native_type));
}
std::int64_t integer(int index) {
require_type(index, SQLITE_INTEGER);
return sqlite3_column_int64(stmt, index);
}
String text(int index) {
require_type(index, SQLITE_TEXT);
auto* data = reinterpret_cast<const char*>(sqlite3_column_text(stmt, index));
if (!data) {
throw MutationExecutorError::sqlite(r, SQLITE_NOMEM, "out of memory");
}
std::string_view value(data, std::size_t(sqlite3_column_bytes(stmt, index)));
if (auto invalid = SqliteUtf8Error::validate(value)) {
throw MutationExecutorError::sqlite(
r, SqliteDriverError::utf8_error(r, std::size_t(index), *invalid));
}
return String(value, r);
}
std::optional<String> optional_text(int index) {
if (sqlite3_column_type(stmt, index) == SQLITE_NULL) {
return {};
}
return text(index);
}
};
void execute(Memory r, sqlite3& db, std::string_view sql) {
Statement statement(r, db, sql);
statement.exec();
}
String pragma(Memory r, std::string_view name, std::string_view table) {
String result("PRAGMA ", r);
result += name;
result += '(';
result += quote_identifier_if_needed(r, table, '"');
result += ')';
return result;
}
bool table_exists(Memory r, sqlite3& db, std::string_view name) {
Statement s(r, db, "SELECT COUNT(1) FROM sqlite_master WHERE type = 'table' AND name = ?");
s.bind(name);
s.next();
return s.integer(0) > 0;
}
using Columns = std::pmr::map<String, std::pair<String, bool>, std::less<>>;
Columns table_columns(Memory r, sqlite3& db, std::string_view table) {
Columns columns(r);
Statement s(r, db, pragma(r, "table_info", table));
while (s.next()) {
auto notnull = s.integer(3), pk = s.integer(5);
bool nullable = !(notnull != 0 || pk != 0);
auto name = sqlite_identifier_lower(r, s.text(1));
auto type = s.text(2);
columns.insert_or_assign(std::move(name), std::pair(std::move(type), nullable));
}
return columns;
}
void required_column(Memory r,
sqlite3& db,
const EntityDescriptor& e,
const PropertyDescriptor& p) {
if (p.nullable) {
return;
}
String sql("SELECT EXISTS(SELECT 1 FROM ", r);
sql += quote_identifier_if_needed(r, e.table_name, '"');
sql += " LIMIT 1)";
Statement s(r, db, sql);
s.next();
if (!s.integer(0)) {
return;
}
String message(
"ensure schema cannot add required column without a deterministic backfill: entity=", r);
message += e.name;
message += ", table=";
message += e.table_name;
message += ", column=";
message += p.column_name;
message += "; the table contains rows, so migrate/backfill explicitly before retrying";
throw MutationExecutorError::bind(r, message);
}
struct ForeignKeyRow {
using allocator_type = Allocator;
std::int64_t id, seq;
String column, table, target, update, remove;
ForeignKeyRow(std::allocator_arg_t, Allocator a, Statement& s)
: id(s.integer(0)), seq(s.integer(1)), column(s.text(3), a.resource()),
table(s.text(2), a.resource()), target(s.text(4), a.resource()),
update(s.text(5), a.resource()), remove(s.text(6), a.resource()) {}
ForeignKeyRow(std::allocator_arg_t, Allocator a, ForeignKeyRow&& other)
: id(other.id), seq(other.seq), column(std::move(other.column), a.resource()),
table(std::move(other.table), a.resource()),
target(std::move(other.target), a.resource()),
update(std::move(other.update), a.resource()),
remove(std::move(other.remove), a.resource()) {}
ForeignKeyRow(const ForeignKeyRow&) = delete;
ForeignKeyRow(ForeignKeyRow&&) noexcept = default;
};
void foreign_keys(Memory r, sqlite3& db, std::span<const EntityDescriptor* const> entities) {
for (auto* e : entities) {
auto expected = sqlite_foreign_keys_for(r, *e, entities);
if (expected.empty()) {
continue;
}
Vector<ForeignKeyRow> actual(r);
{
Statement s(r, db, pragma(r, "foreign_key_list", e->table_name));
while (s.next()) {
actual.emplace_back(s);
}
}
for (const auto& key : expected) {
bool found = false;
std::optional<String> incompatible;
for (const auto& candidate : actual) {
if (!ascii_equal(candidate.column, key[0]) ||
!ascii_equal(candidate.table, key[1]) ||
!ascii_equal(candidate.target, key[2])) {
continue;
}
found = true;
std::size_t count = 0;
for (const auto& row : actual) {
if (row.id == candidate.id) {
++count;
}
}
auto restricts = [](std::string_view action) {
return ascii_equal(action, "NO ACTION") || ascii_equal(action, "RESTRICT");
};
if (candidate.seq == 0 && count == 1 && restricts(candidate.update) &&
restricts(candidate.remove)) {
incompatible.reset();
break;
}
if (!incompatible) {
String message("ensure schema incompatible SQLite foreign-key shape: table=",
r);
message += e->table_name;
message += ", column=";
message += key[0];
message += ", referenced_table=";
message += key[1];
message += ", referenced_column=";
message += key[2];
message +=
", expected=one full-column key with RESTRICT actions, installed_fk_id=";
number(message, candidate.id);
message += ", installed_seq=";
number(message, candidate.seq);
message += ", installed_key_count=";
number(message, std::int64_t(count));
message += ", installed_update=";
message += candidate.update;
message += ", installed_delete=";
message += candidate.remove;
message += "; rebuild/migrate the table explicitly before retrying";
incompatible = std::move(message);
}
}
if (!found) {
String message(
"ensure schema cannot add missing SQLite foreign key in place: table=", r);
message += e->table_name;
message += ", column=";
message += key[0];
message += ", referenced_table=";
message += key[1];
message += ", referenced_column=";
message += key[2];
message += "; rebuild/migrate the table explicitly before retrying";
throw MutationExecutorError::bind(r, message);
}
if (incompatible) {
throw MutationExecutorError::bind(r, *incompatible);
}
}
}
}
void index_shapes(Memory r, sqlite3& db, const EntityDescriptor& e) {
auto table = strip_sqlite_identifier_quotes(e.table_name);
for (const auto& spec : schema_index_specs(r, e, std::nullopt)) {
std::optional<String> installed;
{
Statement s(r, db, "SELECT tbl_name FROM sqlite_master WHERE type='index' AND name=?1");
s.bind(spec.name);
if (s.next()) {
installed = s.text(0);
}
}
if (!installed) {
String message("SQLite declared index missing: table=", r);
message += table;
message += " index=";
message += spec.name;
throw MutationExecutorError::bind(r, message);
}
String flags("None", r);
bool flags_match = false;
{
Statement s(r, db, pragma(r, "index_list", table));
while (s.next()) {
auto name = s.text(1);
auto unique = s.integer(2), partial = s.integer(4);
if (name != spec.name || flags != "None") {
continue;
}
flags = "Some((";
flags += debug_text(r, name);
flags += ", ";
number(flags, unique);
flags += ", ";
number(flags, partial);
flags += "))";
flags_match = unique == std::int64_t(spec.unique) && partial == 0;
}
}
bool keys_match = true;
std::size_t count = 0;
String keys("[", r);
{
Statement s(r, db, pragma(r, "index_xinfo", spec.name));
while (s.next()) {
auto seq = s.integer(0), cid = s.integer(1);
auto name = s.optional_text(2);
auto desc = s.integer(3);
auto collation = s.text(4);
auto key = s.integer(5);
if (key != 1) {
continue;
}
if (count) {
keys += ", ";
}
keys += '(';
number(keys, seq);
keys += ", ";
number(keys, cid);
keys += ", ";
if (name) {
keys += "Some(";
keys += debug_text(r, *name);
keys += ')';
} else {
keys += "None";
}
keys += ", ";
number(keys, desc);
keys += ", ";
keys += debug_text(r, collation);
keys += ", ";
number(keys, key);
keys += ')';
keys_match =
keys_match && count < spec.columns.size() && cid >= 0 && name &&
ascii_equal(*name, strip_sqlite_identifier_quotes(spec.columns[count])) &&
desc == 0 && ascii_equal(collation, "BINARY");
++count;
}
}
keys += ']';
keys_match = keys_match && count == spec.columns.size();
if (!ascii_equal(*installed, table) || !flags_match || !keys_match) {
String message("SQLite declared index shape mismatch: table=", r);
message += table;
message += " index=";
message += spec.name;
message += "; expected=";
message += spec.unique ? "unique" : "non-unique";
message += " on (";
bool first = true;
for (const auto& column : spec.columns) {
if (!first) {
message += ", ";
}
first = false;
message += column;
}
message += ") with ascending BINARY full-column keys; installed table=";
message += *installed;
message += ", flags=";
message += flags;
message += ", keys=";
message += keys;
message += "; drop/rename the colliding index or migrate the table explicitly";
throw MutationExecutorError::bind(r, message);
}
}
}
void soundex_callback(sqlite3_context* context, int, sqlite3_value** values) noexcept {
std::optional<std::string_view> input;
if (sqlite3_value_type(values[0]) == SQLITE_TEXT) {
auto* text = reinterpret_cast<const char*>(sqlite3_value_text(values[0]));
if (text) {
std::string_view value(text, std::size_t(sqlite3_value_bytes(values[0])));
if (sqlite_schema_utf8_valid(value)) {
input = value;
}
}
}
auto result = sqlite_compatible_soundex(input);
sqlite3_result_text(context, result.data(), int(result.size()), SQLITE_TRANSIENT);
}
void rollback(Memory r, sqlite3& db) noexcept {
try {
execute(r, db, "ROLLBACK");
} catch (...) {
}
}
}
bool sqlite_table_exists(Memory r, sqlite3& db, std::string_view table) {
return table_exists(r, db, table);
}
SqliteTableColumns sqlite_table_columns(Memory r, sqlite3& db, std::string_view table) {
return table_columns(r, db, table);
}
namespace {
String lower_ascii(Memory memory, std::string_view text) {
String result(text, memory);
for (auto& character : result) {
if (character >= 'A' && character <= 'Z') {
character = static_cast<char>(character + ('a' - 'A'));
}
}
return result;
}
Vector<String> schema_tokens(Memory memory, std::string_view sql) {
Vector<String> tokens(memory);
std::size_t position = 0;
auto word = [](unsigned char character) {
return (character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z') ||
(character >= '0' && character <= '9') || character == '_' || character == '$' ||
character >= 0x80;
};
while (position < sql.size()) {
const auto character = static_cast<unsigned char>(sql[position]);
if (character == ' ' || (character >= '\t' && character <= '\r')) {
++position;
} else if (sql.substr(position, 2) == "--") {
position += 2;
while (position < sql.size() && sql[position] != '\n') {
++position;
}
} else if (sql.substr(position, 2) == "/*") {
const auto end = sql.find("*/", position + 2);
position = end == sql.npos ? sql.size() : end + 2;
} else if (character == '\'' || character == '"' || character == '`' || character == '[') {
const char close = character == '[' ? ']' : static_cast<char>(character);
++position;
String value(memory);
while (position < sql.size()) {
const auto current = sql[position++];
if (current == close) {
if (position < sql.size() && sql[position] == close) {
value += close;
++position;
continue;
}
break;
}
value += current;
}
tokens.emplace_back(character == '\'' ? String("<sql-string>", memory)
: lower_ascii(memory, value));
} else if (word(character)) {
const auto start = position++;
while (position < sql.size() && word(static_cast<unsigned char>(sql[position]))) {
++position;
}
tokens.emplace_back(lower_ascii(memory, sql.substr(start, position - start)));
} else {
tokens.emplace_back(1, static_cast<char>(character));
++position;
}
}
return tokens;
}
bool has_decimal_check(Memory memory, std::string_view ddl, std::string_view column) {
const auto tokens = schema_tokens(memory, ddl);
auto first = std::find(tokens.begin(), tokens.end(), "(");
if (first == tokens.end()) {
return false;
}
std::array<std::string_view, 11> required{
"check", "(", column, "is", "null", "or", "teaql_decimal_valid", "(", column, ")", ")"};
auto column_valid = [&](auto begin, auto end) {
if (end - begin < 2 || *begin != column || *(begin + 1) != "decimal_text") {
return false;
}
unsigned depth = 0;
for (auto token = begin; token != end; ++token) {
if (depth == 0 && *token == "check" &&
static_cast<std::size_t>(end - token) >= required.size() &&
std::equal(required.begin(), required.end(), token)) {
return true;
}
if (*token == "(") {
++depth;
} else if (*token == ")" && depth) {
--depth;
}
}
return false;
};
auto begin = first + 1;
unsigned depth = 1;
for (auto token = begin; token != tokens.end(); ++token) {
if (*token == "(") {
++depth;
} else if (*token == ")") {
if (--depth == 0) {
return column_valid(begin, token);
}
} else if (*token == "," && depth == 1) {
if (column_valid(begin, token)) {
return true;
}
begin = token + 1;
}
}
return false;
}
[[noreturn]] void invalid_decimal_schema(Memory memory,
const EntityDescriptor& entity,
const PropertyDescriptor& property,
std::string_view reason) {
String message("ensure schema Decimal column lacks ", memory);
message.append(reason)
.append(": entity=")
.append(entity.name)
.append(", table=")
.append(entity.table_name)
.append(", column=")
.append(property.column_name)
.append("; migrate the column explicitly before retrying");
throw MutationExecutorError::bind(memory, message);
}
void decimal_storage(Memory memory, sqlite3& connection, const EntityDescriptor& entity) {
for (const auto& property : entity.properties) {
if (property.data_type != DataType::Decimal) {
continue;
}
String sql("EXPLAIN SELECT 1 FROM ", memory);
sql.append(quote_identifier_if_needed(memory, entity.table_name, '"'))
.append(" NOT INDEXED WHERE ")
.append(quote_identifier_if_needed(memory, property.column_name, '"'))
.append(" = ?1");
Statement program(memory, connection, sql);
program.bind("0");
bool correct = false;
while (program.next()) {
const auto opcode = program.text(1);
const auto collation = program.optional_text(5);
if ((opcode == "Eq" || opcode == "Ne") && collation &&
collation->starts_with("TEAQL_DECIMAL")) {
correct = true;
}
}
if (!correct) {
invalid_decimal_schema(memory, entity, property, "TEAQL_DECIMAL collation");
}
Statement declaration(
memory, connection, "SELECT sql FROM sqlite_master WHERE type='table' AND name=?1");
declaration.bind(entity.table_name);
if (!declaration.next()) {
throw MutationExecutorError::sqlite(memory,
SqliteDriverError::query_returned_no_rows(memory));
}
const auto ddl = declaration.text(0);
const auto column =
lower_ascii(memory, strip_sqlite_identifier_quotes(property.column_name));
if (!has_decimal_check(memory, ddl, column)) {
invalid_decimal_schema(memory, entity, property, "required Decimal validation");
}
}
}
}
void ensure_sqlite_physical_schema(Memory r,
sqlite3& db,
const SqliteDialect& dialect,
std::span<const EntityDescriptor* const> entities,
std::span<const EntityDescriptor* const> logical_entities,
const UserContext& context) {
auto code = sqlite3_create_function_v2(&db,
"soundex",
1,
SQLITE_UTF8 | SQLITE_DETERMINISTIC,
nullptr,
soundex_callback,
nullptr,
nullptr,
nullptr);
if (code != SQLITE_OK) {
throw error(r, db, code);
}
execute(r, db, "PRAGMA foreign_keys = true");
execute(r, db, "BEGIN IMMEDIATE");
try {
for (const auto* entity : logical_entities) {
const auto* current = entity;
while (current->joined_parent) {
if (table_exists(r, db, current->table_name)) {
const auto columns = table_columns(r, db, current->table_name);
Vector<std::string_view> names(r);
for (const auto& [name, shape] : columns) {
(void)shape;
names.push_back(name);
}
validate_inherited_storage_columns(r, *current, names);
}
current = current->joined_parent.get();
}
}
execute(
r,
db,
"CREATE TABLE IF NOT EXISTS teaql_id_space (type_name VARCHAR(100) PRIMARY KEY, current_level BIGINT NOT NULL)");
for (auto* entity : entities) {
if (!table_exists(r, db, entity->table_name)) {
execute(r, db, compile_sqlite_create_table(r, dialect, *entity, entities));
(void)context.send_event(RawAuditEvent::schema_created(
r, entity->name, entity->table_name, entity->properties.size()));
} else {
auto columns = table_columns(r, db, entity->table_name);
for (const auto& property : entity->properties) {
auto name = sqlite_identifier_lower(
r, strip_sqlite_identifier_quotes(property.column_name));
auto found = columns.find(name);
if (found != columns.end()) {
ensure_sqlite_column_compatibility(
r, *entity, property, found->second.first, found->second.second);
continue;
}
required_column(r, db, *entity, property);
execute(r, db, dialect.compile_add_column(r, *entity, property));
(void)context.send_event(RawAuditEvent::field_added(
r, entity->name, entity->table_name, property.column_name));
}
}
for (const auto& sql : dialect.schema_indexes_sqls(r, *entity)) {
execute(r, db, sql);
}
decimal_storage(r, db, *entity);
index_shapes(r, db, *entity);
(void)context.send_event(RawAuditEvent::schema_verified(
r, entity->name, entity->table_name, entity->properties.size()));
}
foreign_keys(r, db, entities);
} catch (SqlCompileError& e) {
rollback(r, db);
throw MutationExecutorError::sql_compile(r, std::move(e));
} catch (MutationExecutorError&) {
rollback(r, db);
throw;
}
try {
execute(r, db, "COMMIT");
} catch (MutationExecutorError&) {
rollback(r, db);
throw;
}
}
}