8

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
pengz
  • 2,279
  • 3
  • 48
  • 91

2 Answers2

9

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

brotich
  • 417
  • 3
  • 7
  • this just hangs for me, or maybe takes a long time for the data that I have. GAEfan's answer is much easier/quicker/actually works. – julianhatwell Dec 01 '21 at 03:07
3
  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.

GAEfan
  • 11,244
  • 2
  • 17
  • 33
  • Thanks! Any idea where I can find this file? I tried finding it using the find command but doesn't seem to be returning any results. $ sudo find / -name *.datastore – pengz Oct 26 '17 at 22:23
  • I assumed you knew where it was, as you said you deleted its folder. Are you using the `--datastore_path` flag when you start the project? – GAEfan Oct 26 '17 at 23:06
  • on my machine it's at /WEB-INF/appengine-generated/db_store.bin – julianhatwell Dec 01 '21 at 03:10
  • On Mac, the default is `~/.config/gcloud/emulators/datastore` – new name Jan 01 '22 at 22:09