@intentsolutionsio/jeremy-firestore 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -6
- package/agents/firebase-operations-agent.md +18 -0
- package/agents/firestore-security-agent.md +3 -0
- package/commands/firestore-setup.md +11 -0
- package/package.json +1 -1
- package/skills/firestore-operations-manager/ARD.md +3 -0
- package/skills/firestore-operations-manager/PRD.md +9 -0
- package/skills/firestore-operations-manager/SKILL.md +18 -7
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ Build, manage, and optimize Firebase/Firestore databases with AI-powered agents
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
### Core Capabilities
|
|
12
|
+
|
|
12
13
|
- **CRUD Operations** - Create, read, update, delete with batch support
|
|
13
14
|
- **Security Rules** - Generate, validate, and deploy Firestore security rules
|
|
14
15
|
- **Data Migration** - Migrate data between collections, projects, or environments
|
|
@@ -19,12 +20,14 @@ Build, manage, and optimize Firebase/Firestore databases with AI-powered agents
|
|
|
19
20
|
- **Collection Management** - Schema validation, indexing, and organization
|
|
20
21
|
|
|
21
22
|
### AI Agents
|
|
23
|
+
|
|
22
24
|
- **firebase-operations-agent** - CRUD, queries, batch operations
|
|
23
25
|
- **firestore-security-agent** - Security rules generation and validation
|
|
24
26
|
- **firestore-migration-agent** - Data migration and transformation
|
|
25
27
|
- **firestore-optimizer-agent** - Performance and cost optimization
|
|
26
28
|
|
|
27
29
|
### Commands
|
|
30
|
+
|
|
28
31
|
- `/firestore-setup` - Initialize Firebase SDK and credentials
|
|
29
32
|
- `/firestore-query` - Interactive query builder
|
|
30
33
|
- `/firestore-migrate` - Guided migration workflow
|
|
@@ -68,7 +71,7 @@ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/serviceAccountKey.json"
|
|
|
68
71
|
|
|
69
72
|
### Example 1: CRUD Operations
|
|
70
73
|
|
|
71
|
-
```
|
|
74
|
+
```text
|
|
72
75
|
// Create documents
|
|
73
76
|
"Create a new user document in the 'users' collection"
|
|
74
77
|
|
|
@@ -119,7 +122,8 @@ Agent:
|
|
|
119
122
|
```
|
|
120
123
|
|
|
121
124
|
Agent generates:
|
|
122
|
-
|
|
125
|
+
|
|
126
|
+
```text
|
|
123
127
|
rules_version = '2';
|
|
124
128
|
service cloud.firestore {
|
|
125
129
|
match /databases/{database}/documents {
|
|
@@ -147,6 +151,7 @@ service cloud.firestore {
|
|
|
147
151
|
```
|
|
148
152
|
|
|
149
153
|
Agent workflow:
|
|
154
|
+
|
|
150
155
|
1. **Connects to staging** - Reads source collection
|
|
151
156
|
2. **Transforms data** - Anonymizes PII fields
|
|
152
157
|
3. **Validates** - Checks schema compatibility
|
|
@@ -162,6 +167,7 @@ Agent workflow:
|
|
|
162
167
|
```
|
|
163
168
|
|
|
164
169
|
Agent executes:
|
|
170
|
+
|
|
165
171
|
- Queries in batches of 500 documents
|
|
166
172
|
- Uses batch writes for efficiency (reduces costs 10x)
|
|
167
173
|
- Handles rate limits automatically
|
|
@@ -176,6 +182,7 @@ Agent executes:
|
|
|
176
182
|
```
|
|
177
183
|
|
|
178
184
|
Agent analyzes:
|
|
185
|
+
|
|
179
186
|
- **Missing indexes** - Identifies composite indexes needed
|
|
180
187
|
- **Query patterns** - Finds inefficient queries
|
|
181
188
|
- **Collection structure** - Suggests denormalization opportunities
|
|
@@ -191,18 +198,21 @@ Agent analyzes:
|
|
|
191
198
|
**Purpose:** Handle all Firestore CRUD operations, queries, and batch processing
|
|
192
199
|
|
|
193
200
|
**Use when:**
|
|
201
|
+
|
|
194
202
|
- Creating, reading, updating, or deleting documents
|
|
195
203
|
- Running complex queries with filters and ordering
|
|
196
204
|
- Batch operations on multiple documents
|
|
197
205
|
- Collection management
|
|
198
206
|
|
|
199
207
|
**Trigger phrases:**
|
|
208
|
+
|
|
200
209
|
- "create a document in..."
|
|
201
210
|
- "query the users collection..."
|
|
202
211
|
- "batch update all documents where..."
|
|
203
212
|
- "delete documents matching..."
|
|
204
213
|
|
|
205
214
|
**Example:**
|
|
215
|
+
|
|
206
216
|
```
|
|
207
217
|
User: "Get the 10 most recent orders for user123"
|
|
208
218
|
|
|
@@ -218,18 +228,21 @@ Agent:
|
|
|
218
228
|
**Purpose:** Generate, validate, and deploy Firestore security rules
|
|
219
229
|
|
|
220
230
|
**Use when:**
|
|
231
|
+
|
|
221
232
|
- Creating new security rules
|
|
222
233
|
- Validating existing rules
|
|
223
234
|
- Troubleshooting permission errors
|
|
224
235
|
- Implementing authentication patterns
|
|
225
236
|
|
|
226
237
|
**Trigger phrases:**
|
|
238
|
+
|
|
227
239
|
- "create security rules for..."
|
|
228
240
|
- "validate my firestore rules..."
|
|
229
241
|
- "fix permission denied error..."
|
|
230
242
|
- "implement role-based access..."
|
|
231
243
|
|
|
232
244
|
**Example:**
|
|
245
|
+
|
|
233
246
|
```
|
|
234
247
|
User: "Create rules for a chat app with public rooms and private messages"
|
|
235
248
|
|
|
@@ -248,18 +261,21 @@ Agent:
|
|
|
248
261
|
**Purpose:** Migrate data between collections, projects, or environments
|
|
249
262
|
|
|
250
263
|
**Use when:**
|
|
264
|
+
|
|
251
265
|
- Moving data between environments (staging → production)
|
|
252
266
|
- Restructuring collections
|
|
253
267
|
- Backfilling data
|
|
254
268
|
- Importing/exporting data
|
|
255
269
|
|
|
256
270
|
**Trigger phrases:**
|
|
271
|
+
|
|
257
272
|
- "migrate data from..."
|
|
258
273
|
- "copy collection to..."
|
|
259
274
|
- "restructure the users collection..."
|
|
260
275
|
- "backfill missing fields..."
|
|
261
276
|
|
|
262
277
|
**Example:**
|
|
278
|
+
|
|
263
279
|
```
|
|
264
280
|
User: "Migrate users collection to a new structure with nested addresses"
|
|
265
281
|
|
|
@@ -276,18 +292,21 @@ Agent:
|
|
|
276
292
|
**Purpose:** Optimize Firestore performance and reduce costs
|
|
277
293
|
|
|
278
294
|
**Use when:**
|
|
295
|
+
|
|
279
296
|
- Slow queries need optimization
|
|
280
297
|
- Monthly costs are too high
|
|
281
298
|
- Need index recommendations
|
|
282
299
|
- Want to analyze usage patterns
|
|
283
300
|
|
|
284
301
|
**Trigger phrases:**
|
|
302
|
+
|
|
285
303
|
- "optimize my firestore performance..."
|
|
286
304
|
- "reduce firebase costs..."
|
|
287
305
|
- "why is this query slow..."
|
|
288
306
|
- "analyze my firestore usage..."
|
|
289
307
|
|
|
290
308
|
**Example:**
|
|
309
|
+
|
|
291
310
|
```
|
|
292
311
|
User: "Why is my users query so slow?"
|
|
293
312
|
|
|
@@ -349,24 +368,28 @@ module.exports = {
|
|
|
349
368
|
## Best Practices
|
|
350
369
|
|
|
351
370
|
### Security Rules
|
|
371
|
+
|
|
352
372
|
- **Never allow open access** - Always require authentication
|
|
353
373
|
- **Validate all writes** - Check field types and values
|
|
354
374
|
- **Limit read scope** - Only allow reading necessary data
|
|
355
375
|
- **Test rules thoroughly** - Use Firebase Emulator Suite
|
|
356
376
|
|
|
357
377
|
### Performance
|
|
378
|
+
|
|
358
379
|
- **Use indexes** - Create composite indexes for complex queries
|
|
359
380
|
- **Batch operations** - Use batch writes for multiple documents
|
|
360
381
|
- **Denormalize data** - Duplicate data to avoid joins
|
|
361
382
|
- **Paginate results** - Use cursor-based pagination for large datasets
|
|
362
383
|
|
|
363
384
|
### Cost Optimization
|
|
385
|
+
|
|
364
386
|
- **Cache frequently read data** - Use in-memory caching
|
|
365
387
|
- **Minimize document reads** - Use `select()` to read specific fields
|
|
366
388
|
- **Archive old data** - Move historical data to Cloud Storage
|
|
367
389
|
- **Monitor usage** - Set up billing alerts
|
|
368
390
|
|
|
369
391
|
### Data Modeling
|
|
392
|
+
|
|
370
393
|
- **Keep documents small** - Max 1MB per document
|
|
371
394
|
- **Use subcollections** - For nested data hierarchies
|
|
372
395
|
- **Plan for scale** - Design for millions of documents
|
|
@@ -378,7 +401,7 @@ module.exports = {
|
|
|
378
401
|
|
|
379
402
|
### Pattern 1: User Profiles with Privacy
|
|
380
403
|
|
|
381
|
-
```
|
|
404
|
+
```text
|
|
382
405
|
// Collection structure
|
|
383
406
|
users/{userId}
|
|
384
407
|
- public: { name, avatar, bio } // Anyone can read
|
|
@@ -388,7 +411,7 @@ users/{userId}
|
|
|
388
411
|
|
|
389
412
|
### Pattern 2: Real-time Chat
|
|
390
413
|
|
|
391
|
-
```
|
|
414
|
+
```text
|
|
392
415
|
// Collection structure
|
|
393
416
|
rooms/{roomId}
|
|
394
417
|
- metadata: { name, createdAt, memberCount }
|
|
@@ -404,7 +427,7 @@ messages/{messageId}
|
|
|
404
427
|
|
|
405
428
|
### Pattern 3: E-commerce Orders
|
|
406
429
|
|
|
407
|
-
```
|
|
430
|
+
```text
|
|
408
431
|
// Collection structure
|
|
409
432
|
orders/{orderId}
|
|
410
433
|
- userId, status, total, createdAt
|
|
@@ -475,7 +498,7 @@ firebase projects:list
|
|
|
475
498
|
|
|
476
499
|
### Cloud Functions Integration
|
|
477
500
|
|
|
478
|
-
```
|
|
501
|
+
```text
|
|
479
502
|
// Trigger Cloud Functions from Firestore
|
|
480
503
|
"Create a function that sends an email when a new user signs up"
|
|
481
504
|
|
|
@@ -587,16 +610,19 @@ exports.onUserCreate = functions.firestore
|
|
|
587
610
|
## Resources
|
|
588
611
|
|
|
589
612
|
### Firebase Documentation
|
|
613
|
+
|
|
590
614
|
- [Firestore Documentation](https://firebase.google.com/docs/firestore)
|
|
591
615
|
- [Security Rules](https://firebase.google.com/docs/firestore/security/get-started)
|
|
592
616
|
- [Best Practices](https://firebase.google.com/docs/firestore/best-practices)
|
|
593
617
|
|
|
594
618
|
### Plugin Resources
|
|
619
|
+
|
|
595
620
|
- [GitHub Repository](https://github.com/jeremylongshore/claude-code-plugins)
|
|
596
621
|
- [Issue Tracker](https://github.com/jeremylongshore/claude-code-plugins/issues)
|
|
597
622
|
- [Marketplace](https://claudecodeplugins.io/)
|
|
598
623
|
|
|
599
624
|
### Community
|
|
625
|
+
|
|
600
626
|
- [Discord](https://discord.com/invite/6PPFFzqPDZ) (#claude-code channel)
|
|
601
627
|
- [GitHub Discussions](https://github.com/jeremylongshore/claude-code-plugins/discussions)
|
|
602
628
|
|
|
@@ -10,6 +10,7 @@ You are a Firebase/Firestore operations expert specializing in production-ready
|
|
|
10
10
|
## Your Expertise
|
|
11
11
|
|
|
12
12
|
You are a master of:
|
|
13
|
+
|
|
13
14
|
- **Firestore CRUD operations** - Create, read, update, delete with proper error handling
|
|
14
15
|
- **Complex queries** - Where clauses, ordering, pagination, filtering
|
|
15
16
|
- **Batch operations** - Efficient bulk reads/writes with rate limit handling
|
|
@@ -22,6 +23,7 @@ You are a master of:
|
|
|
22
23
|
## Your Mission
|
|
23
24
|
|
|
24
25
|
Help users perform Firestore operations safely, efficiently, and cost-effectively. Always:
|
|
26
|
+
|
|
25
27
|
1. **Validate before executing** - Check credentials, collections exist, queries are safe
|
|
26
28
|
2. **Handle errors gracefully** - Catch exceptions, provide helpful messages
|
|
27
29
|
3. **Optimize for cost** - Use batch operations, limit reads, suggest indexes
|
|
@@ -33,6 +35,7 @@ Help users perform Firestore operations safely, efficiently, and cost-effectivel
|
|
|
33
35
|
### 1. Create Documents
|
|
34
36
|
|
|
35
37
|
When creating documents:
|
|
38
|
+
|
|
36
39
|
- Validate all required fields are present
|
|
37
40
|
- Check data types match schema
|
|
38
41
|
- Use server timestamps for createdAt/updatedAt
|
|
@@ -40,6 +43,7 @@ When creating documents:
|
|
|
40
43
|
- Handle duplicates gracefully
|
|
41
44
|
|
|
42
45
|
Example:
|
|
46
|
+
|
|
43
47
|
```javascript
|
|
44
48
|
const admin = require('firebase-admin');
|
|
45
49
|
const db = admin.firestore();
|
|
@@ -58,6 +62,7 @@ console.log(`Created user with ID: ${docRef.id}`);
|
|
|
58
62
|
### 2. Read Documents
|
|
59
63
|
|
|
60
64
|
When reading documents:
|
|
65
|
+
|
|
61
66
|
- Use get() for single documents
|
|
62
67
|
- Use where() for filtered queries
|
|
63
68
|
- Add orderBy() for sorting
|
|
@@ -65,6 +70,7 @@ When reading documents:
|
|
|
65
70
|
- Implement pagination for large datasets
|
|
66
71
|
|
|
67
72
|
Example:
|
|
73
|
+
|
|
68
74
|
```javascript
|
|
69
75
|
// Get single document
|
|
70
76
|
const userDoc = await db.collection('users').doc('user123').get();
|
|
@@ -89,6 +95,7 @@ activeUsers.forEach(doc => {
|
|
|
89
95
|
### 3. Update Documents
|
|
90
96
|
|
|
91
97
|
When updating documents:
|
|
98
|
+
|
|
92
99
|
- Use update() for partial updates
|
|
93
100
|
- Use set({ merge: true }) for upserts
|
|
94
101
|
- Always update timestamps
|
|
@@ -96,6 +103,7 @@ When updating documents:
|
|
|
96
103
|
- Handle missing documents
|
|
97
104
|
|
|
98
105
|
Example:
|
|
106
|
+
|
|
99
107
|
```javascript
|
|
100
108
|
// Partial update
|
|
101
109
|
await db.collection('users').doc('user123').update({
|
|
@@ -119,6 +127,7 @@ await db.collection('stats').doc('page_views').update({
|
|
|
119
127
|
### 4. Delete Documents
|
|
120
128
|
|
|
121
129
|
When deleting documents:
|
|
130
|
+
|
|
122
131
|
- **Always confirm dangerous operations**
|
|
123
132
|
- Check for related data (cascading deletes)
|
|
124
133
|
- Use batch deletes for multiple documents
|
|
@@ -126,6 +135,7 @@ When deleting documents:
|
|
|
126
135
|
- Log deletions for audit trail
|
|
127
136
|
|
|
128
137
|
Example:
|
|
138
|
+
|
|
129
139
|
```javascript
|
|
130
140
|
// Single delete
|
|
131
141
|
await db.collection('users').doc('user123').delete();
|
|
@@ -150,6 +160,7 @@ console.log(`Deleted ${docsToDelete.size} documents`);
|
|
|
150
160
|
### Batch Operations
|
|
151
161
|
|
|
152
162
|
For operations on multiple documents:
|
|
163
|
+
|
|
153
164
|
1. **Use batched writes** - Up to 500 operations per batch
|
|
154
165
|
2. **Chunk large operations** - Process in batches of 500
|
|
155
166
|
3. **Handle failures** - Implement retry logic
|
|
@@ -157,6 +168,7 @@ For operations on multiple documents:
|
|
|
157
168
|
5. **Validate first** - Dry run before executing
|
|
158
169
|
|
|
159
170
|
Example:
|
|
171
|
+
|
|
160
172
|
```javascript
|
|
161
173
|
async function batchUpdate(collection, query, updates) {
|
|
162
174
|
const snapshot = await query.get();
|
|
@@ -187,6 +199,7 @@ async function batchUpdate(collection, query, updates) {
|
|
|
187
199
|
### Complex Queries
|
|
188
200
|
|
|
189
201
|
For advanced queries:
|
|
202
|
+
|
|
190
203
|
- **Use composite indexes** - Required for multiple filters
|
|
191
204
|
- **Avoid array-contains with other filters** - Limited support
|
|
192
205
|
- **Use orderBy strategically** - Affects which filters work
|
|
@@ -194,6 +207,7 @@ For advanced queries:
|
|
|
194
207
|
- **Consider denormalization** - For complex joins
|
|
195
208
|
|
|
196
209
|
Example:
|
|
210
|
+
|
|
197
211
|
```javascript
|
|
198
212
|
// Composite query (requires index)
|
|
199
213
|
const results = await db.collection('orders')
|
|
@@ -225,12 +239,14 @@ async function getNextPage() {
|
|
|
225
239
|
### Transactions
|
|
226
240
|
|
|
227
241
|
For atomic operations:
|
|
242
|
+
|
|
228
243
|
- **Use transactions** - For reads and writes that must be consistent
|
|
229
244
|
- **Keep transactions small** - Max 500 writes
|
|
230
245
|
- **Handle contention** - Implement retry logic
|
|
231
246
|
- **Read before write** - Transactions validate reads haven't changed
|
|
232
247
|
|
|
233
248
|
Example:
|
|
249
|
+
|
|
234
250
|
```javascript
|
|
235
251
|
await db.runTransaction(async (transaction) => {
|
|
236
252
|
// Read current balance
|
|
@@ -304,11 +320,13 @@ try {
|
|
|
304
320
|
## Cost Optimization
|
|
305
321
|
|
|
306
322
|
Firestore charges per operation:
|
|
323
|
+
|
|
307
324
|
- **Document reads**: $0.06 per 100k
|
|
308
325
|
- **Document writes**: $0.18 per 100k
|
|
309
326
|
- **Document deletes**: $0.02 per 100k
|
|
310
327
|
|
|
311
328
|
Optimize costs by:
|
|
329
|
+
|
|
312
330
|
- Using batch operations (1 write vs 500 writes)
|
|
313
331
|
- Caching frequently read data
|
|
314
332
|
- Using Cloud Functions for background tasks
|
|
@@ -10,6 +10,7 @@ You are a Firestore security rules expert specializing in production-ready secur
|
|
|
10
10
|
## Your Expertise
|
|
11
11
|
|
|
12
12
|
You are a master of:
|
|
13
|
+
|
|
13
14
|
- **Firestore Security Rules** - rules_version 2 syntax, patterns, validation
|
|
14
15
|
- **Authentication patterns** - Firebase Auth, custom claims, role-based access
|
|
15
16
|
- **A2A security** - Agent-to-agent authentication and authorization
|
|
@@ -22,6 +23,7 @@ You are a master of:
|
|
|
22
23
|
## Your Mission
|
|
23
24
|
|
|
24
25
|
Generate secure, performant Firestore security rules for both human users and AI agents. Always:
|
|
26
|
+
|
|
25
27
|
1. **Default deny** - Start with denying all access, then explicitly allow
|
|
26
28
|
2. **Validate authentication** - Require auth for all sensitive operations
|
|
27
29
|
3. **Validate data** - Check types, formats, required fields
|
|
@@ -465,6 +467,7 @@ When generating security rules:
|
|
|
465
467
|
## Security Checklist
|
|
466
468
|
|
|
467
469
|
Before deploying rules:
|
|
470
|
+
|
|
468
471
|
- [ ] All sensitive collections require authentication
|
|
469
472
|
- [ ] Service accounts are whitelisted (not open to all)
|
|
470
473
|
- [ ] Data validation checks all required fields
|
|
@@ -6,6 +6,7 @@ model: sonnet
|
|
|
6
6
|
# Firestore Setup Command
|
|
7
7
|
|
|
8
8
|
Initialize Firebase Admin SDK in your project with support for:
|
|
9
|
+
|
|
9
10
|
- Basic Firestore operations (CRUD, queries)
|
|
10
11
|
- A2A (Agent-to-Agent) framework integration
|
|
11
12
|
- MCP server communication patterns
|
|
@@ -58,6 +59,7 @@ npm install dotenv # For environment variables
|
|
|
58
59
|
Ask the user:
|
|
59
60
|
|
|
60
61
|
**Option A: Download from Firebase Console**
|
|
62
|
+
|
|
61
63
|
```
|
|
62
64
|
1. Go to https://console.firebase.google.com
|
|
63
65
|
2. Select your project
|
|
@@ -67,12 +69,14 @@ Ask the user:
|
|
|
67
69
|
```
|
|
68
70
|
|
|
69
71
|
**Option B: Use existing GCP credentials**
|
|
72
|
+
|
|
70
73
|
```bash
|
|
71
74
|
# If using Google Cloud SDK
|
|
72
75
|
gcloud auth application-default login
|
|
73
76
|
```
|
|
74
77
|
|
|
75
78
|
**Option C: Environment variable (production)**
|
|
79
|
+
|
|
76
80
|
```bash
|
|
77
81
|
# Set environment variable
|
|
78
82
|
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/serviceAccountKey.json"
|
|
@@ -109,6 +113,7 @@ module.exports = { admin, db };
|
|
|
109
113
|
```
|
|
110
114
|
|
|
111
115
|
For TypeScript:
|
|
116
|
+
|
|
112
117
|
```typescript
|
|
113
118
|
import * as admin from 'firebase-admin';
|
|
114
119
|
|
|
@@ -161,6 +166,7 @@ testFirestore();
|
|
|
161
166
|
```
|
|
162
167
|
|
|
163
168
|
Run the test:
|
|
169
|
+
|
|
164
170
|
```bash
|
|
165
171
|
node test-firestore.js
|
|
166
172
|
```
|
|
@@ -368,6 +374,7 @@ CLOUD_RUN_SERVICE_URL=https://your-service-abc123-uc.a.run.app
|
|
|
368
374
|
```
|
|
369
375
|
|
|
370
376
|
Add to `.gitignore`:
|
|
377
|
+
|
|
371
378
|
```
|
|
372
379
|
serviceAccountKey.json
|
|
373
380
|
.env
|
|
@@ -514,19 +521,23 @@ Tell the user:
|
|
|
514
521
|
## Common Issues
|
|
515
522
|
|
|
516
523
|
### Issue 1: "Permission denied" errors
|
|
524
|
+
|
|
517
525
|
- Check service account has Firestore permissions
|
|
518
526
|
- Verify security rules allow the operation
|
|
519
527
|
- Ensure GOOGLE_APPLICATION_CREDENTIALS is set correctly
|
|
520
528
|
|
|
521
529
|
### Issue 2: "Firebase app already initialized"
|
|
530
|
+
|
|
522
531
|
- This is normal - only initialize once
|
|
523
532
|
- Check if Firebase is initialized in multiple files
|
|
524
533
|
|
|
525
534
|
### Issue 3: "Cannot find module 'firebase-admin'"
|
|
535
|
+
|
|
526
536
|
- Run `npm install firebase-admin`
|
|
527
537
|
- Check package.json includes firebase-admin
|
|
528
538
|
|
|
529
539
|
### Issue 4: A2A collections not accessible
|
|
540
|
+
|
|
530
541
|
- Verify service account email is whitelisted in security rules
|
|
531
542
|
- Check firestore.rules includes A2A patterns
|
|
532
543
|
- Test with Firebase Emulator first
|
package/package.json
CHANGED
|
@@ -112,6 +112,7 @@ for (let i = 0; i < docs.length; i += BATCH_SIZE) {
|
|
|
112
112
|
**Rationale**: A migration processing 100,000 documents takes 200 batch commits. If the script crashes at batch 150, without checkpoints it must restart from document 0 (re-reading 75,000 already-processed documents). With checkpoints, it reads the last checkpoint and resumes from document 75,001.
|
|
113
113
|
|
|
114
114
|
**Checkpoint document schema**:
|
|
115
|
+
|
|
115
116
|
```typescript
|
|
116
117
|
interface MigrationCheckpoint {
|
|
117
118
|
migrationId: string;
|
|
@@ -193,6 +194,7 @@ IndexManager
|
|
|
193
194
|
### Migration Logging
|
|
194
195
|
|
|
195
196
|
Every batch commit logs:
|
|
197
|
+
|
|
196
198
|
```
|
|
197
199
|
[migration:backfill-status-field] Batch 150/200 committed. Processed: 75000, Skipped: 12, Failed: 0. Elapsed: 4m32s.
|
|
198
200
|
```
|
|
@@ -200,6 +202,7 @@ Every batch commit logs:
|
|
|
200
202
|
### Cost Estimation
|
|
201
203
|
|
|
202
204
|
Before executing large operations, estimate cost:
|
|
205
|
+
|
|
203
206
|
```
|
|
204
207
|
Operation: backfill 100,000 documents
|
|
205
208
|
Reads: 100,000 × $0.06/100k = $0.06
|
|
@@ -49,33 +49,42 @@ These problems share a root cause: Firestore's document model and operational co
|
|
|
49
49
|
## Functional Requirements
|
|
50
50
|
|
|
51
51
|
### FR-1: Schema-Aware CRUD
|
|
52
|
+
|
|
52
53
|
The skill must detect the existing collection schema (by reading sample documents) before proposing writes. New fields added via `update()` must not overwrite existing data unless explicitly requested.
|
|
53
54
|
|
|
54
55
|
### FR-2: Batch Write Management
|
|
56
|
+
|
|
55
57
|
Batch writes must:
|
|
58
|
+
|
|
56
59
|
- Chunk operations into groups of 500 (Firestore limit per `batch.commit()`)
|
|
57
60
|
- Log progress every N documents (configurable, default 1,000)
|
|
58
61
|
- Write a checkpoint document after each successful batch so the operation can resume
|
|
59
62
|
- Retry failed batches with exponential backoff (3 attempts, 1s/2s/4s delays)
|
|
60
63
|
|
|
61
64
|
### FR-3: Composite Index Generation
|
|
65
|
+
|
|
62
66
|
When the skill generates a query with multiple `where()` clauses or a `where()` + `orderBy()` combination, it must also produce the corresponding composite index entry for `firestore.indexes.json`.
|
|
63
67
|
|
|
64
68
|
### FR-4: Security Rules
|
|
69
|
+
|
|
65
70
|
Generated rules must:
|
|
71
|
+
|
|
66
72
|
- Deny all access by default (no `match /{document=**} { allow read, write: if true }`)
|
|
67
73
|
- Use helper functions for authentication and ownership checks
|
|
68
74
|
- Include field-level validation for create and update operations
|
|
69
75
|
- Be testable with `@firebase/rules-unit-testing`
|
|
70
76
|
|
|
71
77
|
### FR-5: Migration Operations
|
|
78
|
+
|
|
72
79
|
Migrations must:
|
|
80
|
+
|
|
73
81
|
- Support backfill (add field to existing documents) and transform (modify field values)
|
|
74
82
|
- Write a checkpoint after each batch to a `_migrations/{migrationId}` document
|
|
75
83
|
- Support dry-run mode that reads but does not write
|
|
76
84
|
- Produce a summary (documents processed, skipped, failed)
|
|
77
85
|
|
|
78
86
|
### FR-6: Pagination
|
|
87
|
+
|
|
79
88
|
Queries that may return more than 100 documents must use `startAfter()` cursor-based pagination. The skill must produce both the query code and the pagination cursor management logic.
|
|
80
89
|
|
|
81
90
|
## Non-Functional Requirements
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: firestore-operations-manager
|
|
3
|
-
description:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
description: 'Manage Firebase/Firestore operations including CRUD, queries, batch
|
|
4
|
+
processing, and index/rule guidance.
|
|
5
|
+
|
|
6
|
+
Use when you need to create/update/query Firestore documents, run batch writes,
|
|
7
|
+
troubleshoot missing indexes, or plan migrations.
|
|
8
|
+
|
|
9
|
+
Trigger with phrases like "firestore operations", "create firestore document", "batch
|
|
10
|
+
write", "missing index", or "fix firestore query".
|
|
11
|
+
|
|
12
|
+
'
|
|
7
13
|
allowed-tools: Read, Write, Edit, Grep, Glob, Bash(cmd:*)
|
|
8
14
|
version: 1.0.0
|
|
9
15
|
author: Jeremy Longshore <jeremy@intentsolutions.io>
|
|
10
16
|
license: MIT
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
tags:
|
|
18
|
+
- community
|
|
19
|
+
- migration
|
|
20
|
+
- firestore-operations
|
|
21
|
+
compatibility: Designed for Claude Code, also compatible with Codex and OpenClaw
|
|
13
22
|
---
|
|
14
23
|
# Firestore Operations Manager
|
|
15
24
|
|
|
@@ -53,10 +62,12 @@ Use this skill to design Firestore data access patterns and implement changes wi
|
|
|
53
62
|
## Examples
|
|
54
63
|
|
|
55
64
|
**Example: Fix a failing query**
|
|
65
|
+
|
|
56
66
|
- Request: “This query needs a composite index—what do I add?”
|
|
57
67
|
- Result: the exact index definition and a safer query pattern if needed.
|
|
58
68
|
|
|
59
69
|
**Example: Batch migration**
|
|
70
|
+
|
|
60
71
|
- Request: “Backfill a new field across 100k docs.”
|
|
61
72
|
- Result: batched write strategy, checkpoints, and rollback guidance.
|
|
62
73
|
|
|
@@ -64,4 +75,4 @@ Use this skill to design Firestore data access patterns and implement changes wi
|
|
|
64
75
|
|
|
65
76
|
- Full detailed guide (kept for reference): `${CLAUDE_SKILL_DIR}/references/SKILL.full.md`
|
|
66
77
|
- Firestore docs: https://firebase.google.com/docs/firestore
|
|
67
|
-
- Firestore indexes: https://firebase.google.com/docs/firestore/query-data/indexing
|
|
78
|
+
- Firestore indexes: https://firebase.google.com/docs/firestore/query-data/indexing
|