firestore-safety

Guides safe read and write operations on Firestore documents to prevent data loss.

Updated May 6, 2026
One-click install
npx skills add https://github.com/BanePlayss/primitivao --skill firestore-safety-baneplayss
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: firestore-safety
Source: https://github.com/BanePlayss/primitivao/tree/main/.opencode/skills/firestore-safety
Command: npx skills add https://github.com/BanePlayss/primitivao --skill firestore-safety-baneplayss

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Firestore writes to the Primitivão betting app have repeatedly caused data-loss scares: transient onSnapshot snapshots treated as resets, set() calls without merge wiping sibling fields, and reducers writing unwrapped state. This Skill encodes every known landmine so persistence code changes stop destroying production data. ## Core Features & Use Cases - Write-path discipline: Documents the commitBetDocUpdate reducer contract, including the { next } unwrapping rule and the protectMap guard that refuses to overwrite populated users/teamPlayers maps with empty objects. - Snapshot safety rules: Explains how to handle transient exists=false snapshots using hasLoadedRef checks and snap.metadata.fromCache so reconnects never trigger a fake reset or reseed. - Backup, restore, and wipe safeguards: Requires backups before restoreFromBackup or wipeAllData, merge:true on all top-level field writes, and Firestore security rules (delete: if false, notWipingJson shrink guard) verified as published in the Firebase Console. - Use Case: Before modifying the onSnapshot loader for the apostas document, consult this Skill to confirm the correct handling of cache snapshots and avoid recreating the document on a transient read. ## Quick Start Review the firestore-safety guidelines before I modify commitBetDocUpdate or any onSnapshot loader in the betting app.

Frequently Asked Questions about firestore-safety

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely update a Firestore document without losing data?▼

Route every write through a single reducer helper and always use set with { merge: true } so sibling top-level fields are preserved. Never write the raw reducer output; unwrap the next field first, and guard against overwriting populated maps with empty objects.

Why does Firestore onSnapshot return exists false and how to handle it?▼

A snapshot can transiently report exists=false during first connection, offline-to-online reconnects, or rule evaluation. If real data already loaded, ignore it; if snap.metadata.fromCache is true, create nothing and wait. Only create the document when the server confirms absence, using merge:true.

Does Firestore set without merge delete other fields?▼

Yes. Calling set without { merge: true } replaces the entire document, deleting sibling top-level fields such as news or webhook data. Always pass merge:true when writing individual top-level fields alongside a main JSON payload.

How do I back up Firestore data before a wipe or restore?▼

Run a full backup covering both the JSON payload and all top-level fields before any restoreFromBackup or wipeAllData call, and abort the operation if the backup fails. Restrict these destructive operations to an admin panel only.

Can Firestore security rules prevent accidental data deletion?▼

Yes. Rules like delete: if false block document deletion, and a shrink guard can reject writes that reduce the JSON payload below a threshold of its previous size. Rules only protect data if actually published in the Firebase Console, not just present in the repo.