CLI reference

Schema

List, validate, extract, and deploy schema.

Available commands

usage: npx sanity schema [--default] [-v|--version] [-d|--debug] [-h|--help] <command> [<args>]

Commands:
   delete    Delete schemas by their IDs.
   deploy    Deploy schemas into workspace datasets.
   extract   Extracts a JSON representation of a Sanity schema within a Studio context.
   list      Lists all schemas in the current dataset.
   validate  Validates all schema types specified in a workspace.

See 'sanity help schema <command>' for specific information on a subcommand.

Delete a schema

usage: npx sanity schema delete 

   Delete schemas by their IDs.

Options
  --ids <schema_id_1,schema_id_2,...> comma-separated list of schema IDs to delete
  --dataset <dataset_name> delete schemas from a specific dataset
  --manifest-dir <directory> directory containing your manifest file if it's not in the default location
  --no-extract-manifest disables manifest generation – the command will fail if no manifest exists

Examples
  # Delete single schema
  sanity schema delete --ids <schema_id>

  # Delete multiple schemas
  sanity schema delete --ids <schema_id_1,schema_id_2,...>

Deploy schemas

usage: npx sanity schema deploy 

   Deploy schemas into workspace datasets.

Options:
  --workspace <workspace_name> deploy schema for a specific workspace
  --manifest-dir <directory> directory containing your manifest file if it's not in the default location
  --no-extract-manifest disables manifest generation – the command will fail if no manifest exists
  --id-prefix <prefix> add a prefix to the schema ID
  --schema-required fail if schema file is not found
  --verbose print detailed information during store

Examples
  # if no options are provided all workspace schemas will be deployed
  sanity schema deploy
  # Deploy the schema for only the workspace 'default'
  sanity schema deploy --workspace default

Extract a schema

usage: npx sanity schema extract

   Extracts a JSON representation of a Sanity schema within a Studio context.

**Note**: This command is experimental and subject to change.

Options
  --workspace <name> The name of the workspace to generate a schema for
  --path Optional path to specify destination of the schema file
  --enforce-required-fields Makes the schema generated treat fields marked as required as non-optional. Defaults to false.
  --format=[groq-type-nodes] Format the schema as GROQ type nodes. Only available format at the moment.

Examples
  # Extracts schema types in a Sanity project with more than one workspace
  sanity schema extract --workspace default

List schemas

usage: npx sanity schema list 

   Lists all schemas in the current dataset.

Options
  --json get schemas as json
  --id <schema_id> fetch a specific schema by its ID
  --manifest-dir <directory> directory containing your manifest file if it's not in the default location
  --no-extract-manifest disables manifest generation – the command will fail if no manifest exists

Examples
  # Get full json schemas
  sanity schema list --json

  # Get a specific schema by ID
  sanity schema list --id <schema_id>

Validate a schema

usage: npx sanity schema validate

  Validates all schema types specified in a workspace.

Options
  --workspace <name> The name of the workspace to use when validating all schema types.
  --format <pretty|ndjson|json> The output format used to print schema errors and warnings.
  --level <error|warning> The minimum level reported out. Defaults to warning.

Examples
  # Validates all schema types in a Sanity project with more than one workspace
  sanity schema validate --workspace default

  # Save the results of the report into a file
  sanity schema validate > report.txt

  # Report out only errors
  sanity schema validate --level error

Was this page helpful?