hasura/graphql-engine · error · errDatabaseNotFound

%w: error determining database kind for '%s', check if datab

Error message

%w: error determining database kind for '%s', check if database exists on hasura

What it means

The metadata export succeeded but the requested source name was not found in the returned metadata (sourceKind == nil), so its kind cannot be determined. It wraps the sentinel errDatabaseNotFound, making it detectable via errors.Is.

Source

Thrown at cli/commands/migrate.go:283

func validateSourceInfo(ec *cli.ExecutionContext) error {
	var op errors.Op = "commands.validateSourceInfo"
	// find out the database kind by making a API call to server
	// and update ec to include the database name and kind
	sourceKind, err := metadatautil.GetSourceKind(
		ec.APIClient.V1Metadata.ExportMetadata,
		ec.Source.Name,
	)
	if err != nil {
		return errors.E(
			op,
			fmt.Errorf("determining database kind of '%s': %w", ec.Source.Name, err),
		)
	}

	if sourceKind == nil {
		return errors.E(
			op,
			fmt.Errorf(
				"%w: error determining database kind for '%s', check if database exists on hasura",
				errDatabaseNotFound,
				ec.Source.Name,
			),
		)
	}

	ec.Source.Kind = *sourceKind

	return nil
}

func databaseChooser(ec *cli.ExecutionContext) error {
	var op errors.Op = "commands.databaseChooser"
	// prompt UI for choosing database if source name is not set
	if ec.Source.Name == "" {
		databaseName, err := metadatautil.DatabaseChooserUI(ec.APIClient.V1Metadata.ExportMetadata)
		if err != nil {

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Run `hasura metadata export` and check sources[].name to confirm the exact source name
  2. Re-add the source (`hasura database add` or metadata apply) if it should exist
  3. Use the correct --database-name matching metadata exactly (case-sensitive)
  4. Point --endpoint at the environment that actually has this database
Defensive patterns

Strategy: validation

Validate before calling

hasura metadata export -o m.json
jq -e --arg n "$DB" '.metadata.sources[] | select(.name==$n)' m.json >/dev/null || echo "source missing"

Try / catch

if errors.Is(err, migrate.ErrDatabaseNotFound) { /* re-add source or fix name */ }

Prevention

When it happens

Trigger: Running migrate commands with --database-name <name> where <name> is not a source in the server's metadata; or the migrations/<name> directory exists locally but the source was removed server-side.

Common situations: Renaming/removing a database in the console but keeping stale local migrations; typo in --database-name; pointing the CLI at a different environment/project than the one where the source was added.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/27439b5dcf6cff78. Report an issue: GitHub.