Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB: migrate to unique IDs for groups #1333

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

obfusk
Copy link
Contributor

@obfusk obfusk commented Jun 1, 2023

Edit: should be rebased on #1394.


Based on #1214, closes #1045.

TODO

  • rebase on main
  • cleanup & bug fixes
  • ensure tests pass
  • (manually) test migration
  • (manually) test v2 import/export
  • (manually) test v3 import/export
  • review
  • add tests for v2/v3 import/export

TODO but maybe out of scope for this PR

  • refactor duplicate code
  • handle duplicate IDs properly (hard) / drop data before importing (easy, warn user, use transaction)
  • make sure all (database) errors are handled properly
  • python script to merge two exports? https://github.com/obfusk/catimerge

@@ -717,7 +797,7 @@ public static int getLoyaltyCardCount(SQLiteDatabase database) {
*/
public static Cursor getGroupCursor(SQLiteDatabase database) {
return database.rawQuery("select * from " + LoyaltyCardDbGroups.TABLE +
" ORDER BY " + LoyaltyCardDbGroups.ORDER + " ASC," + LoyaltyCardDbGroups.ID + " COLLATE NOCASE ASC", null, null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Altonss why did you remove COLLATE NOCASE?

}

@Override
public boolean equals(@Nullable Object obj) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we lo longer need .equals() and .hashCode()? I think the default implementation is platform-dependent and would usually not consider objects equal if their fields are, only if they are the same object in memory. But I'm not familiar enough with the codebase to be sure that matters.

throw new FormatException("Group has no name: " + record);
}

DBHelper.insertGroup(database, id, name);
Copy link
Contributor Author

@obfusk obfusk Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for duplicates here, and reuse an existing group with the same name if it already exists.

*/
private void importCardGroupMappingV3(SQLiteDatabase database, CSVRecord record) throws FormatException {
int cardId = CSVHelpers.extractInt(DBHelper.LoyaltyCardDbIdsGroups.cardID, record);
int groupId = CSVHelpers.extractInt(DBHelper.LoyaltyCardDbIdsGroups.groupID, record);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we reuse an existing group ID in importGroupsV3(), we need to keep track of it to reuse it here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate groups to proper unique id
2 participants