8000 Sync with merge by golesny · Pull Request #2260 · moneymanagerex/android-money-manager-ex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Sync with merge #2260

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Sync with merge #2260

wants to merge 9 commits into from

Conversation

golesny
Copy link
@golesny golesny commented Feb 12, 2025

Hi @guanlisheng
This is the first code for the sync.
the sync code should work (when categories and the rest is not modified).

I could now force a both modified. What is strange is that the metadata check is only working when I download the remote file to the tmp file before checking the modified date.

@golesny golesny marked this pull request as draft February 12, 2025 16:47
@golesny golesny changed the base branch from sync to master February 12, 2025 16:47
@golesny golesny changed the title Sync Sync with merge Feb 13, 2025
SupportSQLiteDatabase tmpDBReadable = tmpDBHelper.getReadableDatabase();
// prepare local db (writeable)
SupportSQLiteDatabase localDB = MmexApplication.getApp().openHelperAtomicReference.get().getWritableDatabase();
MmxDate lastLocalSyncDate = getLastLocalSyncDate(storage.getContext());
Copy link
Contributor

Choose a reason for hiding this comment

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

hi @golesny, this file-level info should be ready from the database metadata.

  1. sync date/time is for file level
  2. suid is helpful on row level
  3. Some fields might be helpful for the column level.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I understood the principle, now. Working on an abstraction and I need to add last modified time to each entry for all tables. I will upload it for payee, first, to let you check the changes. Only the SUID is not helping when an entry was modified.
I guess, I need to implement the manual merge, also.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about starting with row-level/suid first? there is no perfect solution for the field/column level, and there is even no updated_at field

Copy link
Author

Choose a reason for hiding this comment

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

Yes, you are right.
I just don't know what to do, when both entries are modified after creation.
The SUIDs solves only the creation problem.
In the transaction table is the last updated field which is needed for merge. The other tables don't have this.
Or do I miss something?

Copy link
Author
@golesny golesny Feb 16, 2025

Choose a reason for hiding this comment

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

@guanlisheng I tried to implement it without the last Modified Date.
This is not possible, because I don't know which side is modified. (I updated the PR)
And then I would need to ignore the changes (either remote or local). This would end up in and endless loop of ignoring the new values.
Example:
User 1 and User 2 are sharing the file and U1 is modifying one payee.
On prefering the local version I would use the new value on sync and upload the new file.
U2 now syncs the file back but I would not take the changes because I would prefer the local changes.
And the file with the old value would be uploaded.
U1 would always upload the local value and U2 always the old value.

I need to add a lastModifiedDate and a LastSyncDate to determine what has changed when.
Otherwise we need to inactivate old rows and create always a new one, but this is a very big change.
What do you think?
My proposal:

  • Add a modifiedDateTime to each table in an extra PR (this can be introduced easiliy, default is 1900 or so) -> who can do that? Shall I try it?
  • Based on that I provide my PR with the merge

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @golesny

Thank you for continuing on this hard topic. Your understanding is correct that SUID is to mitigate the issue instead.

Modifications on both sides will result in conflict, no matter in which level.

  1. for file level today, it will raise an error and let the end user decide: either force download or upload.
  2. for row level, we may consider a similar proposal and leave it to the user to choose one as well.
  3. for column level, the user may pick a more fine grain when dealing with conflicts.

Copy link
Author

Choose a reason for hiding this comment

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

@guanlisheng I would not go to Column Level with this PR
I agree, that manual decision will solve the conflict problems. Then, we also don't need the last modified time on each table. It might be a bit annoying when a lot of changes (from edit operation) are incoming (but we can improve later, e.g. checkbox).
I will prepare the PR with manual merging decision.

Copy link
Author

Choose a reason for hiding this comment

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

@guanlisheng @wolfsolver I have the UI now implemented roughly (currently just for testing).
The merge seems to work now (currently only for Payee and Transaction)
Missing things:

  • Show the entity as text (for the conflict dialog)
  • After sync/merge the current table needs to be refreshed (currently you have to go out and in again)

@wolfsolver
Copy link
Member

Please wait to push until 5.1.1 was release

Thanks

@golesny
Copy link
Author
golesny commented Feb 22, 2025

Please wait to push until 5.1.1 was release

No problem, I need some time to finalize the UI.
The question is also, do we need to implement the merge on all platforms, first?
I might be able to implement it in C# (Java is quite similiar, but I guess it will take a while) but iOS is not possible for me.

@guanlisheng
Copy link
Contributor

hi @golesny, eventually yes while it takes time. with your help, android might go first.

@wolfsolver
Copy link
Member

I don't think that we have to wait for all platforms ready to merge. Is enough when all platforms handle new suid

@wolfsolver
Copy link
Member

Please wait to push until 5.1.1 was release

Thanks

5.1 is gone. :)

@golesny
Copy link
Author
golesny commented Mar 5, 2025

