CLI reference
Schemas CLI command reference
List, validate, extract, and deploy schema.
Available commands
npx sanity schemas --help
pnpm dlx sanity schemas --help
yarn dlx sanity schemas --help
bunx sanity schemas --help
Commands
delete
USAGE
$ sanity schemas delete [-d <name>] [-p <id>] --ids <value> [--verbose]
FLAGS
-d, --dataset=<name> Delete schemas from a specific dataset
--ids=<value> Comma-separated list of schema ids to delete
--verbose Enable verbose logging
OVERRIDE FLAGS
-p, --project-id=<id> Project ID to delete schema from (overrides CLI configuration)
DESCRIPTION
Delete schema documents by id
EXAMPLES
Delete a single schema
$ sanity schemas delete --ids sanity.workspace.schema.workspaceName
Delete multiple schemas
$ sanity schemas delete --ids sanity.workspace.schema.workspaceName,prefix.sanity.workspace.schema.otherWorkspacedeploy
USAGE
$ sanity schemas deploy [--extract-manifest] [--manifest-dir <directory>] [--tag <tag>] [--verbose] [--workspace <name>]
FLAGS
--extract-manifest Disables manifest generation - the command will fail if no manifest exists
--manifest-dir=<directory> Directory containing manifest file
--tag=<tag> Add a tag suffix to the schema id
--verbose Print detailed information during deployment
--workspace=<name> The name of the workspace to deploy a schema for
DESCRIPTION
Deploy schema documents into workspace datasets.
**Note**: This command is experimental and subject to change.
This operation (re-)generates a manifest file describing the sanity config workspace by default.
To re-use an existing manifest file, use --no-extract-manifest.
EXAMPLES
Deploy all workspace schemas
$ sanity schemas deploy
Deploy the schema for only the workspace "default"
$ sanity schemas deploy --workspace defaultextract
USAGE
$ sanity schemas extract [--enforce-required-fields] [--format <format>] [--path <value>] [--watch] [--watch-patterns <glob>] [--workspace <name>]
FLAGS
--enforce-required-fields Makes the schema generated treat fields marked as required as non-optional
--format=<format> Format the schema as GROQ type nodes. Only available format at the moment.
--path=<value> Optional path to specify destination of the schema file
--watch Enable watch mode to re-extract schema on file changes
--watch-patterns=<glob> Additional glob pattern(s) to watch (can be specified multiple times)
--workspace=<name> The name of the workspace to generate a schema for
DESCRIPTION
Extracts a JSON representation of a Sanity schema within a Studio context.
**Note**: This command is experimental and subject to change.
EXAMPLES
Extracts schema types in a Sanity project with more than one workspace
$ sanity schemas extract --workspace default
Watch mode - re-extract on changes
$ sanity schemas extract --watch
Watch with custom glob patterns
$ sanity schemas extract --watch --watch-patterns "lib/**/*.ts"list
USAGE
$ sanity schemas list [--id <schema_id>] [--json]
FLAGS
--id=<schema_id> Fetch a single schema by id
--json Get schema as json
DESCRIPTION
Lists all schemas in the current dataset.
**Note**: This command is experimental and subject to change.
This operation (re-)generates a manifest file describing the sanity config workspace by default.
To re-use an existing manifest file, use --no-extract-manifest.
EXAMPLES
List all schemas found in any workspace dataset in a table
$ sanity schemas list
Get a schema for a given id
$ sanity schemas list --id _.schemas.workspaceName
Get stored schemas as pretty-printed json-array
$ sanity schemas list --json
Get singular stored schema as pretty-printed json-object
$ sanity schemas list --json --id _.schemas.workspaceNamevalidate
USAGE
$ sanity schemas validate [--debug-metafile-path <value>] [--format <value>] [--level <value>] [--workspace <value>]
FLAGS
--format=<value> The output format used to print schema errors and warnings
--level=<value> The minimum level reported out
--workspace=<value> The name of the workspace to use when validating all schema types
DEBUG FLAGS
--debug-metafile-path=<value> Optional path where a metafile will be written for build analysis. Only written on successful validation. Can be analyzed at https://esbuild.github.io/analyze/
DESCRIPTION
Validates all schema types specified in a workspace
EXAMPLES
Validates all schema types in a Sanity project with more than one workspace
$ sanity schemas validate --workspace default
Save the results of the report into a file
$ sanity schemas validate > report.txt
Report out only errors
$ sanity schemas validate --level error
Generate a report which can be analyzed with https://esbuild.github.io/analyze/
$ sanity schemas validate --debug-metafile-path metafile.json