Skip to content

Commit bdbcf3a

Browse files
authored
Add unique index support in Firestore (#14682)
1 parent 214ebd8 commit bdbcf3a

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

mmv1/products/firestore/Index.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ examples:
9292
database_id: 'database-id-sparse-any'
9393
test_env_vars:
9494
project_id: 'PROJECT_NAME'
95+
- name: 'firestore_index_unique'
96+
primary_resource_id: 'my-index'
97+
vars:
98+
database_id: 'database-id-unique'
99+
test_env_vars:
100+
project_id: 'PROJECT_NAME'
95101
parameters:
96102
properties:
97103
- name: 'name'
@@ -152,6 +158,12 @@ properties:
152158
definition reach or traverse an array, except via an explicit array
153159
index. Violations will result in errors. Note this field only applies to
154160
indexes with MONGODB_COMPATIBLE_API ApiScope.
161+
- name: 'unique'
162+
type: Boolean
163+
default_from_api: true
164+
description:
165+
Whether it is an unique index. Unique index ensures all values for the
166+
indexed field(s) are unique across documents.
155167
- name: 'fields'
156168
type: Array
157169
description: |
@@ -206,7 +218,7 @@ properties:
206218
send_empty_value: true
207219
allow_empty_object: true
208220
properties:
209-
# Meant to be an empty object with no properties.
221+
# Meant to be an empty object with no properties.
210222
[]
211223
# Most composite indexes require at least two fields, but it is possible
212224
# for a user to require a single field index such as `__name__ DESC`.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
resource "google_firestore_database" "database" {
2+
project = "{{index $.TestEnvVars "project_id"}}"
3+
name = "{{index $.Vars "database_id"}}"
4+
location_id = "nam5"
5+
type = "FIRESTORE_NATIVE"
6+
database_edition = "ENTERPRISE"
7+
8+
delete_protection_state = "DELETE_PROTECTION_DISABLED"
9+
deletion_policy = "DELETE"
10+
}
11+
12+
resource "google_firestore_index" "{{$.PrimaryResourceId}}" {
13+
project = "{{index $.TestEnvVars "project_id"}}"
14+
database = google_firestore_database.database.name
15+
collection = "atestcollection"
16+
17+
api_scope = "MONGODB_COMPATIBLE_API"
18+
query_scope = "COLLECTION_GROUP"
19+
multikey = true
20+
density = "DENSE"
21+
unique = true
22+
23+
fields {
24+
field_path = "name"
25+
order = "ASCENDING"
26+
}
27+
28+
fields {
29+
field_path = "description"
30+
order = "DESCENDING"
31+
}
32+
}

0 commit comments

Comments
 (0)