I have a Firebase project, which uses Firestore. I often manually modify security rules and indexes on the Firebase console, but I also have local copies on my dev machine (firestore.rules
and firestore.indexes.json
), which become out of sync when I do so.
Is there a way to automatically sync them? For example, if I create an index in the console, how do I then persist that index in my firestore.indexes.json
?
So far I am manually applying those changes to local copies, but that is obviously an error prone process, and I'm trying to avoid accidentally overriding with out-of-date indexes or rules.
There is no automatic mechanism to handle conflicts between the Security rules declared in the Firebase console and the rules declared locally that get deployed when you deploy with the CLI.
If your local project is set-up to deploy the Firestore security rules they will overwrite the rules in the console when you deploy with the CLI. (See this documentation item: https://firebase.google.com/docs/rules/manage-deploy#edit_and_update_your_rules)
There are two possible approaches:
"rules": "firestore.rules"
line from the firebase.json
file and remove the firestore.rules
file from your project.Note that "using the CLI allows you to keep your rules under version control with your application code".
With indexes, things are a bit different: if there are differences between the two versions (the local firestore.indexes.json
file and the index in the console), you will get a warning in the terminal when deploying through the CLI:
i firestore: there are some indexes defined in your project that are not present in your firestore indexes file. Run firebase firestore:indexes and save the result to correct the discrepancy.
i firestore: there are some field overrides defined in your project that are not present in your firestore indexes file. Run firebase firestore:indexes and save the result to correct the discrepancy.
To update your local index JSON file, run firebase firestore:indexes > firestore/firestore.indexes.json
.