Skip to content

Commit

Permalink
make it easier to manage min/max schema versions
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsieurNicolas committed Aug 15, 2019
1 parent 17deb58 commit b36409a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/database/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ using namespace std;

bool Database::gDriversRegistered = false;

// smallest schema version supported
static unsigned long const MIN_SCHEMA_VERSION = 9;
static unsigned long const SCHEMA_VERSION = 10;

// These should always match our compiled version precisely, since we are
Expand Down Expand Up @@ -194,15 +196,7 @@ Database::applySchemaUpgrade(unsigned long vers)
mApp.getHerderPersistence().createQuorumTrackingTable(mSession);
break;
default:
if (vers <= 9)
{
throw std::runtime_error(
"Database version is too old, must use at least 10");
}
else
{
throw std::runtime_error("Unknown DB schema version");
}
throw std::runtime_error("Unknown DB schema version");
}
tx.commit();
}
Expand All @@ -211,6 +205,14 @@ void
Database::upgradeToCurrentSchema()
{
auto vers = getDBSchemaVersion();
if (vers < MIN_SCHEMA_VERSION)
{
std::string s = ("DB schema version " + std::to_string(vers) +
" is older than minimum supported schema " +
std::to_string(MIN_SCHEMA_VERSION));
throw std::runtime_error(s);
}

if (vers > SCHEMA_VERSION)
{
std::string s = ("DB schema version " + std::to_string(vers) +
Expand Down Expand Up @@ -374,7 +376,7 @@ Database::initialize()
HerderPersistence::dropAll(*this);
mApp.getLedgerTxnRoot().dropData();
BanManager::dropAll(*this);
putSchemaVersion(9);
putSchemaVersion(MIN_SCHEMA_VERSION);

LOG(INFO) << "* ";
LOG(INFO) << "* The database has been initialized";
Expand Down

5 comments on commit b36409a

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from marta-lokhova
at MonsieurNicolas@b36409a

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging MonsieurNicolas/stellar-core/squashDBschema10 = b36409a into auto

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MonsieurNicolas/stellar-core/squashDBschema10 = b36409a merged ok, testing candidate = c5fb1e3

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c5fb1e3

Please sign in to comment.