MCPcopy Create free account
hub / github.com/blizzard4591/openMittsu / createOrUpdateTables

Method createOrUpdateTables

src/database/SimpleDatabase.cpp:487–580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485 }
486
487 void SimpleDatabase::createOrUpdateTables() {
488 int versionTableVersions = createTableIfMissingAndGetVersion(Tables::TableVersions, 1);
489 int versionTableContacts = createTableIfMissingAndGetVersion(Tables::Contacts, 1);
490 int versionTableContactMessages = createTableIfMissingAndGetVersion(Tables::ContactMessages, 1);
491 int versionTableControlMessages = createTableIfMissingAndGetVersion(Tables::ControlMessages, 1);
492 int versionTableFeatureLevels = createTableIfMissingAndGetVersion(Tables::FeatureLevels, 1);
493 int versionTableGroups = createTableIfMissingAndGetVersion(Tables::Groups, 1);
494 int versionTableGroupMessages = createTableIfMissingAndGetVersion(Tables::GroupMessages, 1);
495 int versionTableMedia = createTableIfMissingAndGetVersion(Tables::Media, 3);
496 int versionTableSettings = createTableIfMissingAndGetVersion(Tables::Settings, 1);
497
498 if (versionTableVersions != 1) {
499 LOGGER()->warn("Table TableVersions has version {} instead of {}.", versionTableVersions, 1);
500 }
501 if (versionTableContacts != 1) {
502 LOGGER()->warn("Table Contacts has version {} instead of {}.", versionTableContacts, 1);
503 }
504 if (versionTableContactMessages != 1) {
505 LOGGER()->warn("Table ContactMessages has version {} instead of {}.", versionTableContactMessages, 1);
506 }
507 if (versionTableControlMessages != 1) {
508 LOGGER()->warn("Table ControlMessages has version {} instead of {}.", versionTableControlMessages, 1);
509 }
510 if (versionTableFeatureLevels != 1) {
511 LOGGER()->warn("Table FeatureLevels has version {} instead of {}.", versionTableFeatureLevels, 1);
512 }
513 if (versionTableGroups != 1) {
514 LOGGER()->warn("Table Groups has version {} instead of {}.", versionTableGroups, 1);
515 }
516 if (versionTableGroupMessages != 1) {
517 LOGGER()->warn("Table GroupMessages has version {} instead of {}.", versionTableGroupMessages, 1);
518 }
519 if (versionTableMedia != 3) {
520 LOGGER()->warn("Table Media has version {} instead of {}.", versionTableMedia, 3);
521
522 if (versionTableMedia == 1) {
523 // Update 1: Added `type` field to media table.
524 LOGGER()->info("Upgrading media database to file schema version 2...");
525 this->transactionStart();
526 QSqlQuery query(database);
527 QStringList const updateQueries = getUpdateStatementForTable(Tables::Media, 2);
528 auto it = updateQueries.constBegin();
529 auto const end = updateQueries.constEnd();
530 for (; it != end; ++it) {
531 LOGGER_DEBUG("Running part of update query: {}", it->toStdString());
532 if (!query.exec(*it)) {
533 throw openmittsu::exceptions::InternalErrorException() << "Could not update table 'media' to version 2. Query error: " << query.lastError().text().toStdString();
534 }
535 }
536 setTableVersion(Tables::Media, 2);
537 m_mediaFileStorage.upgradeMediaDatabase(1);
538 this->transactionCommit();
539 LOGGER()->info("Upgrading media database to file schema version 2... Done.");
540 } else if (versionTableMedia == 2) {
541 // Update 2: Creation of the tables was broken, everyone maybe needs this fix.
542 LOGGER()->info("Upgrading media database to file schema version 3...");
543 this->transactionStart();
544 QSqlQuery query(database);

Callers

nothing calls this directly

Calls 7

transactionStartMethod · 0.95
transactionCommitMethod · 0.95
upgradeMediaDatabaseMethod · 0.80
valueMethod · 0.80
containsMethod · 0.80
nextMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected