Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[qtcontacts-sqlite] Use safer drop-index syntax during schema upgrade…
…. Contributes to JB#51847

Otherwise the schema upgrade can fail for spurious reasons, if the
FamiliesDetailsContactIdIndex or GeoLocationsDetailsContactIdIndex
were not created for some database due to versioning issues.

Contributes to JB#51847
  • Loading branch information
chriadam committed Nov 4, 2020
1 parent 14626fd commit c7043c8
Showing 1 changed file with 57 additions and 57 deletions.
114 changes: 57 additions & 57 deletions src/engine/contactsdatabase.cpp
Expand Up @@ -856,7 +856,7 @@ static const char *upgradeVersion8[] = {
0 // NULL-terminated
};
static const char *upgradeVersion9[] = {
"DROP INDEX DetailsJoinIndex",
"DROP INDEX IF EXISTS DetailsJoinIndex",
// Don't recreate the index since it doesn't exist in versions after 10:
//createDetailsJoinIndex,
"PRAGMA user_version=10",
Expand Down Expand Up @@ -940,34 +940,34 @@ static const char *upgradeVersion10[] = {
"FROM DetailsIndexing AS DI "
"JOIN OldDetails AS OD ON OD.detailId = DI.oldDetailId AND OD.detail = DI.detail",
"DROP INDEX IF EXISTS DetailsJoinIndex",
"DROP INDEX DetailsRemoveIndex",
"DROP INDEX IF EXISTS DetailsRemoveIndex",
"DROP TABLE OldDetails",
// Drop all indexes for tables we are rebuilding
"DROP INDEX AddressesDetailsContactIdIndex",
"DROP INDEX AnniversariesDetailsContactIdIndex",
"DROP INDEX AvatarsDetailsContactIdIndex",
"DROP INDEX BirthdaysDetailsContactIdIndex",
"DROP INDEX EmailAddressesDetailsContactIdIndex",
"DROP INDEX GlobalPresencesDetailsContactIdIndex",
"DROP INDEX GuidsDetailsContactIdIndex",
"DROP INDEX HobbiesDetailsContactIdIndex",
"DROP INDEX NicknamesDetailsContactIdIndex",
"DROP INDEX NotesDetailsContactIdIndex",
"DROP INDEX OnlineAccountsDetailsContactIdIndex",
"DROP INDEX OrganizationsDetailsContactIdIndex",
"DROP INDEX PhoneNumbersDetailsContactIdIndex",
"DROP INDEX PresencesDetailsContactIdIndex",
"DROP INDEX RingtonesDetailsContactIdIndex",
"DROP INDEX TagsDetailsContactIdIndex",
"DROP INDEX UrlsDetailsContactIdIndex",
"DROP INDEX TpMetadataDetailsContactIdIndex",
"DROP INDEX ExtendedDetailsContactIdIndex",
"DROP INDEX PhoneNumbersIndex",
"DROP INDEX EmailAddressesIndex",
"DROP INDEX OnlineAccountsIndex",
"DROP INDEX NicknamesIndex",
"DROP INDEX TpMetadataTelepathyIdIndex",
"DROP INDEX TpMetadataAccountIdIndex",
"DROP INDEX IF EXISTS AddressesDetailsContactIdIndex",
"DROP INDEX IF EXISTS AnniversariesDetailsContactIdIndex",
"DROP INDEX IF EXISTS AvatarsDetailsContactIdIndex",
"DROP INDEX IF EXISTS BirthdaysDetailsContactIdIndex",
"DROP INDEX IF EXISTS EmailAddressesDetailsContactIdIndex",
"DROP INDEX IF EXISTS GlobalPresencesDetailsContactIdIndex",
"DROP INDEX IF EXISTS GuidsDetailsContactIdIndex",
"DROP INDEX IF EXISTS HobbiesDetailsContactIdIndex",
"DROP INDEX IF EXISTS NicknamesDetailsContactIdIndex",
"DROP INDEX IF EXISTS NotesDetailsContactIdIndex",
"DROP INDEX IF EXISTS OnlineAccountsDetailsContactIdIndex",
"DROP INDEX IF EXISTS OrganizationsDetailsContactIdIndex",
"DROP INDEX IF EXISTS PhoneNumbersDetailsContactIdIndex",
"DROP INDEX IF EXISTS PresencesDetailsContactIdIndex",
"DROP INDEX IF EXISTS RingtonesDetailsContactIdIndex",
"DROP INDEX IF EXISTS TagsDetailsContactIdIndex",
"DROP INDEX IF EXISTS UrlsDetailsContactIdIndex",
"DROP INDEX IF EXISTS TpMetadataDetailsContactIdIndex",
"DROP INDEX IF EXISTS ExtendedDetailsContactIdIndex",
"DROP INDEX IF EXISTS PhoneNumbersIndex",
"DROP INDEX IF EXISTS EmailAddressesIndex",
"DROP INDEX IF EXISTS OnlineAccountsIndex",
"DROP INDEX IF EXISTS NicknamesIndex",
"DROP INDEX IF EXISTS TpMetadataTelepathyIdIndex",
"DROP INDEX IF EXISTS TpMetadataAccountIdIndex",
// Migrate the Addresses table to the new form
"ALTER TABLE Addresses RENAME TO OldAddresses",
createAddressesTable,
Expand Down Expand Up @@ -1316,8 +1316,8 @@ static const char *upgradeVersion10[] = {
"JOIN DetailsIndexing AS DI ON DI.oldDetailId = OD.detailId AND DI.detail = 'ExtendedDetail'",
"DROP TABLE OldExtendedDetails",
// Drop the indexing table
"DROP INDEX DetailsIndexingOldDetailIdIndex",
"DROP INDEX DetailsIndexingDetailIndex",
"DROP INDEX IF EXISTS DetailsIndexingOldDetailIdIndex",
"DROP INDEX IF EXISTS DetailsIndexingDetailIndex",
"DROP TABLE DetailsIndexing",
// Rebuild the indexes we dropped
createDetailsRemoveIndex,
Expand Down Expand Up @@ -1439,34 +1439,34 @@ static const char *upgradeVersion20[] = {
// sync plugins need to re-sync anyway...
"DROP TABLE DeletedContacts", // this table is no longer used.
// drop a bunch of indexes which we will need to recreate
"DROP INDEX DetailsRemoveIndex",
"DROP INDEX AddressesDetailsContactIdIndex",
"DROP INDEX AnniversariesDetailsContactIdIndex",
"DROP INDEX AvatarsDetailsContactIdIndex",
"DROP INDEX BirthdaysDetailsContactIdIndex",
"DROP INDEX EmailAddressesDetailsContactIdIndex",
"DROP INDEX FamiliesDetailsContactIdIndex",
"DROP INDEX GeoLocationsDetailsContactIdIndex",
"DROP INDEX GlobalPresencesDetailsContactIdIndex",
"DROP INDEX GuidsDetailsContactIdIndex",
"DROP INDEX HobbiesDetailsContactIdIndex",
"DROP INDEX NicknamesDetailsContactIdIndex",
"DROP INDEX NotesDetailsContactIdIndex",
"DROP INDEX OnlineAccountsDetailsContactIdIndex",
"DROP INDEX OrganizationsDetailsContactIdIndex",
"DROP INDEX PhoneNumbersDetailsContactIdIndex",
"DROP INDEX PresencesDetailsContactIdIndex",
"DROP INDEX RingtonesDetailsContactIdIndex",
"DROP INDEX TagsDetailsContactIdIndex",
"DROP INDEX UrlsDetailsContactIdIndex",
"DROP INDEX OriginMetadataDetailsContactIdIndex",
"DROP INDEX ExtendedDetailsContactIdIndex",
"DROP INDEX PhoneNumbersIndex",
"DROP INDEX EmailAddressesIndex",
"DROP INDEX OnlineAccountsIndex",
"DROP INDEX NicknamesIndex",
"DROP INDEX OriginMetadataIdIndex",
"DROP INDEX OriginMetadataGroupIdIndex",
"DROP INDEX IF EXISTS DetailsRemoveIndex",
"DROP INDEX IF EXISTS AddressesDetailsContactIdIndex",
"DROP INDEX IF EXISTS AnniversariesDetailsContactIdIndex",
"DROP INDEX IF EXISTS AvatarsDetailsContactIdIndex",
"DROP INDEX IF EXISTS BirthdaysDetailsContactIdIndex",
"DROP INDEX IF EXISTS EmailAddressesDetailsContactIdIndex",
"DROP INDEX IF EXISTS FamiliesDetailsContactIdIndex",
"DROP INDEX IF EXISTS GeoLocationsDetailsContactIdIndex",
"DROP INDEX IF EXISTS GlobalPresencesDetailsContactIdIndex",
"DROP INDEX IF EXISTS GuidsDetailsContactIdIndex",
"DROP INDEX IF EXISTS HobbiesDetailsContactIdIndex",
"DROP INDEX IF EXISTS NicknamesDetailsContactIdIndex",
"DROP INDEX IF EXISTS NotesDetailsContactIdIndex",
"DROP INDEX IF EXISTS OnlineAccountsDetailsContactIdIndex",
"DROP INDEX IF EXISTS OrganizationsDetailsContactIdIndex",
"DROP INDEX IF EXISTS PhoneNumbersDetailsContactIdIndex",
"DROP INDEX IF EXISTS PresencesDetailsContactIdIndex",
"DROP INDEX IF EXISTS RingtonesDetailsContactIdIndex",
"DROP INDEX IF EXISTS TagsDetailsContactIdIndex",
"DROP INDEX IF EXISTS UrlsDetailsContactIdIndex",
"DROP INDEX IF EXISTS OriginMetadataDetailsContactIdIndex",
"DROP INDEX IF EXISTS ExtendedDetailsContactIdIndex",
"DROP INDEX IF EXISTS PhoneNumbersIndex",
"DROP INDEX IF EXISTS EmailAddressesIndex",
"DROP INDEX IF EXISTS OnlineAccountsIndex",
"DROP INDEX IF EXISTS NicknamesIndex",
"DROP INDEX IF EXISTS OriginMetadataIdIndex",
"DROP INDEX IF EXISTS OriginMetadataGroupIdIndex",
// cannot alter a table to add a foreign key
// instead, rename the existing table and recreate it with the foreign key.
// we only keep "local" and "aggregate" contacts.
Expand Down

0 comments on commit c7043c8

Please sign in to comment.