Skip to content

Commit

Permalink
bugfix/create-firestore-indexes-one-after-another (#194)
Browse files Browse the repository at this point in the history
* Artificially depend on each index prior to the next

* Create indexes one after another

* Lint and format
  • Loading branch information
Jackson Maxfield Brown committed Jun 15, 2022
1 parent 42c697f commit 9a2e02d
Showing 1 changed file with 16 additions and 2 deletions.
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

0 comments on commit 9a2e02d

Please sign in to comment.