OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sync/syncable/directory_backing_store.h" | 5 #include "sync/syncable/directory_backing_store.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 using std::string; | 28 using std::string; |
29 | 29 |
30 namespace syncer { | 30 namespace syncer { |
31 namespace syncable { | 31 namespace syncable { |
32 | 32 |
33 // This just has to be big enough to hold an UPDATE or INSERT statement that | 33 // This just has to be big enough to hold an UPDATE or INSERT statement that |
34 // modifies all the columns in the entry table. | 34 // modifies all the columns in the entry table. |
35 static const string::size_type kUpdateStatementBufferSize = 2048; | 35 static const string::size_type kUpdateStatementBufferSize = 2048; |
36 | 36 |
37 // Increment this version whenever updating DB tables. | 37 // Increment this version whenever updating DB tables. |
38 const int32 kCurrentDBVersion = 88; | 38 const int32 kCurrentDBVersion = 89; |
39 | 39 |
40 // Iterate over the fields of |entry| and bind each to |statement| for | 40 // Iterate over the fields of |entry| and bind each to |statement| for |
41 // updating. Returns the number of args bound. | 41 // updating. Returns the number of args bound. |
42 void BindFields(const EntryKernel& entry, | 42 void BindFields(const EntryKernel& entry, |
43 sql::Statement* statement) { | 43 sql::Statement* statement) { |
44 int index = 0; | 44 int index = 0; |
45 int i = 0; | 45 int i = 0; |
46 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { | 46 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { |
47 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); | 47 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); |
48 } | 48 } |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 if (MigrateVersion86To87()) | 436 if (MigrateVersion86To87()) |
437 version_on_disk = 87; | 437 version_on_disk = 87; |
438 } | 438 } |
439 | 439 |
440 // Version 88 migration adds datatype contexts to the models table. | 440 // Version 88 migration adds datatype contexts to the models table. |
441 if (version_on_disk == 87) { | 441 if (version_on_disk == 87) { |
442 if (MigrateVersion87To88()) | 442 if (MigrateVersion87To88()) |
443 version_on_disk = 88; | 443 version_on_disk = 88; |
444 } | 444 } |
445 | 445 |
| 446 // Version 89 migration adds server attachment metadata to the metas table. |
| 447 if (version_on_disk == 88) { |
| 448 if (MigrateVersion88To89()) |
| 449 version_on_disk = 89; |
| 450 } |
| 451 |
446 // If one of the migrations requested it, drop columns that aren't current. | 452 // If one of the migrations requested it, drop columns that aren't current. |
447 // It's only safe to do this after migrating all the way to the current | 453 // It's only safe to do this after migrating all the way to the current |
448 // version. | 454 // version. |
449 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) { | 455 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) { |
450 if (!RefreshColumns()) | 456 if (!RefreshColumns()) |
451 version_on_disk = 0; | 457 version_on_disk = 0; |
452 } | 458 } |
453 | 459 |
454 // A final, alternative catch-all migration to simply re-sync everything. | 460 // A final, alternative catch-all migration to simply re-sync everything. |
455 if (version_on_disk != kCurrentDBVersion) { | 461 if (version_on_disk != kCurrentDBVersion) { |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 | 1325 |
1320 bool DirectoryBackingStore::MigrateVersion87To88() { | 1326 bool DirectoryBackingStore::MigrateVersion87To88() { |
1321 // Version 88 adds the datatype context to the models table. | 1327 // Version 88 adds the datatype context to the models table. |
1322 if (!db_->Execute("ALTER TABLE models ADD COLUMN context blob")) | 1328 if (!db_->Execute("ALTER TABLE models ADD COLUMN context blob")) |
1323 return false; | 1329 return false; |
1324 | 1330 |
1325 SetVersion(88); | 1331 SetVersion(88); |
1326 return true; | 1332 return true; |
1327 } | 1333 } |
1328 | 1334 |
| 1335 bool DirectoryBackingStore::MigrateVersion88To89() { |
| 1336 // Version 89 adds server_attachment_metadata. |
| 1337 if (!db_->Execute( |
| 1338 "ALTER TABLE metas ADD COLUMN " |
| 1339 "server_attachment_metadata BLOB")) { |
| 1340 return false; |
| 1341 } |
| 1342 SetVersion(89); |
| 1343 needs_column_refresh_ = true; |
| 1344 return true; |
| 1345 } |
| 1346 |
1329 bool DirectoryBackingStore::CreateTables() { | 1347 bool DirectoryBackingStore::CreateTables() { |
1330 DVLOG(1) << "First run, creating tables"; | 1348 DVLOG(1) << "First run, creating tables"; |
1331 // Create two little tables share_version and share_info | 1349 // Create two little tables share_version and share_info |
1332 if (!db_->Execute( | 1350 if (!db_->Execute( |
1333 "CREATE TABLE share_version (" | 1351 "CREATE TABLE share_version (" |
1334 "id VARCHAR(128) primary key, data INT)")) { | 1352 "id VARCHAR(128) primary key, data INT)")) { |
1335 return false; | 1353 return false; |
1336 } | 1354 } |
1337 | 1355 |
1338 { | 1356 { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 } | 1586 } |
1569 query.append(" ) "); | 1587 query.append(" ) "); |
1570 values.append(" )"); | 1588 values.append(" )"); |
1571 query.append(values); | 1589 query.append(values); |
1572 save_statement->Assign(db_->GetUniqueStatement( | 1590 save_statement->Assign(db_->GetUniqueStatement( |
1573 base::StringPrintf(query.c_str(), "metas").c_str())); | 1591 base::StringPrintf(query.c_str(), "metas").c_str())); |
1574 } | 1592 } |
1575 | 1593 |
1576 } // namespace syncable | 1594 } // namespace syncable |
1577 } // namespace syncer | 1595 } // namespace syncer |
OLD | NEW |