Index: components/offline_pages/offline_page_metadata_store_sql.cc |
diff --git a/components/offline_pages/offline_page_metadata_store_sql.cc b/components/offline_pages/offline_page_metadata_store_sql.cc |
index 93afcb30ad5c8c13231e1147ff692f840bbfbba1..2be42570a5220f6156c5d1a9e7df899ac252e846 100644 |
--- a/components/offline_pages/offline_page_metadata_store_sql.cc |
+++ b/components/offline_pages/offline_page_metadata_store_sql.cc |
@@ -38,7 +38,7 @@ const char kOfflinePagesColumns[] = |
// later use. We will treat NULL as "Unknown" in any subsequent queries |
// for user_initiated values. |
" user_initiated INTEGER," // this is actually a boolean |
- " expiration_time INTEGER NOT NULL," |
+ " expiration_time INTEGER NOT NULL DEFAULT 0," |
" client_namespace VARCHAR NOT NULL," |
" client_id VARCHAR NOT NULL," |
" online_url VARCHAR NOT NULL," |
@@ -81,14 +81,45 @@ bool CreateTable(sql::Connection* db, const TableInfo& table_info) { |
return db->Execute(sql.c_str()); |
} |
+bool RefreshColumns(sql::Connection* db) { |
+ if (!db->Execute("ALTER TABLE " OFFLINE_PAGES_TABLE_NAME |
+ " RENAME TO temp_" OFFLINE_PAGES_TABLE_NAME)) { |
+ return false; |
+ } |
+ if (!CreateTable(db, kOfflinePagesTable)) |
+ return false; |
+ if (!db->Execute( |
fgorski
2016/06/03 18:17:16
because you are actually doing the upgrade, could
romax
2016/06/03 19:36:22
Done.
|
+ "INSERT INTO " OFFLINE_PAGES_TABLE_NAME |
+ " (offline_id, creation_time, file_size, version, last_access_time, " |
+ "access_count, status, user_initiated, client_namespace, client_id, " |
+ "online_url, offline_url, file_path) " |
+ "SELECT offline_id, creation_time, file_size, version, " |
+ "last_access_time, " |
+ "access_count, status, user_initiated, client_namespace, client_id, " |
+ "online_url, offline_url, file_path " |
+ "FROM temp_" OFFLINE_PAGES_TABLE_NAME)) { |
+ return false; |
+ } |
+ if (!db->Execute("DROP TABLE IF EXISTS temp_" OFFLINE_PAGES_TABLE_NAME)) |
+ return false; |
+ |
+ return true; |
+} |
+ |
bool CreateSchema(sql::Connection* db) { |
// If you create a transaction but don't Commit() it is automatically |
// rolled back by its destructor when it falls out of scope. |
sql::Transaction transaction(db); |
if (!transaction.Begin()) |
return false; |
- if (db->DoesTableExist(kOfflinePagesTable.table_name)) |
+ if (db->DoesTableExist(kOfflinePagesTable.table_name)) { |
+ if (!db->DoesColumnExist(OFFLINE_PAGES_TABLE_NAME, "expiration_time")) { |
+ if (!RefreshColumns(db)) |
+ return false; |
+ return transaction.Commit(); |
+ } |
return true; |
+ } |
if (!CreateTable(db, kOfflinePagesTable)) |
return false; |