static const string::size_type kUpdateStatementBufferSize = 2048;
// Increment this version whenever updating DB tables.
-const int32 kCurrentDBVersion = 86;
+const int32 kCurrentDBVersion = 88;
// Iterate over the fields of |entry| and bind each to |statement| for
// updating. Returns the number of args bound.
entry.ref(static_cast<UniquePositionField>(i)).SerializeToString(&temp);
statement->BindBlob(index++, temp.data(), temp.length());
}
+ for (; i < ATTACHMENT_METADATA_FIELDS_END; ++i) {
+ std::string temp;
+ entry.ref(static_cast<AttachmentMetadataField>(i)).SerializeToString(&temp);
+ statement->BindBlob(index++, temp.data(), temp.length());
+ }
}
// The caller owns the returned EntryKernel*. Assumes the statement currently
kernel->mutable_ref(static_cast<UniquePositionField>(i)) =
UniquePosition::FromProto(proto);
}
+ for (; i < ATTACHMENT_METADATA_FIELDS_END; ++i) {
+ kernel->mutable_ref(static_cast<AttachmentMetadataField>(i)).ParseFromArray(
+ statement->ColumnBlob(i), statement->ColumnByteLength(i));
+ }
return kernel.Pass();
}
sql::Statement s2(db_->GetCachedStatement(
SQL_FROM_HERE,
"INSERT OR REPLACE "
- "INTO models (model_id, progress_marker, transaction_version) "
- "VALUES (?, ?, ?)"));
+ "INTO models (model_id, "
+ "progress_marker, "
+ "transaction_version, "
+ "context) "
+ "VALUES (?, ?, ?, ?)"));
ModelTypeSet protocol_types = ProtocolTypes();
for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
s2.BindBlob(0, model_id.data(), model_id.length());
s2.BindBlob(1, progress_marker.data(), progress_marker.length());
s2.BindInt64(2, info.transaction_version[type]);
+ string context;
+ info.datatype_context[type].SerializeToString(&context);
+ s2.BindBlob(3, context.data(), context.length());
if (!s2.Run())
return false;
DCHECK_EQ(db_->GetLastChangeCount(), 1);
version_on_disk = 86;
}
+ // Version 87 migration adds a collection of attachment ids per sync entry.
+ if (version_on_disk == 86) {
+ if (MigrateVersion86To87())
+ version_on_disk = 87;
+ }
+
+ // Version 88 migration adds datatype contexts to the models table.
+ if (version_on_disk == 87) {
+ if (MigrateVersion87To88())
+ version_on_disk = 88;
+ }
+
// If one of the migrations requested it, drop columns that aren't current.
// It's only safe to do this after migrating all the way to the current
// version.
sql::Statement s(
db_->GetUniqueStatement(
"SELECT model_id, progress_marker, "
- "transaction_version FROM models"));
+ "transaction_version, context FROM models"));
while (s.Step()) {
ModelType type = ModelIdToModelTypeEnum(s.ColumnBlob(0),
info->kernel_info.download_progress[type].ParseFromArray(
s.ColumnBlob(1), s.ColumnByteLength(1));
info->kernel_info.transaction_version[type] = s.ColumnInt64(2);
+ info->kernel_info.datatype_context[type].ParseFromArray(
+ s.ColumnBlob(3), s.ColumnByteLength(3));
}
}
if (!s.Succeeded())
// Version 85 removes the initial_sync_ended flag.
if (!db_->Execute("ALTER TABLE models RENAME TO temp_models"))
return false;
- if (!CreateModelsTable())
+ if (!CreateV81ModelsTable())
return false;
if (!db_->Execute("INSERT INTO models SELECT "
"model_id, progress_marker, transaction_version "
return true;
}
+bool DirectoryBackingStore::MigrateVersion86To87() {
+ // Version 87 adds AttachmentMetadata proto.
+ if (!db_->Execute(
+ "ALTER TABLE metas ADD COLUMN "
+ "attachment_metadata BLOB")) {
+ return false;
+ }
+ SetVersion(87);
+ needs_column_refresh_ = true;
+ return true;
+}
+
+bool DirectoryBackingStore::MigrateVersion87To88() {
+ // Version 88 adds the datatype context to the models table.
+ if (!db_->Execute("ALTER TABLE models ADD COLUMN context blob"))
+ return false;
+
+ SetVersion(88);
+ return true;
+}
+
bool DirectoryBackingStore::CreateTables() {
DVLOG(1) << "First run, creating tables";
// Create two little tables share_version and share_info
"initial_sync_ended BOOLEAN default 0)");
}
+bool DirectoryBackingStore::CreateV81ModelsTable() {
+ // This is an old schema for the Models table, used from versions 81 to 87.
+ return db_->Execute(
+ "CREATE TABLE models ("
+ "model_id BLOB primary key, "
+ "progress_marker BLOB, "
+ // Gets set if the syncer ever gets updates from the
+ // server and the server returns 0. Lets us detect the
+ // end of the initial sync.
+ "transaction_version BIGINT default 0)");
+}
+
bool DirectoryBackingStore::CreateModelsTable() {
- // This is the current schema for the Models table, from version 81
+ // This is the current schema for the Models table, from version 88
// onward. If you change the schema, you'll probably want to double-check
// the use of this function in the v84-v85 migration.
return db_->Execute(
// Gets set if the syncer ever gets updates from the
// server and the server returns 0. Lets us detect the
// end of the initial sync.
- "transaction_version BIGINT default 0)");
+ "transaction_version BIGINT default 0,"
+ "context BLOB)");
}
bool DirectoryBackingStore::CreateShareInfoTable(bool is_temporary) {