HASURA - nself-org/cli GitHub Wiki
Deprecated.
nself hasurahas moved tonself db hasura.# Old (deprecated โ removed in v1.0.0) nself hasura console nself hasura metadata apply # New nself db hasura console nself db hasura metadata apply
Version: v0.9.9
Status: Deprecated โ use nself db hasura
Hasura GraphQL management commands for metadata operations and console access. These commands are now part of nself db hasura since Hasura management is database-adjacent (metadata tracks schema, permissions, and relationships). This page is kept for reference โ see DB.md for the current documentation.
nself db hasura <subcommand> [options]| Subcommand | Description |
|---|---|
metadata apply |
Apply metadata to Hasura |
metadata export |
Export metadata from Hasura |
metadata reload |
Reload metadata cache |
console |
Open Hasura Console |
help |
Show help information |
For metadata apply, metadata export, and console commands with CLI features:
# Install globally
npm install -g hasura-cli
# Verify installation
hasura versionNote: The metadata reload command uses curl and doesn't require Hasura CLI.
Apply local metadata to Hasura instance.
nself db hasura metadata applyRequirements:
- Hasura CLI installed
-
HASURA_GRAPHQL_ADMIN_SECRETset in environment - Metadata files in
hasura/metadata/directory
What it does:
- Reads
HASURA_GRAPHQL_ADMIN_SECRETfrom environment - Determines Hasura endpoint from config
- Auto-generates
hasura/config.yamlif missing (see Config File Auto-Generation below) - Applies metadata from local directory using
--projectand--endpointflags
Example:
nself db hasura metadata applyExport metadata from Hasura instance to local files.
nself db hasura metadata exportRequirements:
- Hasura CLI installed
-
HASURA_GRAPHQL_ADMIN_SECRETset in environment
What it does:
- Connects to Hasura instance
- Exports all metadata (tables, relationships, permissions, etc.)
- Saves to
hasura/metadata/directory
Example:
nself db hasura metadata exportReload Hasura metadata cache without restarting.
nself db hasura metadata reloadRequirements:
-
HASURA_GRAPHQL_ADMIN_SECRETset in environment - Hasura service running
What it does:
- Sends API request to Hasura
- Triggers metadata cache reload
- No service restart required
Example:
nself db hasura metadata reloadUse cases:
- After database schema changes
- After modifying tracked tables
- To refresh stale metadata cache
Open Hasura Console in browser.
nself db hasura consoleWith Hasura CLI:
- Opens Hasura CLI console (with migration tracking)
- Automatically authenticates with admin secret
- Changes are tracked in metadata files
Without Hasura CLI:
- Prints URL to web console
- Manual navigation required
Examples:
# Open console
nself db hasura console
# Or access directly at
# http://localhost:8080/consoleThe Hasura CLI v2 requires a config.yaml file even when --endpoint and --admin-secret are passed as flags. It uses config.yaml to locate the metadata_directory.
nself db hasura metadata apply, metadata export, and console all call ensure_hasura_config before running any Hasura CLI command. This function:
- Checks for
HASURA_PROJECT_DIRenv var, then falls back to looking forhasura/in the current directory - Creates
hasura/config.yamlif the directory exists but the file is missing - Never overwrites an existing
config.yaml
The generated file sets metadata_directory: metadata and the Hasura endpoint. The admin secret is intentionally NOT written to the file โ it is passed as --admin-secret on the CLI invocation so no secret lands on disk.
If your hasura directory is not at hasura/ relative to where you run nself commands, set HASURA_PROJECT_DIR=<path> in your .env.
nself build also runs this step, so after a build the file will always be present before you run any hasura commands.
The command automatically reads:
| Variable | Description | Default |
|---|---|---|
HASURA_GRAPHQL_ENDPOINT |
Hasura API endpoint | http://localhost:8080 |
HASURA_PORT |
Hasura port | 8080 |
HASURA_GRAPHQL_ADMIN_SECRET |
Admin secret for authentication | (required) |
HASURA_PROJECT_DIR |
Path to hasura project directory (contains config.yaml and metadata/) | hasura |
HASURA_PORT=8080
HASURA_GRAPHQL_ADMIN_SECRET=your-secret-key-here
HASURA_GRAPHQL_ENDPOINT=http://localhost:8080# 1. Make changes in Hasura Console
nself db hasura console
# 2. Export metadata after changes
nself db hasura metadata export
# 3. Commit metadata to git
git add hasura/metadata/
git commit -m "Add users table and permissions"
# 4. Apply to another environment
nself db hasura metadata apply# After running database migration
nself db migrate
# Reload Hasura metadata
nself db hasura metadata reload# Export current state
nself db hasura metadata export
# Clear and reapply
nself db hasura metadata applyhasura/
โโโ metadata/
โโโ actions.graphql
โโโ actions.yaml
โโโ allow_list.yaml
โโโ cron_triggers.yaml
โโโ databases/
โ โโโ default/
โ โโโ tables/
โ โโโ public_users.yaml
โ โโโ public_posts.yaml
โโโ query_collections.yaml
โโโ remote_schemas.yaml
โโโ version.yaml
- Metadata commands read from cascading environment files
- Admin secret is required for all operations
- Console access requires Hasura service to be running
- Metadata files should be version controlled
- Always test metadata changes in staging first
# Error: HASURA_GRAPHQL_ADMIN_SECRET not set
# Solution: Set in environment
echo "HASURA_GRAPHQL_ADMIN_SECRET=your-secret" >> .env
nself restart hasura# Error: Hasura CLI not found
# Solution: Install CLI
npm install -g hasura-cli
# Or access console directly
nself urls | grep hasura
# Open console URL in browser# Check Hasura is running
nself status hasura
# Check endpoint
nself config env | grep HASURA
# Restart service
nself restart hasura# Export current metadata first
nself db hasura metadata export
# Check for conflicts
diff -r hasura/metadata/ /path/to/backup/
# Apply with verbose output
hasura metadata apply --endpoint http://localhost:8080 --admin-secret $HASURA_GRAPHQL_ADMIN_SECRETDocumentation: https://hasura.io/docs/latest/graphql/core/migrations/index.html
Category: Core Services