Debian Codegraph @

docstore/gcpfirestore/create_indexes.sh

raw
1 #!/usr/bin/env bash
2 # Copyright 2019 The Go Cloud Development Kit Authors
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # https://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # Creates the Firestore indexes needed for tests.
17 # Takes one argument: the GCP project ID.
18 #
19 # If an index already exists, this script will fail. To re-create the index, delete
20 # it from the UI at https://firebase.corp.google.com/project/$project_id/database/firestore/indexes.
21
22 # https://coderwall.com/p/fkfaqq/safer-bash-scripts-with-set-euxo-pipefail
23 # Except we want to keep going if there is a failure, and x is too verbose.
24 set -uo pipefail
25
26 project_id="${1:-}"
27 if [[ -z "$project_id" ]]; then
28 echo "usage: create_indexes.sh PROJECT" 1>&2
29 exit 64
30 fi
31
32 echo "Creating indexes for $project_id"
33 echo "UI at https://firebase.corp.google.com/project/$project_id/database/firestore/indexes"
34
35 collection=docstore-test-2
36
37 function create_index() {
38 gcloud --project "$project_id" beta firestore indexes composite create --collection-group "$collection" \
39 --field-config field-path=$1,order=$2 --field-config field-path=$3,order=$4
40 }
41
42 set -x
43
44 create_index Player ascending Score ascending
45 create_index Game ascending Score ascending
46 create_index Player ascending Time ascending
47 create_index Game ascending Player ascending
48 create_index Game ascending Player descending