Documentation Index
Fetch the complete documentation index at: https://grantmaster.dev/llms.txt
Use this file to discover all available pages before exploring further.
Data Migrations & Schema Evolution
Because Firestore is schemaless, managing data evolution requires a specific strategy to ensure the application doesn’t crash when encountering legacy document structures.1. Migration Strategy: “Lazy” vs. “Eager”
Lazy Migration (Preferred)
Instead of running a script across millions of documents, we migrate data on-read.- Frontend/Service reads a document.
- A
Zodschema with.default()or.transform()handles the legacy structure. - The next time the document is saved, it is written in the new format.
Eager Migration (Bulk)
Required for searchable fields or major re-architecting.- Tool: Custom scripts in
scripts/migrations/. - Pattern:
- Always use batches (limit 500 operations per batch).
- Use
transactionif atomicity is required. - Log every migrated record to a temporary CSV for audit verification.
2. Standard Migration Script Template
3. Breaking Changes Checklist
Before changing a key field in a major collection:- Update the owning schema or feature contract module.
- Update the Zod schema in
src/schemas/. - Add a fallback in the Zod schema for legacy data.
- Search codebase for direct Firestore queries using the old field name and update them.
- Update Firestore Security Rules if the field is used for
allowconditions. - Update Firestore Indexes if the field is indexed.
Maintenance
Update this document when:- Establishing a new standardized migration tool.
- Changing the batch size limit (e.g., if switching to a different database).
- Introducing a formal schema registry.