How to create multi environment DB's with Firestore

霸气de小男生 提交于 2020-01-09 19:48:40

问题


I've been looking how to create multiple Firestore instances in Firebase, I need different Db's for prod, staging and development. I read the documentation and seems that I only need to modify the "Google-services.json" file in the applications. what I don't get is what should I modify and how that would look in the console.

  • Am I going to see different instances in the same project?

  • I need to create different projects for every environment and modify those values in the file?

  • If I need to test something that requires testing in all environments and all of them require Blaze to run that test do I have to pay Triple?

Thanks in advance


回答1:


Firebase doesn't support the use of multiple Firestore instances in a single project.

The Firebase team strongly recommends creating different projects for each of your environments to keep them separate. This probably means you will have to build different apps that each point to different instances, or you will have to somehow configure your app at runtime to select which project you want to work with.

There is no obligation to add billing to any of the projects you don't want to pay for, as long as you accept the limitations of the Spark plan.




回答2:


Yes Firebase doesn't support multiple instance in a single project. However my case, i created 3 different document in Firestore root and setup each environment to refer these documents accordingly. Each document will have the same collections, sub collections and documents.

For example,

dev -> users -> details
    -> others_collection -> details

stag -> users
     -> others_collection -> details

prod -> users
     -> others_collection -> details

On the client side, each environment will get the collection like this :

db.collection(`${env}/users`)

I am doing this on small project and seem pretty happy with what Firestore provided. In single project. i can create many ios/android apps according to the environment and each environment have it own document and collections in Firestore.




回答3:


The safest way is to create a new google cloud project. You can export your current firestore database to your new project if needed.

Step by step:

  1. Backup your current database by exporting all your documents into a bucket: https://firebase.google.com/docs/firestore/manage-data/export-import

    gcloud beta firestore export gs://[BUCKET_NAME]

  2. Create a new project -> https://cloud.google.com/resource-manager/docs/creating-managing-projects

  3. In the dashboard, select Firestore into your new project and create an empty database
  4. In the dashboard, go to your BACKUP_BUCKET and add your new project service account in the permission tab

  5. Switch project to your new project gcloud config set project 'new-project'

  6. Then export your data gcloud beta firestore import gs://[BUCKET_NAME]/[EXPORT_PREFIX]/ The EXPORT_PREFIX being the name of the folder created in your bucket.

I use this method to have clearly separated 'preprod' and 'production' environments (the team can access and synchronize with production without having access to the production environment codebase and configuration).



来源:https://stackoverflow.com/questions/48649120/how-to-create-multi-environment-dbs-with-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!