Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/create-firestore-indexes-one-after-another #194

Merged
merged 3 commits into from Jun 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions cdp_backend/infrastructure/cdp_stack.py
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

import json
from typing import List

import pulumi
import pulumi_gcp as gcp
Expand Down Expand Up @@ -183,6 +184,7 @@ def __init__(
)

# Create all firestore indexes
prior_index = None
for model_cls in DATABASE_MODELS:
for idx_field_set in model_cls._INDEXES:

Expand All @@ -201,14 +203,26 @@ def __init__(
# Finish creating the index set name
idx_set_name = "_".join(idx_set_name_parts)
fq_idx_set_name = f"{model_cls.collection_name}-{idx_set_name}"
firestore.Index(

# Create depends on list
# We don't want to create a ton of indexes in parallel
if prior_index is None:
depends_on: List[pulumi.Resource] = []
else:
depends_on = [prior_index]

# Create
prior_index = firestore.Index(
fq_idx_set_name,
project=self.gcp_project_id,
database_id="(default)",
collection_group_id=model_cls.collection_name,
fields=idx_set_fields,
query_scope="COLLECTION",
opts=pulumi.ResourceOptions(parent=self.firestore_app),
opts=pulumi.ResourceOptions(
parent=self.firestore_app,
depends_on=depends_on,
),
)

# Add metadata document
Expand Down