关闭。这个问题是opinion-based .它目前不接受答案。
想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题.
2年前关闭。
Improve this question
我有一个使用 Firestore 的 Firebase 项目。我经常在 Firebase 控制台上手动修改安全规则和索引,但我的开发机器上也有本地副本( firestore.rules
和 firestore.indexes.json
),这样做时它们会变得不同步。
有没有办法自动同步它们?例如,如果我在控制台中创建了一个索引,那么我如何将该索引保存在我的 firestore.indexes.json
中? ?
到目前为止,我手动将这些更改应用到本地副本,但这显然是一个容易出错的过程,我试图避免意外覆盖过时的索引或规则。
最佳答案
没有自动机制来处理 Firebase 控制台中声明的安全规则与使用 CLI 部署时在本地声明的规则之间的冲突。
如果您的本地项目设置为部署 Firestore 安全规则,当您使用 CLI 部署时,它们将覆盖控制台中的规则。 (请参阅此文档项:https://firebase.google.com/docs/rules/manage-deploy#edit_and_update_your_rules)
有两种可能的方法:
"rules": "firestore.rules"
来自 firebase.json
的线路文件并删除 firestore.rules
来自您项目的文件。 请注意,“使用 CLI 允许您使用应用程序代码将规则置于版本控制之下”。
使用索引,情况有点不同 : 如果两个版本存在差异(本地
firestore.indexes.json
文件和控制台中的索引),通过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.
通过运行
firebase firestore:indexes
,索引将打印在终端中,您将能够复制它们以手动更新 firestore.indexes.json
文件。
关于firebase - 如何同步 Firestore 规则和索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56307808/