diff --git a/src/ledger/LedgerTxnContractCodeSQL.cpp b/src/ledger/LedgerTxnContractCodeSQL.cpp index 54d0c46da9..c3bc17f736 100644 --- a/src/ledger/LedgerTxnContractCodeSQL.cpp +++ b/src/ledger/LedgerTxnContractCodeSQL.cpp @@ -364,17 +364,21 @@ LedgerTxnRoot::Impl::dropContractCode(bool rebuild) std::string coll = mApp.getDatabase().getSimpleCollationClause(); mApp.getDatabase().getSession() << "DROP TABLE IF EXISTS contractcode;"; - mApp.getDatabase().getSession() - << "CREATE TABLE contractcode (" - << "hash TEXT " << coll << " NOT NULL, " - << "ledgerentry TEXT " << coll << " NOT NULL, " - << "lastmodified INT NOT NULL, " - << "PRIMARY KEY (hash));"; - if (!mApp.getDatabase().isSqlite()) + + if (rebuild) { - mApp.getDatabase().getSession() << "ALTER TABLE contractcode " - << "ALTER COLUMN hash " - << "TYPE TEXT COLLATE \"C\";"; + mApp.getDatabase().getSession() + << "CREATE TABLE contractcode (" + << "hash TEXT " << coll << " NOT NULL, " + << "ledgerentry TEXT " << coll << " NOT NULL, " + << "lastmodified INT NOT NULL, " + << "PRIMARY KEY (hash));"; + if (!mApp.getDatabase().isSqlite()) + { + mApp.getDatabase().getSession() << "ALTER TABLE contractcode " + << "ALTER COLUMN hash " + << "TYPE TEXT COLLATE \"C\";"; + } } } diff --git a/src/ledger/LedgerTxnTTLSQL.cpp b/src/ledger/LedgerTxnTTLSQL.cpp index 3bde212373..abe5b44a0f 100644 --- a/src/ledger/LedgerTxnTTLSQL.cpp +++ b/src/ledger/LedgerTxnTTLSQL.cpp @@ -359,17 +359,21 @@ LedgerTxnRoot::Impl::dropTTL(bool rebuild) std::string coll = mApp.getDatabase().getSimpleCollationClause(); mApp.getDatabase().getSession() << "DROP TABLE IF EXISTS ttl;"; - mApp.getDatabase().getSession() - << "CREATE TABLE ttl (" - << "keyhash TEXT " << coll << " NOT NULL, " - << "ledgerentry TEXT " << coll << " NOT NULL, " - << "lastmodified INT NOT NULL, " - << "PRIMARY KEY (keyhash));"; - if (!mApp.getDatabase().isSqlite()) + + if (rebuild) { - mApp.getDatabase().getSession() << "ALTER TABLE ttl " - << "ALTER COLUMN keyhash " - << "TYPE TEXT COLLATE \"C\";"; + mApp.getDatabase().getSession() + << "CREATE TABLE ttl (" + << "keyhash TEXT " << coll << " NOT NULL, " + << "ledgerentry TEXT " << coll << " NOT NULL, " + << "lastmodified INT NOT NULL, " + << "PRIMARY KEY (keyhash));"; + if (!mApp.getDatabase().isSqlite()) + { + mApp.getDatabase().getSession() << "ALTER TABLE ttl " + << "ALTER COLUMN keyhash " + << "TYPE TEXT COLLATE \"C\";"; + } } } diff --git a/src/main/ApplicationImpl.cpp b/src/main/ApplicationImpl.cpp index a6f0ec3859..cef22bfc68 100644 --- a/src/main/ApplicationImpl.cpp +++ b/src/main/ApplicationImpl.cpp @@ -154,17 +154,17 @@ maybeRebuildLedger(Application& app, bool applyBuckets) auto bucketListDBEnabled = app.getConfig().isUsingBucketListDB(); for (auto let : xdr::xdr_traits::enum_values()) { + // If BucketListDB is enabled, drop all tables except for offers LedgerEntryType t = static_cast(let); - if (ps.shouldRebuildForType(t)) + if (let != OFFER && bucketListDBEnabled) { - toRebuild.emplace(t); + toDrop.emplace(t); continue; } - // If bucketlist is enabled, drop all tables except for offers - if (let != OFFER && bucketListDBEnabled) + if (ps.shouldRebuildForType(t)) { - toDrop.emplace(t); + toRebuild.emplace(t); } }