@wolfsolver @guanlisheng
Could you please check/test the current state?
Still the refresh of the current view is missing (I need a hint there how to do that).
But for Payee and AccoutnTransaction it works fine, now.
I implemented a very simple text diff output for now. Perhaps you have some ideas how to improve that.
Additionally, while testing I faced often problems with the GDrive upload (app showed "Copied 123 bytes" but after that the gdrive upload started and failed and than on sync again it says "Database up to date" which is wrong, Force upload solved that problem)
For testing, the easiest way is to modify on both sides a payee (as this entity has no last modified field the diff dialog is forced) and then upload on the one phone and then sync on the other.

Next steps: Add all entities

@guanlisheng
Copy link
Contributor

thanks, @golesny , will run it locally with some test data.

also + @velmuruganc

@wolfsolver
Copy link
Member

Great I'll do some test. @golesny for the issue regarding misleading message is known and there is also this #2056

@guanlisheng guanlisheng requested a review from Copilot April 2, 2025 02:35
Copy link
Contributor
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces changes to support sync functionality by exposing entity creation and table name information for multiple repositories, along with adjustments to sync-related methods.

  • Changed access modifiers for createEntity() methods from protected to public and added getTableName() implementations
  • Updated AccountTransactionRepository to utilize a different date format for last updated time
  • Introduced new helper methods in FileStorageHelper and added a constant in InfoKeys to support sync metadata

Reviewed Changes

Copilot reviewed 36 out of 37 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
StockRepository.java Changed createEntity() access modifier and added getTableName()
StockHistoryRepository.java Changed createEntity() access modifier and added getTableName()
SplitScheduledCategoryRepository.java Changed createEntity() access modifier and added getTableName() (note the entity type returned)
SplitCategoryRepository.java Changed createEntity() access modifier and added getTableName()
ScheduledTransactionRepository.java Changed createEntity() access modifier and added getTableName()
RepositoryBase.java Updated abstract methods' access and added getTableName() declaration
ReportRepository.java Changed createEntity() access modifier and added getTableName()
PayeeRepository.java Changed table name constant to public and updated createEntity() access
IModificationTraceable.java Added new interface for modification traceability
CategoryRepository.java, BudgetRepository.java, BudgetEntryRepository.java, AttachmentRepository.java, CurrencyRepository.java Updated createEntity() access modifiers and added getTableName() implementations
AccountTransactionRepository.java Updated createEntity() access modifier, added getTableName(), and modified date format in update()
AccountRepository.java Changed createEntity() access modifier and added getTableName()
QueryAllDataRepository.java Changed createEntity() access modifier and added getTableName() (with a FIXME placeholder)
FileStorageHelper.java Introduced pullDatabaseToTmpFile() method and modified uploadDatabase() to handle sync rollback
InfoKeys.java Added LAST_SYNC_DATE constant
Files not reviewed (1)
  • app/build.gradle: Language not supported
Comments suppressed due to low confidence (2)

app/src/main/java/com/money/manager/ex/datalayer/SplitScheduledCategoryRepository.java:46

  • The repository name is SplitScheduledCategoryRepository, but the createEntity() method returns a SplitRecurringCategory. Verify if this type is correct or if it should be SplitScheduledCategory instead.
public SplitRecurringCategory createEntity() {

app/src/main/java/com/money/manager/ex/datalayer/AccountTransactionRepository.java:106

  • Changing from toIsoCombinedString() to toIsoString() may affect the expected date format. Please verify that toIsoString() returns the format required by downstream consumers.
item.setLastUpdatedTime((new MmxDate()).toIsoString());

return new AccountTransactionDisplay();
}

@Override
public String getTableName() {
return ""; // FIXME
Copy link
Preview
Copilot AI Apr 2, 2025

Choose a reason for hiding this comment

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

The getTableName() method currently returns an empty string with a FIXME comment. Please update this to return the correct table name to avoid potential runtime issues when querying data.

Suggested change
return ""; // FIXME
return "queryalldata";

Copilot uses AI. Check for mistakes.

@golesny
Copy link
Author
golesny commented Apr 20, 2025

@wolfsolver @guanlisheng Sorry for being absent so long. I tried to finalize the merge but there are some datalayer classes for some tables missing: ASSETS_, CURRENCYFORMATS, CURRENCYHISTORY, CUSTOMFIELDDATA, CUSTOMFIELD, INFOTABLE, CATEGORY_, CHECKINGACCOUNT, TRANSLINK
Why is there no datalayer (Repository) and can I just create the Repository classes for merge?

@guanlisheng
Copy link
Contributor

Thanks @golesny.
mobile MMEX has some lag so far, feel free to create them. and i will take a look shortly.

@golesny
Copy link
Author
golesny commented May 4, 2025

I added all missing tables, now everything should be complete. Thanks for adding missing ORM @guanlisheng
Unfortunately I cannot test it, currently, I have IDE problems since last rebase, but will try to solve it.

@golesny
Copy link
Author
golesny commented May 20, 2025

I think its ready now for experimental use. I added a switch in the sync settings.
I'm not really able to test every table because I don't know where to put in stocks and several other tables like additional info.
I will try it out in real life in the next months. I guess its good enough for me for now.

@golesny golesny marked this pull request as ready for review May 20, 2025 19:59
@wolfsolver
Copy link
Member

Great work.

Tomorrow I will compile and test on my android to verify and perform some test before meege

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.

3 participants
0