I've just put SquadWOD into beta testing and made the annoying error of not properly preparing the backend before onboarding the first few users, I just kept the same database that I had been using during development. The obvious ramification of this mistake is that my own development testing can't now be against the same database as I'd risk making my users very unhappy, potentially corrupting their data.
The solution is to have at least a dev and production database, in Firebase this means creating a new project and making all the same setup choices as the first database. Simple enough, but I now had some real life useful data (not created by me) in that production database that I wanted in my new, empty, dev database.
Exporting and importing with Google Cloud Platform isn't particularly difficult but it is specific and I lost a couple of hours following the wrong documentation and misunderstand some concepts, so here's a walk through for future me (and you) on what to do as of June 2020.
We are going to use gcloud's export
command to get the data out of the source database and into a storage bucket that we will create using Google Cloud Platform Console in the same project.
gcloud config set project [your-project-name]
gcloud firestore export gs://[bucket-name]
, if you get a permissions error then it is highly likely you have created the bucket in a different project to the one your Firebase project is in, this is what tripped me up for a while.gcloud config set project [destination-project-id]
to change into the destination project.gsutil iam ch serviceAccount:[project-name]@appspot.gserviceaccount.com:admin gs://[source-bucket-name]
.gcloud firestore import gs://[bucket-name]/2020-06-05T14:59:17_93348
(changing the part after the /
to match yours) to import that source bucket straight into your Cloud Firestore database.Now the data is in, you need to bring across the user accounts so that the data ties to the correct user (assuming you have users). This is very straightforward and uses the Firebase CLI instead.
firebase projects:list
to get a handy list of all your projects.firebase auth:export accounts.json --format=json --project=[source-project-id]
to export the users to a file on your local machine.firebase auth:import accounts.json --project=[destination-project-id]
to import them to the destination project. Now all the user created data will tie to their information should you need it.Done! Not too difficult but fiddly at points and you need to be very aware of what account you're in ans what you're trying to do at that moment.