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

Add Backfilled data script #28

Merged
merged 14 commits into from
Mar 17, 2022
Merged

Add Backfilled data script #28

merged 14 commits into from
Mar 17, 2022

Conversation

alallema
Copy link
Contributor

@alallema alallema commented Nov 30, 2021

Pull Request

What does this PR do?

Add a script to back-filled data from Firestore to MeiliSearch to give the possibility to import existing documents or reindex them if you already have documents in a Firestore Collection when you enable the MeiliSearch extension.
Check an example from google extension
#15

PR checklist

  • Handles different possibilities to launch the script
    • Command line with parameter
    • interactively
  • Add the possibility to import documents by batch
  • Add the possibility to import documents from sub-collections
  • Write a guide

Notes:

@alallema alallema force-pushed the backfilled-data branch 4 times, most recently from e95b5d4 to 774bb13 Compare December 1, 2021 10:22
@alallema alallema linked an issue Dec 1, 2021 that may be closed by this pull request
@alallema alallema force-pushed the backfilled-data branch 6 times, most recently from e2f719e to ef9d43a Compare December 8, 2021 16:28
@alallema alallema force-pushed the backfilled-data branch 2 times, most recently from 0ee91a8 to 059a2dd Compare December 9, 2021 16:42
@alallema alallema marked this pull request as ready for review December 9, 2021 16:48
functions/src/adapter.ts Outdated Show resolved Hide resolved
functions/src/import/config.ts Outdated Show resolved Hide resolved
functions/src/import/config.ts Outdated Show resolved Hide resolved
functions/src/import/config.ts Outdated Show resolved Hide resolved
functions/src/import/config.ts Outdated Show resolved Hide resolved
functions/src/import/index.ts Outdated Show resolved Hide resolved
functions/src/import/index.ts Outdated Show resolved Hide resolved
functions/src/import/index.ts Outdated Show resolved Hide resolved
functions/src/index.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@@ -20,23 +20,20 @@ jobs:
with:
node-version: 14
- name: Install dependencies
run: npm run install:functions
run: yarn install:functions
Copy link
Member

Choose a reason for hiding this comment

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

Any particular reason to change? 😸

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no particular opinion on the matter but all js repo use yarn by default so ... I change it

.github/workflows/test.yml Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
- Run the project for development:
Launch Meilisearch instance:
``` bash
curl -L https://install.meilisearch.com | sh # download Meilisearch
Copy link
Member

Choose a reason for hiding this comment

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

I saw that earlier 👀 😄

CONTRIBUTING.md Outdated Show resolved Hide resolved

test('adaptDocument with fields not set and with id field in document', () => {
mockedGetFieldsToIndex.mockReturnValueOnce([])
const snapshot = firebaseMock.firestore.makeDocumentSnapshot(
Copy link
Member

Choose a reason for hiding this comment

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

Could apply the http://xunitpatterns.com/Four%20Phase%20Test.html in these tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made some changes is this better?

functions/__tests__/config.test.ts Outdated Show resolved Hide resolved
@@ -40,7 +40,7 @@ describe('extension', () => {

beforeEach(() => {
restoreEnv = mockedEnv(defaultEnvironment)
config = require('../src/config').default
config = require('../src/config').config
Copy link
Member

Choose a reason for hiding this comment

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

This config can be loaded like this import config from '../src/config', no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, defaultEnvironment variables must be loaded first otherwise the config has no access to them.

functions/src/import/config.ts Outdated Show resolved Hide resolved
functions/src/import/config.ts Outdated Show resolved Hide resolved
.github/workflows/test.yml Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
guides/IMPORT_EXISTING_DOCUMENTS.md Outdated Show resolved Hide resolved
guides/IMPORT_EXISTING_DOCUMENTS.md Outdated Show resolved Hide resolved
guides/IMPORT_EXISTING_DOCUMENTS.md Outdated Show resolved Hide resolved
guides/IMPORT_EXISTING_DOCUMENTS.md Outdated Show resolved Hide resolved
guides/IMPORT_EXISTING_DOCUMENTS.md Show resolved Hide resolved
@alallema alallema force-pushed the backfilled-data branch 5 times, most recently from 31573f4 to 9aeb93a Compare March 15, 2022 12:00
Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

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

If we use yarn everywhere there should not be a package-lock.json

CONTRIBUTING.md Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
extension.yaml Outdated Show resolved Hide resolved
},
"engines": {
"node": ">=14.0.0"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"meilisearch": "^0.21.0"
"firebase-functions": "^3.16.0",
"meilisearch": "^0.24.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be updated in a later PR

functions/src/import/config.ts Outdated Show resolved Hide resolved
Comment on lines +60 to +62
return config.meilisearch.fieldsToIndex
? config.meilisearch.fieldsToIndex.split(/[ ,]+/)
: []
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes be before we arrive here, were they validated by your validation functions?

bidoubiwa
bidoubiwa previously approved these changes Mar 17, 2022
Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

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

🔥🔥🔥🔥🔥 LGTM 🔥🔥🔥🔥🔥 GREAT WORK

@alallema
Copy link
Contributor Author

bors merge

meili-bors bot added a commit that referenced this pull request Mar 17, 2022
28: Add Backfilled data script r=alallema a=alallema

# Pull Request

## What does this PR do?
Add a script to back-filled data from Firestore to MeiliSearch to give the possibility to import existing documents or reindex them if you already have documents in a Firestore Collection when you enable the MeiliSearch extension.
Check [an example from google extension](https://github.com/firebase/extensions/tree/master/firestore-bigquery-export#backfill-your-bigquery-dataset)
#15

## PR checklist
- [x] Handles different possibilities to launch the script
    - [x] Command line with parameter
    - [x] interactively
- [x] Add the possibility to import documents by batch
- [x] Add the possibility to import documents from sub-collections
- [x] Write a guide

**Notes:**
- The ability to run the script with a configuration file is not part of the MVP and may be implemented later #29 

Co-authored-by: alallema <[email protected]>
Co-authored-by: Amélie <[email protected]>
@meili-bors
Copy link
Contributor

meili-bors bot commented Mar 17, 2022

Build succeeded:

Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

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

Still LGTM 🔥🔥🔥

@alallema
Copy link
Contributor Author

bors merge

@meili-bors
Copy link
Contributor

meili-bors bot commented Mar 17, 2022

Already running a review

@alallema alallema merged commit 63fa7b6 into main Mar 17, 2022
@alallema alallema deleted the backfilled-data branch March 17, 2022 16:08
@bidoubiwa bidoubiwa added the enhancement New feature or request label Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BackFilled Data
4 participants