sanity-schema-manager
Manages schema lifecycle including scaffolding, safe field deprecation, and data migrations. Use when modifying existing schemas.
When & Why to Use This Skill
The Sanity Schema Manager is a specialized Claude skill designed to automate and streamline the entire lifecycle of Sanity.io content schemas. It facilitates best-practice scaffolding for document and object types, implements a safe, multi-stage field deprecation workflow, and generates robust data migration scripts. By enforcing consistent coding standards and providing a structured approach to schema evolution, it helps developers maintain clean, scalable, and error-free content structures.
Use Cases
- Automated Schema Scaffolding: Rapidly generate boilerplate code for new Sanity document types, objects, and singletons using standardized defineType and defineField patterns.
- Safe Field Deprecation: Execute a controlled 'ReadOnly -> Hidden -> Deprecated' transition for legacy fields to ensure backward compatibility while guiding users toward new data structures.
- Data Migration Scripting: Automatically generate migration scripts using @sanity/migrate to move data between fields or transform content across large document sets.
- Schema Maintenance and Cleanup: Safely remove obsolete field definitions after verifying data migration completion, preventing accidental data loss during schema refactoring.
| name | sanity-schema-manager |
|---|---|
| description | Manages schema lifecycle including scaffolding, safe field deprecation, and data migrations. Use when modifying existing schemas. |
Schema Manager
This skill handles the lifecycle of Sanity Schema types.
Procedure
Scaffold (Create)
- Use templates to create
document,object, orsingletontypes. - Constraint: Ensure
defineTypeanddefineFieldare used. - Constraint: Ensure an icon is imported from
@sanity/icons.
- Use templates to create
Deprecate (Update)
- Ask: "Which field do you want to deprecate?"
- Action: Apply the "ReadOnly -> Hidden -> Deprecated" pattern to the field definition.
- Output:
defineField({ name: 'oldField', deprecated: { reason: 'Use newField instead' }, readOnly: true, hidden: ({value}) => value === undefined, initialValue: undefined })
Migrate (Data)
- Generate a migration script using
@sanity/migrateor standard client patches. - Template: Iterate over documents ->
patch(doc.id).set({ newField: doc.oldField }).unset(['oldField']).
- Generate a migration script using
Clean (Delete)
- Only allow deleting a field definition if the user confirms "I have migrated the data and the field is undefined in all documents."