Potential issue with database migration
Hi!
I'm not quite sure if this is really an issue with the migration code in GOM or if I somehow managed to use it incorrectly on my side, so please bear with me :)
In Calls I have a database for the call history and I'm trying to add a new property
Originally (database version 1) it was only storing the call number, whether a call was inbound, time when answered, etc. In database version 2 I added a "protocol" property (tel, sip, ...) which all worked fine (in case you're interested this was the commit: calls@6d8c227b). Now I want to keep track which modem or sip account was used for database version 3.
You can see how it was done in the above commit. It looks to me that I'm doing the same for v3 as I did for v2
My problem is that when I use the automatic migrator it fails because it's trying to add the "protocol" column even though it is already present (see calls!505 (comment 1375591)):
CallsRecordStore[157281]: WARNING: Error migrating call record database /home/fortysixandtwo/.local/share/calls/records.db: sqlite3_prepare_v2 failed: duplicate column name: protocol: ALTER TABLE 'calls' ADD COLUMN 'protocol' TEXT
This is how the database in question looks like:
sqlite> SELECT MAX(version) FROM _gom_version;
2
sqlite> .schema
CREATE TABLE _gom_version (version INTEGER);
CREATE TABLE IF NOT EXISTS 'calls' ('id' INTEGER PRIMARY KEY AUTOINCREMENT,'target' TEXT,'inbound' INTEGER,'start' BLOB,'answered' BLOB,'end' BLOB, 'protocol' TEXT);
Thinking this was maybe a bug in GOM I wrote a unit test for a two step migration (v1->v2->v3) and I was very confused that the test actually passed (btw I'd be more than happy to propose a MR for this if there's interest!).
So I whipped out gdb
to try to understand what exactly is going on and I think I have some idea of where the problem is:
https://gitlab.gnome.org/GNOME/gom/-/blob/master/gom/gom-repository.c#L182
I have current = 2
and version = 3
-> gom_repository_automatic_migrator()
being called with version=2
and because the protocol
property is new in version 2 (gom_resource_class_set_property_new_in_version (resource_class, "protocol", 2);
)
it tries to ALTER TABLE 'calls' ADD COLUMN 'protocol' TEXT
even though it is already present!
I will check in detail what happens in the current = 2
and version = 2
case (since the very same codepath should be hit here?!) and will follow up on that shortly.
Thanks for reading this far and for maintaining GOM!