You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: bin/mas-devops-feature-status-update.md
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -148,6 +148,8 @@ Verifies MongoDB connectivity and confirms that the required indexes exist on th
148
148
149
149
Pass `--create-indexes` to create missing indexes automatically instead of exiting with an error.
150
150
151
+
**Idempotency:** Safe to run repeatedly. The connectivity check is read-only. When `--create-indexes` is passed, `create_index` is a no-op for any index that already exists — it will never drop or recreate an existing index.
152
+
151
153
**Options**
152
154
153
155
| Flag | Required | Description |
@@ -181,9 +183,11 @@ After a successful `prep` run the command prints the `export` statements needed
181
183
182
184
### `status-update`
183
185
184
-
Upserts a feature status document.
186
+
Upserts a feature status document.
185
187
Upsert key: `(region, instance_id, account, cluster, type)` — an existing document is updated in-place; a new document is inserted if no match is found.
186
188
189
+
**Idempotency:** Safe to call multiple times with the same arguments. The underlying `find_one_and_update` with `upsert=True` guarantees that re-running with the same identity key produces the same final document state. `created_at` is set only on the first insert (`$setOnInsert`); subsequent calls update `updated_at` and all mutable fields without creating duplicate documents.
> **Idempotency:**`db.createCollection()` raises a `MongoServerError: Collection already exists` error if the collection is already present. The initialization scripts are **not safe to re-run** against an existing database. Use the safe re-initialization pattern below if you need to ensure indexes are up to date without dropping data.
If the collections already exist and you only need to ensure indexes are up to date, run `createIndex` calls directly — they are no-ops when the index name and definition already match:
> **Note:**`drop()` removes the collection, all its documents, and its indexes. Re-run `init_db.js` to recreate them.
549
+
> **Idempotency:** Not idempotent — `drop()` raises an error if the collection does not exist. Re-running `init_db.js` after a drop is safe because the collections no longer exist at that point.
> **Idempotency:** Same caveat as `init_db.js` — each file calls `db.createCollection()`, which fails if the collection already exists. Only run against a fresh or dropped database.
559
+
560
+
---
561
+
562
+
## Idempotency reference
563
+
564
+
| Operation | Idempotent | Notes |
565
+
|---|---|---|
566
+
|`init_db.js` (full init) | ❌ |`db.createCollection()` fails if the collection already exists. Only run against a fresh or dropped database. |
567
+
|`cluster_level_config.js`| ❌ | Same — calls `db.createCollection()`. |
568
+
|`instance_level_config.js`| ❌ | Same — calls `db.createCollection()`. |
569
+
|`createIndex` (standalone) | ✅ | No-op when an index with the same name and definition already exists. Safe to run on a live collection. |
570
+
|`deleteMany({})` (clear) | ✅ | No-op on an already-empty collection. |
571
+
|`drop()`| ❌ | Errors if the collection does not exist. |
572
+
| Document upserts via `mas-devops-feature-status-update status-update`| ✅ | Uses `find_one_and_update` with `upsert=True`. Repeated calls on the same identity key update in-place; `created_at` is protected by `$setOnInsert`. |
0 commit comments