Tidy up SQLite table creation:

* Check if tables and indexes exist
* Remove commands for unused table
This commit is contained in:
seelabs
2015-04-21 10:40:40 -07:00
committed by Vinnie Falco
parent 6a0c26a709
commit d2cba1c54f

View File

@@ -36,7 +36,7 @@ const char* TxnDBInit[] =
"BEGIN TRANSACTION;",
"CREATE TABLE Transactions ( \
"CREATE TABLE IF NOT EXISTS Transactions ( \
TransID CHARACTER(64) PRIMARY KEY, \
TransType CHARACTER(24), \
FromAcct CHARACTER(35), \
@@ -46,20 +46,20 @@ const char* TxnDBInit[] =
RawTxn BLOB, \
TxnMeta BLOB \
);",
"CREATE INDEX TxLgrIndex ON \
"CREATE INDEX IF NOT EXISTS TxLgrIndex ON \
Transactions(LedgerSeq);",
"CREATE TABLE AccountTransactions ( \
"CREATE TABLE IF NOT EXISTS AccountTransactions ( \
TransID CHARACTER(64), \
Account CHARACTER(64), \
LedgerSeq BIGINT UNSIGNED, \
TxnSeq INTEGER \
);",
"CREATE INDEX AcctTxIDIndex ON \
"CREATE INDEX IF NOT EXISTS AcctTxIDIndex ON \
AccountTransactions(TransID);",
"CREATE INDEX AcctTxIndex ON \
"CREATE INDEX IF NOT EXISTS AcctTxIndex ON \
AccountTransactions(Account, LedgerSeq, TxnSeq, TransID);",
"CREATE INDEX AcctLgrIndex ON \
"CREATE INDEX IF NOT EXISTS AcctLgrIndex ON \
AccountTransactions(LedgerSeq, Account, TransID);",
"END TRANSACTION;"
@@ -76,7 +76,7 @@ const char* LedgerDBInit[] =
"BEGIN TRANSACTION;",
"CREATE TABLE Ledgers ( \
"CREATE TABLE IF NOT EXISTS Ledgers ( \
LedgerHash CHARACTER(64) PRIMARY KEY, \
LedgerSeq BIGINT UNSIGNED, \
PrevHash CHARACTER(64), \
@@ -88,17 +88,17 @@ const char* LedgerDBInit[] =
AccountSetHash CHARACTER(64), \
TransSetHash CHARACTER(64) \
);",
"CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);",
"CREATE INDEX IF NOT EXISTS SeqLedger ON Ledgers(LedgerSeq);",
"CREATE TABLE Validations ( \
"CREATE TABLE IF NOT EXISTS Validations ( \
LedgerHash CHARACTER(64), \
NodePubKey CHARACTER(56), \
SignTime BIGINT UNSIGNED, \
RawData BLOB \
);",
"CREATE INDEX ValidationsByHash ON \
"CREATE INDEX IF NOT EXISTS ValidationsByHash ON \
Validations(LedgerHash);",
"CREATE INDEX ValidationsByTime ON \
"CREATE INDEX IF NOT EXISTS ValidationsByTime ON \
Validations(SignTime);",
"END TRANSACTION;"
@@ -111,7 +111,7 @@ const char* RpcDBInit[] =
{
// Local persistence of the RPC client
"CREATE TABLE RPCData ( \
"CREATE TABLE IF NOT EXISTS RPCData ( \
Key TEXT PRIMARY Key, \
Value TEXT \
);",
@@ -127,7 +127,7 @@ const char* WalletDBInit[] =
// Node identity must be persisted for CAS routing and responsibilities.
"BEGIN TRANSACTION;",
"CREATE TABLE NodeIdentity ( \
"CREATE TABLE IF NOT EXISTS NodeIdentity ( \
PublicKey CHARACTER(53), \
PrivateKey CHARACTER(52), \
Dh512 TEXT, \
@@ -138,7 +138,7 @@ const char* WalletDBInit[] =
// Integer: 1 : Used to simplify SQL.
// ScoreUpdated: when scores was last updated.
// FetchUpdated: when last fetch succeeded.
"CREATE TABLE Misc ( \
"CREATE TABLE IF NOT EXISTS Misc ( \
Magic INTEGER UNIQUE NOT NULL, \
ScoreUpdated DATETIME, \
FetchUpdated DATETIME \
@@ -167,7 +167,7 @@ const char* WalletDBInit[] =
// Comment:
// User supplied comment.
// Table of Domains user has asked to trust.
"CREATE TABLE SeedDomains ( \
"CREATE TABLE IF NOT EXISTS SeedDomains ( \
Domain TEXT PRIMARY KEY NOT NULL, \
PublicKey CHARACTER(53), \
Source CHARACTER(1) NOT NULL, \
@@ -179,7 +179,7 @@ const char* WalletDBInit[] =
);",
// Allow us to easily find the next SeedDomain to fetch.
"CREATE INDEX SeedDomainNext ON SeedDomains (Next);",
"CREATE INDEX IF NOT EXISTS SeedDomainNext ON SeedDomains (Next);",
// Table of PublicKeys user has asked to trust.
// Fetches are made to the CAS. This gets the ripple.txt so even validators
@@ -199,7 +199,7 @@ const char* WalletDBInit[] =
// Checksum of last fetch.
// Comment:
// User supplied comment.
"CREATE TABLE SeedNodes ( \
"CREATE TABLE IF NOT EXISTS SeedNodes ( \
PublicKey CHARACTER(53) PRIMARY KEY NOT NULL, \
Source CHARACTER(1) NOT NULL, \
Next DATETIME, \
@@ -210,7 +210,7 @@ const char* WalletDBInit[] =
);",
// Allow us to easily find the next SeedNode to fetch.
"CREATE INDEX SeedNodeNext ON SeedNodes (Next);",
"CREATE INDEX IF NOT EXISTS SeedNodeNext ON SeedNodes (Next);",
// Nodes we trust to not grossly collude against us. Derived from
// SeedDomains, SeedNodes, and ValidatorReferrals.
@@ -219,7 +219,7 @@ const char* WalletDBInit[] =
// Computed trust score. Higher is better.
// Seen:
// Last validation received.
"CREATE TABLE TrustedNodes ( \
"CREATE TABLE IF NOT EXISTS TrustedNodes ( \
PublicKey CHARACTER(53) PRIMARY KEY NOT NULL, \
Score INTEGER DEFAULT 0 NOT NULL, \
Seen DATETIME, \
@@ -237,7 +237,7 @@ const char* WalletDBInit[] =
// - Public key for CAS based referral.
// - Domain for domain based referral.
// XXX Do garbage collection when validators have no references.
"CREATE TABLE ValidatorReferrals ( \
"CREATE TABLE IF NOT EXISTS ValidatorReferrals (\
Validator CHARACTER(53) NOT NULL, \
Entry INTEGER NOT NULL, \
Referral TEXT NOT NULL, \
@@ -254,7 +254,7 @@ const char* WalletDBInit[] =
// Port:
// -1 = Default
// XXX Do garbage collection when ips have no references.
"CREATE TABLE IpReferrals ( \
"CREATE TABLE IF NOT EXISTS IpReferrals ( \
Validator CHARACTER(53) NOT NULL, \
Entry INTEGER NOT NULL, \
IP TEXT NOT NULL, \
@@ -262,18 +262,12 @@ const char* WalletDBInit[] =
PRIMARY KEY (Validator,Entry) \
);",
"CREATE TABLE Features ( \
"CREATE TABLE IF NOT EXISTS Features ( \
Hash CHARACTER(64) PRIMARY KEY, \
FirstMajority BIGINT UNSIGNED, \
LastMajority BIGINT UNSIGNED \
);",
// This removes an old table and its index which are now redundant. This
// code will eventually go away. It's only here to clean up the wallet.db
"DROP TABLE IF EXISTS PeerIps;",
"DROP INDEX IF EXISTS;",
"END TRANSACTION;"
};