A TypeScript utility to delete schedules from your Sanity.io project. By default, this tool removes schedules in the 'succeeded' state, but can be configured to delete schedules in other states (scheduled, cancelled). The tool will fetch up to 1000 schedules per execution.
- A Sanity project
- Sanity CLI installed
- Being logged in to Sanity CLI (
sanity login)
- Clone this repository
- Install dependencies:
pnpm install
This script uses sanity exec to run in the context of your Sanity project, which automatically handles authentication and project configuration. The TypeScript code is automatically compiled before execution.
--days=<number>: Specify how many days old a schedule must be to be considered for deletion. Defaults to 90 days if not specified.--dry-run=<boolean>: Whether to run in dry-run mode (default: true).--state=<string>: Filter schedules by state ('succeeded', 'scheduled', or 'cancelled'). Defaults to 'succeeded' if not specified.
To preview which completed schedules would be deleted without actually deleting them:
sanity exec ./deleteSchedules.ts --with-user-token
# Or specify a custom number of days:
sanity exec ./deleteSchedules.ts --with-user-token -- --days=30To perform the actual deletion of completed schedules:
sanity exec ./deleteSchedules.ts --with-user-token -- --dry-run=false
# Or specify a custom number of days:
sanity exec ./deleteSchedules.ts --with-user-token -- --dry-run=false --days=30The script will provide detailed output including:
- Number of schedules found
- Schedule details including:
- Schedule ID
- Document type and ID
- Creation timestamp
- Planned and actual execution times
- Schedule state
- Deletion status for each schedule
- Summary of operations
- Written in TypeScript for better type safety and developer experience
- Dry run mode to safely preview changes
- State filtering (succeeded, scheduled, cancelled)
- Processes up to 1000 schedules per execution
- Uses Sanity CLI for authentication
- Detailed logging of operations
- Continues processing if individual deletions fail