-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Rename receiptFilename to filename #27203
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
83cc790
Add type for filename property
tgolen 3b410aa
Remove fallback to old property name
tgolen 8521bfb
Write initial migration
tgolen b9a72f4
Add an early return
tgolen 78b8b54
Clean up final migration
tgolen 45e8800
Merge branch 'main' into tgolen-rename-filename
tgolen 0ab4031
Let property be optional
tgolen f77b7c6
Merge branch 'main' into tgolen-rename-filename
tgolen cb248d2
Remove duplicate props
tgolen 2b404ad
Merge branch 'main' into tgolen-rename-filename
tgolen 20b6ce6
Lint
tgolen 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 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 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 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 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,57 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
import lodashHas from 'lodash/has'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
import Log from '../Log'; | ||
|
||
// This migration changes the property name on a transaction from receiptFilename to filename so that it matches what is stored in the database | ||
export default function () { | ||
return new Promise((resolve) => { | ||
// Connect to the TRANSACTION collection key in Onyx to get all of the stored transactions. | ||
// Go through each transaction and change the property name | ||
const connectionID = Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.TRANSACTION, | ||
waitForCollectionCallback: true, | ||
callback: (transactions) => { | ||
Onyx.disconnect(connectionID); | ||
|
||
if (!transactions || transactions.length === 0) { | ||
Log.info('[Migrate Onyx] Skipped migration RenameReceiptFilename because there are no transactions'); | ||
return resolve(); | ||
} | ||
|
||
if (!_.compact(_.pluck(transactions, 'receiptFilename')).length) { | ||
Log.info('[Migrate Onyx] Skipped migration RenameReceiptFilename because there were no transactions with the receiptFilename property'); | ||
return resolve(); | ||
} | ||
|
||
Log.info('[Migrate Onyx] Running RenameReceiptFilename migration'); | ||
|
||
const dataToSave = _.reduce( | ||
transactions, | ||
(result, transaction) => { | ||
// Do nothing if there is no receiptFilename property | ||
if (!lodashHas(transaction, 'receiptFilename')) { | ||
return result; | ||
} | ||
Log.info(`[Migrate Onyx] Renaming receiptFilename ${transaction.receiptFilename} to filename`); | ||
return { | ||
...result, | ||
[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`]: { | ||
filename: transaction.receiptFilename, | ||
receiptFilename: null, | ||
}, | ||
}; | ||
}, | ||
{}, | ||
); | ||
|
||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, dataToSave).then(() => { | ||
Log.info(`[Migrate Onyx] Ran migration RenameReceiptFilename and renamed ${_.size(dataToSave)} properties`); | ||
resolve(); | ||
}); | ||
}, | ||
}); | ||
}); | ||
} |
This file contains 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's a little OCD but I like the alphabetize these.