Best way to import/export Firebase Firestore Indexes and rules!
When it comes for BaaS, Firebase Firestore is used widely and as it has a free tier, mostly different firebase projects are used for development and production.
While development for composite quires, indexes are needed to be build.
In development it is created as required but during production release, its hard to create all the indexes manually.
So here's a quick method for that.
Firebase CLI:
In the project directory use:
firebase use <dev_project_id>
firebase init firestore
then y,
It will ask:
? What file should be used for Firestore Rules? firestore.rules
Press Enter.
It will ask:
? What file should be used for Firestore indexes? firestore.indexes.json
Press Enter.
Files will be created accordingly.
Create a new file firestore_keys.json
And from firestore.indexes.json copy content to firebase_keys.json.
Now in the terminal.
firebase use <prod_project_id>
firebase init firestore
then Y, Enter, Enter.
Now copy the content from the firestore_keys.json file that we created into firestore.indexes.json.
Now,
firebase deploy --only firestore:indexes
this will deploy all the indexes to prod.
Cheers Prod Indexes are ready !