How to switch from Datastore to Firestore in existing project?
Asked Answered
U

3

6

I have an existing Google Cloud project which uses Datastore. I'm excited by Firestore and would like to switch. According to https://www.youtube.com/watch?v=SYG-BgXoJFQ it is recommended to create a new project.

Is it possible to just nuke Datastore somehow (I don't care about the data) and start from scratch with Firestore?

If not, what are the implications of creating a new project?

Ullund answered 20/9, 2018 at 23:2 Comment(0)
J
11

If there is no data written to Cloud datastore, it's possible to convert from datastore to firestore with the following steps. I tried on 2 projects and each project took 3 minutes. The user should be the project owner to attempt:

  1. Disable Cloud datastore API
  2. Disable Cloud Firestore API
  3. gcloud firestore databases create --region=us-central --project $PROJECT_ID

I have another project that has little datastore entities. I deleted them and executed the steps, but received the following error. While disabling datastore API, I read Disable Cloud Datastore API? If any resources were created by Cloud Datastore API, they may be deleted soon after Cloud Datastore API is disabled. All code that uses this project's credentials to call Cloud Datastore API will fail.

ERROR: (gcloud.firestore.databases.create) Error Response: [9] The "database_type" field cannot be modified for this application. Note: If data has already been written for this application, then the "database_type" may not be modified.

The solution is to contact Google cloud support to convert from Datastore to Firestore. You need to make sure no entities exist and nothing is creating any entities.

In the case where no Datastore entities have been written, the operation should succeed:

Success! Selected Google Cloud Firestore Native database for $PROJECT_ID

Jerrilyn answered 21/10, 2020 at 1:3 Comment(7)
I was able to successfully change the database I was using even tough I had already written some entries on the database by following this process and then calling google cloud support. console.cloud.google.com/support/phone I had to pay like 30 usd to be able to call support.Haller
A note to this also, between disabling both API's and the command line avoid visiting datastore/firestore at all in the GUI, it will undo your work and re-enable the old API's again!Markup
I tried this trick but got the [13] An internal error occurred message in the last step. Any idea?Deplore
Please check cloud logging for related messages during the timespan of the internal error. Usually, there's not much you can do seeing that type of error but contact Google cloud support, especially, the error is reproducible.Jerrilyn
I tried this but got this error "The app engine region is us-central which is not the same as us-east1. Right now the Firestore region must match the App Engine region." I need it in us-east1. I think this is all because years ago I created some resources and never used them. Beware of undocumented one-way doors and trapdoor side effects in GCP. It looks like I'm going to have to create a new project and set EVERYTHING up again, that's about $10,000 work :-(Bullpup
It may appear to be irreversible to you but Google cloud support is usually able to reset your App engine to us-east1 if there are no deployed services. Please work with them to coordinate the reset. The support cost is usually 3-4% of the cloud spend. The downside is all your deployed app engine services may need to be deleted. you may want to deploy them to a different project during the reset to maintain the SLA.Jerrilyn
The instructions above worked for me with the additional gcloud beta firestore databases delete --database='(default)' --project=foo cmd to delete the datastore.Harv
A
8

If your Datastore database is empty, you can switch to Firestore in Native mode with the following command:

gcloud alpha firestore databases update --type=firestore-native
Amusing answered 3/3, 2023 at 22:8 Comment(2)
This is definitely the preferred answer if you do not have any data in Firestore.Ericerica
Worked for me with an empty DBHowenstein
A
6

It is not possible to switch from Datastore to Firestore within the same project as yet, but you may operate Firestore in Datastore mode. By creating a Cloud Firestore database in Datastore mode, you can access Cloud Firestore's improved storage layer while keeping Cloud Datastore system behavior. You may find more information of relevance by reading the "Automatic Upgrade to Cloud Firestore" documentation page.

Amalgam answered 21/9, 2018 at 1:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.