Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Datastore emulator remove data from local database

I have a local Datastore emulator instance running on my local machine (Mac OSX 10.11.6).

I have a bunch of data in there already, but I want to remove all data from the local database to start with a clean slate.

However I have already tried deleting the directory (where I thought) the data was being stored.

This message appears when starting the emulator.

WARNING: Reusing existing data in [/Users/myusername/.config/gcloud/emulators/datastore].

I deleted the entire datastore directory and it seems to be re-generated properly when the emulator is restarted. However, the old data is still there.

rm -rf /Users/myusername/.config/gcloud/emulators/datastore

I also confirmed that my Node App is connecting to the local emulator.

myusername$ $(gcloud beta emulators datastore env-init)
myusername$ gcloud beta emulators datastore env-init
export DATASTORE_DATASET=projectname
export DATASTORE_EMULATOR_HOST=localhost:8081
export DATASTORE_EMULATOR_HOST_PATH=localhost:8081/datastore
export DATASTORE_HOST=http://localhost:8081
export DATASTORE_PROJECT_ID=projectname
like image 843
pengz Avatar asked Oct 26 '17 14:10

pengz


People also ask

How to stop Datastore emulator?

After you start the emulator, you should see a message similar to the following: ... [datastore] Dev App Server is now running. To stop the emulator, type Control-C at the command prompt.

Is Datastore deprecated?

Because Cloud Datastore API v1 is released, Cloud Datastore API v1beta3 is now deprecated.

How do I remove all entities from Datastore?

Open "Datastore Admin" for your application and enable Admin. Then all of your entities will be listed with check boxes. You can simply select the unwanted entites and delete them. Save this answer.

How do I delete an index in Datastore?

Deleting unused indexes When you are sure that old indexes are no longer needed, you can delete them by using the datastore indexes cleanup command. This command deletes all indexes for the production Datastore mode instance that are not mentioned in the local version of index.


2 Answers

Datastore emulator supports resetting datastore when its running. This can be used to reset datastore when running tests.

Make POST request to http://localhost:8081/reset to clear the internal state of the emulator i.e

curl -X POST http://<emulator-host>:<port>/reset

see https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1292 discussion

like image 168
brotich Avatar answered Oct 03 '22 19:10

brotich


  1. Stop the local dev server from running
  2. Find its dev_appserver.datastore file and drag it to the trash
  3. Restart dev server

A new, empty local datastore will be created.

like image 40
GAEfan Avatar answered Oct 03 '22 18:10

GAEfan