39 if (!sql_foreign_keys.
Execute())
50 "CREATE TABLE tags (name TEXT, hash TEXT, revision INTEGER, "
51 " timestamp INTEGER, channel INTEGER, description TEXT, size "
53 " branch TEXT, CONSTRAINT pk_tags PRIMARY KEY (name), "
54 " FOREIGN KEY (branch) REFERENCES branches (branch));")
62 "CREATE TABLE recycle_bin (hash TEXT, flags INTEGER, "
63 " CONSTRAINT pk_hash PRIMARY KEY (hash))")
72 "CREATE TABLE branches (branch TEXT, parent TEXT, "
73 "initial_revision INTEGER,"
74 " CONSTRAINT pk_branch PRIMARY KEY (branch), "
75 " FOREIGN KEY (parent) REFERENCES branches (branch), "
76 " CHECK ((branch <> '') OR (parent IS NULL)), "
77 " CHECK ((branch = '') OR (parent IS NOT NULL)));");
78 bool retval = sql_create.
Execute();
84 "INSERT INTO branches (branch, parent, initial_revision) "
85 "VALUES ('', NULL, 0);");
113 if (!sql_foreign_keys.
Execute())
120 "upgrading history schema revision "
121 "%.2f (Rev: %d) to %.2f (Rev: %d)",
176 "ALTER TABLE tags ADD branch TEXT REFERENCES branches (branch);");
202 #define DB_FIELDS_V1R0 \
203 "name, hash, revision, timestamp, channel, " \
205 #define DB_FIELDS_V1R1 \
206 "name, hash, revision, timestamp, channel, " \
207 "description, size, ''"
208 #define DB_FIELDS_V1R3 \
209 "name, hash, revision, timestamp, channel, " \
210 "description, size, branch"
211 #define DB_PLACEHOLDERS \
212 ":name, :hash, :revision, :timestamp, :channel, " \
213 ":description, :size, :branch"
214 #define ROLLBACK_COND \
215 "(revision > :target_rev OR " \
216 " name = :target_name) " \
219 #define MAKE_STATEMENT(STMT_TMPL, REV) \
220 static const std::string REV = ReplaceAll( \
221 ReplaceAll(ReplaceAll(STMT_TMPL, "@DB_FIELDS@", DB_FIELDS_##REV), \
222 "@DB_PLACEHOLDERS@", DB_PLACEHOLDERS), \
223 "@ROLLBACK_COND@", ROLLBACK_COND)
225 #define MAKE_STATEMENTS(STMT_TMPL) \
226 MAKE_STATEMENT(STMT_TMPL, V1R0); \
227 MAKE_STATEMENT(STMT_TMPL, V1R1); \
228 MAKE_STATEMENT(STMT_TMPL, V1R3)
230 #define DEFERRED_INIT(DB, REV) DeferredInit((DB)->sqlite_db(), (REV).c_str())
232 #define DEFERRED_INITS(DB) \
233 if ((DB)->IsEqualSchema((DB)->schema_version(), 1.0f) \
234 && (DB)->schema_revision() == 0) { \
235 DEFERRED_INIT((DB), V1R0); \
236 } else if ((DB)->schema_revision() < 3) { \
237 DEFERRED_INIT((DB), V1R1); \
239 DEFERRED_INIT((DB), V1R3); \
243 MAKE_STATEMENTS(
"INSERT INTO tags (@DB_FIELDS@) VALUES (@DB_PLACEHOLDERS@);");
293 "WHERE (branch = '') AND (timestamp <= :timestamp) "
294 "ORDER BY revision DESC LIMIT 1;");
310 "WHERE (branch = :branch) "
311 "ORDER BY revision DESC LIMIT 1;");
330 return static_cast<uint64_t
>(count);
339 "SELECT @DB_FIELDS@ FROM tags ORDER BY timestamp DESC, revision DESC;");
349 "ORDER BY timestamp, revision ASC");
372 "WHERE @ROLLBACK_COND@ "
373 "ORDER BY revision DESC;");
386 "SELECT branch, parent, initial_revision FROM branches;");
392 const std::string parent =
404 "INSERT INTO branches (branch, parent, initial_revision) "
405 "VALUES (:branch, :parent, :initial_revision);");
bool BindTimestamp(const time_t timestamp)
static const float kLatestSchema
bool BindTextTransient(const int index, const std::string &value)
unsigned RetrieveCount() const
SqlFindTag(const HistoryDatabase *database)
bool CreateEmptyDatabase()
bool BindText(const int index, const std::string &value)
bool CheckSchema(const HistoryDatabase *database) const
static const float kLatestSupportedSchema
bool CheckSchemaCompatibility()
bool CreateRecycleBinTable()
std::string ToString(const bool with_suffix=false) const
SqlFindTagByDate(const HistoryDatabase *database)
const history::History * history() const
shash::Any RetrieveHash() const
assert((mem||(size==0))&&"Out Of Memory")
SqlInsertTag(const HistoryDatabase *database)
bool UpgradeSchemaRevision_10_1()
float schema_version() const
SqlCountTags(const HistoryDatabase *database)
SqlListRollbackTags(const HistoryDatabase *database)
void set_schema_revision(const unsigned rev)
unsigned schema_revision() const
SqlFindBranchHead(const HistoryDatabase *database)
bool InsertInitialValues(const std::string &repository_name)
bool BindBranchName(const std::string &branch_name)
void DeferredInit(const sqlite3 *database, const char *statement)
SqlRecycleBinFlush(const HistoryDatabase *database)
static const float kSchemaEpsilon
static const unsigned int kFlagCatalog
bool BindName(const std::string &name)
const char kSuffixCatalog
bool BindTag(const History::Tag &tag)
SqlListTags(const HistoryDatabase *database)
sqlite3_int64 RetrieveInt64(const int idx_column) const
#define MAKE_STATEMENTS(STMT_TMPL)
sqlite3 * sqlite_db() const
bool BindBranch(const History::Branch &branch)
bool BindInt64(const int index, const sqlite3_int64 value)
bool SetProperty(const std::string &key, const T value)
SqlInsertBranch(const HistoryDatabase *database)
static const unsigned kLatestSchemaRevision
shash::Any RetrieveHash()
bool LiveSchemaUpgradeIfNecessary()
bool IsEqualSchema(const float value, const float compare) const
SqlGetHashes(const HistoryDatabase *database)
std::string RetrieveString(const int idx_column) const
static const std::string kFqrnKey
bool BindName(const std::string &name)
int RetrieveType(const int idx_column) const
bool UpgradeSchemaRevision_10_2()
uint64_t initial_revision
Any MkFromHexPtr(const HexPtr hex, const char suffix)
SqlRemoveTag(const HistoryDatabase *database)
bool ContainsRecycleBin() const
#define DEFERRED_INITS(DB)
bool CreateBranchesTable()
bool StoreSchemaRevision()
History::Branch RetrieveBranch() const
SqlRecycleBinList(const HistoryDatabase *database)
SqlRollbackTag(const HistoryDatabase *database)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
bool UpgradeSchemaRevision_10_3()
SqlListBranches(const HistoryDatabase *database)