You can use the
gcloud command-line tool to test your application locally and
to manage indexes for your production Google Cloud Datastore instance. This page
describes the typical workflow for these activities.
gcloud tool supports the following workflow:
- Create local support for a Cloud Datastore instance, including directory, required files, and project ID.
- Start up the Cloud Datastore emulator, which provides local emulation of the production Cloud Datastore environment.
- Generate index definitions from your application's queries to the emulator.
- Upload manually created or generated index definitions to your production Cloud Datastore instance.
- Delete unused indexes from your production Cloud Datastore instance.
The development workflow using the command-line tool
The following is the typical workflow using the
Set environment variables so your application knows it is using the emulator.
Start your application and test it against the emulator. You need to run the queries your application uses against the emulator in order to generate indexes for your production Cloud Datastore instance.
Upload the generated indexes with the
create-indexescommand, passing in the path to your local
index.yamlfile, as in the following example:
gcloud datastore create-indexes ~/.config/gcloud/emulators/datastore/WEB-INF/index.yaml
The example path assumes you have not set a specific directory for the
data-diroption. If you have set a specific directory, modify the path to use the path to your
Remove environment variables so your application knows it is using the production Cloud Datastore instance.
Run your application against your production Cloud Datastore instance.
Over time, you might no longer use some of the indexes. You can delete unused indexes from your production Cloud Datastore instance by removing them from your local
index.yamlfile and then invoking the
gcloud datastore cleanup-indexes ~/.config/gcloud/emulators/datastore/WEB-INF/index.yaml
If you have set a specific directory for the
data-diroption, modify the path in the example to use the path to your