-
Notifications
You must be signed in to change notification settings - Fork 125
fix(datastore): base sync when sync expression changes #2937
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
Merged
edisooon
merged 36 commits into
main
from
edisooon/use-last-syncexpression-in-lookupLastSyncTime
Jan 2, 2025
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
9720a40
added comments for migration place in SQLiteStorageAdapter
a28ad3e
changed log before migration
24a24c2
added AddSyncExpressionToLastSyncMetadata
6a3f061
DB migration (MVP)
455f879
add new field to LastSyncMetadata model (MVP: pre-deserialized Query …
1fc5f09
updated signature of saveLastDelta/BaseSyncTime and added TODO in Syn…
f409ad3
use & save syncExpression (MVP)
0daf143
changed syncExpression in LastSyncMetadata from String to QueryPredic…
552cd9e
Added NONE PredicateType for MatchNoneQueryPredicate in GsonPredicate…
7975082
enabled objects assigned to concrete QueryPredicate classes to be ser…
7b03322
fix broken test cases
ab1c7f2
Updated lookupLastSyncTime logic with syncExpression comparison
5e694e0
fixed existing unit tests in SyncProcessorTest
9568719
added test cases when sync expression change in SyncProcessorTest
1e68d62
[minor format fix]
4c85614
minor fixed to pass checkstyle
076a042
[minor] more fixes for checkstyles
fc8d8a0
one last fix for checkstyle (hopefully)
66e0447
modified access modifier of ModelMigration and its implementations
f76bb96
reverted access modifier in ModelMigrations and added InternalApiWarning
ae8a66f
changed visibility modifier in LastMetadata and added InternalApiWarning
b282dab
got rid of new syncExpressions API in DataStoreConfiguration and its …
329b1d8
Update aws-datastore.api
34ffcfc
release resources if SyncProcessor reinitialization is required
c3eee86
[test the unit test failing cause in CI]
66f34df
removed initSyncProcessor from @Before to avoid double initialization
3046a41
checkstyle fix
b852be6
Merge branch 'main' into edisooon/use-last-syncexpression-in-lookupLa…
edisooon acac3ee
Merge branch 'main' into edisooon/use-last-syncexpression-in-lookupLa…
edisooon ba02506
Merge branch 'main' into edisooon/use-last-syncexpression-in-lookupLa…
tylerjroach 39695e6
deleted internalAPIWarning for ModelMigration classes
3ae7025
kept and deprecated old methods and created overrides in LastSyncMeta…
85b4999
used Objects.equals in SyncTimeRegistry
921fc67
fixed checkstyle
9f783a0
Merge branch 'main' into edisooon/use-last-syncexpression-in-lookupLa…
tylerjroach 5af954d
apiDump
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...ifyframework/datastore/storage/sqlite/migrations/AddSyncExpressionToLastSyncMetadata.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amplifyframework.datastore.storage.sqlite.migrations; | ||
|
||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
|
||
import com.amplifyframework.core.Amplify; | ||
import com.amplifyframework.core.category.CategoryType; | ||
import com.amplifyframework.logging.Logger; | ||
import com.amplifyframework.util.Wrap; | ||
|
||
/** | ||
* Add SyncExpression (TEXT) column to LastSyncMetadata table. | ||
*/ | ||
final class AddSyncExpressionToLastSyncMetadata implements ModelMigration { | ||
private static final Logger LOG = Amplify.Logging.logger(CategoryType.DATASTORE, "amplify:aws-datastore"); | ||
private final SQLiteDatabase database; | ||
private final String newSyncExpColumnName = "syncExpression"; | ||
|
||
/** | ||
* Constructor for the migration class. | ||
* @param database Connection to the SQLite database. | ||
*/ | ||
AddSyncExpressionToLastSyncMetadata(SQLiteDatabase database) { | ||
this.database = database; | ||
} | ||
|
||
@Override | ||
public void apply() { | ||
if (!needsMigration()) { | ||
LOG.debug("No LastSyncMetadata migration needed."); | ||
return; | ||
} | ||
addNewSyncExpColumnName(); | ||
} | ||
|
||
/** | ||
* Alter LastSyncMetadata table with new column. | ||
* Existing rows in LasySyncMetadata will have 'null' for ${newSyncExpColumnName} value, | ||
* until the next sync/hydrate operation. | ||
*/ | ||
private void addNewSyncExpColumnName() { | ||
try { | ||
database.beginTransaction(); | ||
final String addColumnSql = "ALTER TABLE LastSyncMetadata ADD COLUMN " + | ||
edisooon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
newSyncExpColumnName + " TEXT"; | ||
database.execSQL(addColumnSql); | ||
database.setTransactionSuccessful(); | ||
LOG.debug("Successfully upgraded LastSyncMetadata table with new field: " + newSyncExpColumnName); | ||
} finally { | ||
if (database.inTransaction()) { | ||
database.endTransaction(); | ||
} | ||
} | ||
} | ||
|
||
private boolean needsMigration() { | ||
final String checkColumnSql = "SELECT COUNT(*) FROM pragma_table_info('LastSyncMetadata') " + | ||
edisooon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"WHERE name=" + Wrap.inSingleQuotes(newSyncExpColumnName); | ||
try (Cursor queryResults = database.rawQuery(checkColumnSql, new String[]{})) { | ||
if (queryResults.moveToNext()) { | ||
int recordNum = queryResults.getInt(0); | ||
return recordNum == 0; // needs to be upgraded if there's no column named ${newSyncExpColumnName} | ||
} | ||
} | ||
return false; | ||
edisooon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.