mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-14 14:22:13 +00:00
Correctly migrate the history database
I forgot to include the protocol column when migrating to v3, so create a v4 which ignores the sqlite error if the column already exists. Fixes https://github.com/hughsie/fwupd/issues/909
This commit is contained in:
parent
305f1f2ab1
commit
f692b71dc4
@ -157,7 +157,7 @@ fu_history_create_database (FuHistory *self, GError **error)
|
||||
"CREATE TABLE schema ("
|
||||
"created timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,"
|
||||
"version INTEGER DEFAULT 0);"
|
||||
"INSERT INTO schema (version) VALUES (3);"
|
||||
"INSERT INTO schema (version) VALUES (4);"
|
||||
"CREATE TABLE history ("
|
||||
"device_id TEXT,"
|
||||
"update_state INTEGER DEFAULT 0,"
|
||||
@ -226,7 +226,8 @@ fu_history_migrate_database_v2 (FuHistory *self, GError **error)
|
||||
|
||||
/* rename the table to something out the way */
|
||||
rc = sqlite3_exec (self->db,
|
||||
"ALTER TABLE history ADD COLUMN checksum_device TEXT DEFAULT NULL;",
|
||||
"ALTER TABLE history ADD COLUMN checksum_device TEXT DEFAULT NULL;"
|
||||
"ALTER TABLE history ADD COLUMN protocol TEXT DEFAULT NULL;",
|
||||
NULL, NULL, NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INTERNAL,
|
||||
@ -236,7 +237,7 @@ fu_history_migrate_database_v2 (FuHistory *self, GError **error)
|
||||
}
|
||||
|
||||
/* update version */
|
||||
rc = sqlite3_exec (self->db, "UPDATE schema SET version=3;", NULL, NULL, NULL);
|
||||
rc = sqlite3_exec (self->db, "UPDATE schema SET version=4;", NULL, NULL, NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INTERNAL,
|
||||
"Failed to migrate database: %s",
|
||||
@ -246,6 +247,29 @@ fu_history_migrate_database_v2 (FuHistory *self, GError **error)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
fu_history_migrate_database_v3 (FuHistory *self, GError **error)
|
||||
{
|
||||
gint rc;
|
||||
|
||||
/* rename the table to something out the way */
|
||||
rc = sqlite3_exec (self->db,
|
||||
"ALTER TABLE history ADD COLUMN protocol TEXT DEFAULT NULL;",
|
||||
NULL, NULL, NULL);
|
||||
if (rc != SQLITE_OK)
|
||||
g_debug ("ignoring database error: %s", sqlite3_errmsg (self->db));
|
||||
|
||||
/* update version */
|
||||
rc = sqlite3_exec (self->db, "UPDATE schema SET version=4;", NULL, NULL, NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INTERNAL,
|
||||
"Failed to update schema version: %s",
|
||||
sqlite3_errmsg (self->db));
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* returns 0 if database is not initialised */
|
||||
static guint
|
||||
fu_history_get_schema_version (FuHistory *self)
|
||||
@ -333,6 +357,10 @@ fu_history_load (FuHistory *self, GError **error)
|
||||
g_debug ("migrating v%u database", schema_ver);
|
||||
if (!fu_history_migrate_database_v2 (self, error))
|
||||
return FALSE;
|
||||
} else if (schema_ver == 3) {
|
||||
g_debug ("migrating v%u database", schema_ver);
|
||||
if (!fu_history_migrate_database_v3 (self, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
Loading…
Reference in New Issue
Block a user