You can use the
gcloud command-line tool to test your application locally and
to manage indexes for your production Cloud Firestore in Datastore mode instance. This page
describes the typical workflow for these activities.
gcloud tool supports the following workflow:
- Create local support for a Datastore mode instance, including directory, required files, and project ID.
- Start up the Datastore mode emulator, which provides local emulation of the production Datastore mode environment.
- Generate index definitions from your application's queries to the emulator.
- Upload manually created or generated index definitions to your production Datastore mode instance.
- Delete unused indexes from your production Datastore mode 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 Datastore mode instance.
Upload the generated indexes with the
indexes createcommand, passing in the path to your local
index.yamlfile, as in the following example:
gcloud datastore indexes create ~/.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 Datastore mode instance.
Run your application against your production Datastore mode instance.
Over time, you might no longer use some of the indexes. You can delete unused indexes from your production Datastore mode instance by removing them from your local
index.yamlfile and then invoking the
gcloud datastore indexes cleanup ~/.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