forked from invertase/react-native-firebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-firestore-indexes.sh
More file actions
executable file
·90 lines (76 loc) · 3.14 KB
/
Copy pathverify-firestore-indexes.sh
File metadata and controls
executable file
·90 lines (76 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
set -euo pipefail
# Post-deploy verification for pipelines-e2e composite/search indexes.
# Fails non-zero when expected index definitions are absent from cloud export.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# shellcheck source=firebase-cli.sh
source "$SCRIPT_DIR/firebase-cli.sh"
PROJECT="${FIREBASE_PROJECT:-react-native-firebase-testing}"
DATABASE="${FIRESTORE_VERIFY_DATABASE:-pipelines-e2e}"
TMP_INDEXES="$(mktemp)"
trap 'rm -f "$TMP_INDEXES"' EXIT
MIN_FIREBASE_TOOLS_VERSION="${MIN_FIREBASE_TOOLS_VERSION:-15.17.0}"
version_ge() {
local installed="$1"
local required="$2"
if [ "$(printf '%s\n' "$required" "$installed" | sort -V | head -n1)" != "$required" ]; then
return 1
fi
return 0
}
INSTALLED_VERSION="$("${FIREBASE_CMD[@]}" --version | tr -d '\r')"
if ! version_ge "$INSTALLED_VERSION" "$MIN_FIREBASE_TOOLS_VERSION"; then
echo "❌ firebase-tools ${INSTALLED_VERSION} is below required ${MIN_FIREBASE_TOOLS_VERSION} (search index deploy)." >&2
exit 1
fi
echo "Verifying Firestore indexes for project=${PROJECT} database=${DATABASE} (firebase-tools ${INSTALLED_VERSION})"
"${FIREBASE_CMD[@]}" use "$PROJECT" >/dev/null
"${FIREBASE_CMD[@]}" firestore:indexes --project "$PROJECT" --database "$DATABASE" >"$TMP_INDEXES"
# B2: full-text search composite on search-text/menu (not find-nearest vector index).
if ! python3 - "$TMP_INDEXES" <<'PY'
import json, sys
path = sys.argv[1]
with open(path) as f:
data = json.load(f)
indexes = data.get("indexes") or []
def has_search_menu_index(indexes):
for entry in indexes:
if entry.get("collectionGroup") != "search-text":
continue
for field in entry.get("fields") or []:
if field.get("fieldPath") != "menu":
continue
sc = field.get("searchConfig") or {}
specs = ((sc.get("textSpec") or {}).get("indexSpecs") or [])
for spec in specs:
if spec.get("indexType") == "TOKENIZED" and spec.get("matchType") == "MATCH_GLOBALLY":
return True
return False
if not has_search_menu_index(indexes):
print("Missing expected search-text/menu TOKENIZED MATCH_GLOBALLY searchConfig index in cloud export.", file=sys.stderr)
print("Triage: firebase-tools version, firestore.pipelines-e2e.indexes.json schema, index BUILDING state.", file=sys.stderr)
sys.exit(1)
print("OK: search-text/menu search index present in cloud export.")
PY
then
exit 1
fi
# Optional: warn when vector find-nearest index missing (separate from search spine).
if ! python3 - "$TMP_INDEXES" <<'PY'
import json, sys
path = sys.argv[1]
with open(path) as f:
data = json.load(f)
for entry in data.get("indexes") or []:
if entry.get("collectionGroup") == "find-nearest":
for field in entry.get("fields") or []:
if field.get("fieldPath") == "embedding" and field.get("vectorConfig"):
print("OK: find-nearest vector index present.")
sys.exit(0)
print("WARN: find-nearest vector index not found in cloud export (may still be BUILDING).", file=sys.stderr)
PY
then
:
fi
echo "Firestore index verification passed."