Additional utility commands for project management, exposure generation, and code validation.
Refreshes a Lightdash project from its connected remote git repository.
lightdash refresh [options]Options:
--verbose - Enable debug logging (default: false)Usage Examples:
# Refresh active project from git
lightdash refresh
# Refresh with verbose output
lightdash refresh --verboseRequirements:
Behavior:
Use Cases:
Example Workflow:
# Developer pushes changes to git
git add models/
git commit -m "Update customer model"
git push
# Refresh Lightdash to pull changes
lightdash refresh
# Lightdash now reflects git changesError Handling:
Error: "Project not connected to git"
Error: "Git refresh failed"
[EXPERIMENTAL] Generates a dbt exposures YAML file from Lightdash charts and dashboards.
lightdash generate-exposures [options]Options:
--project-dir <path> - dbt project directory (default: .)--output <path> - Output file path (default: <project-dir>/models/lightdash_exposures.yml)--verbose - Enable debug logging (default: false)Usage Examples:
# Generate exposures with defaults
lightdash generate-exposures
# Generate to custom output file
lightdash generate-exposures --output ./exposures/lightdash.yml
# Generate with custom project directory
lightdash generate-exposures --project-dir ./my-dbt-project
# Generate with custom output in custom project
lightdash generate-exposures \
--project-dir ./dbt \
--output ./dbt/models/exposures/lightdash.yml
# Generate with verbose output
lightdash generate-exposures --verboseWhat Are dbt Exposures?
dbt exposures represent downstream uses of dbt models (charts, dashboards, reports). They:
Generated File Format:
# lightdash_exposures.yml
version: 2
exposures:
- name: monthly_revenue_chart
label: Monthly Revenue
type: dashboard
maturity: high
url: https://app.lightdash.cloud/saved/abc-123
description: Track monthly revenue trends
depends_on:
- ref('orders')
- ref('customers')
owner:
name: Analytics Team
email: analytics@example.com
- name: executive_dashboard
label: Executive Dashboard
type: dashboard
maturity: high
url: https://app.lightdash.cloud/dashboards/def-456
description: Key business metrics at a glance
depends_on:
- ref('orders')
- ref('customers')
- ref('products')
owner:
name: Executive Team
email: exec@example.comBehavior:
dbt Version Compatibility:
The command automatically adapts the generated format for dbt 1.10+:
config.tags instead of top-level tagsExposure Details:
Each exposure includes:
Use Cases:
Example Workflow:
# 1. Generate exposures
lightdash generate-exposures
# 2. Review generated file
cat models/lightdash_exposures.yml
# 3. Commit to git
git add models/lightdash_exposures.yml
git commit -m "Add Lightdash exposures"
# 4. Generate dbt docs
dbt docs generate
# 5. View in dbt docs
dbt docs serve
# Navigate to model → "Used By" sectionIntegration with dbt:
After generating exposures:
# Generate dbt docs
dbt docs generate
# Serve docs
dbt docs serve
# In docs UI:
# - Navigate to any model
# - See "Used By" section
# - Shows Lightdash charts/dashboards
# - Click links to view in LightdashLimitations:
Best Practices:
# Daily or weekly regeneration
lightdash generate-exposures
git add models/lightdash_exposures.yml
git commit -m "Update Lightdash exposures"# .github/workflows/update-exposures.yml
name: Update Exposures
on:
schedule:
- cron: '0 0 * * 0' # Weekly
jobs:
update:
steps:
- run: lightdash generate-exposures
- run: git add models/lightdash_exposures.yml
- run: git commit -m "Update exposures" || true
- run: git push# Check output before committing
lightdash generate-exposures
git diff models/lightdash_exposures.ymlValidates Lightdash Code files (YAML) against JSON schemas.
lightdash lint [options]Options:
-p, --path <path> - File or directory to lint (default: current directory)--verbose - Show detailed output (default: false)-f, --format <format> - Output format: cli or json (SARIF) (default: cli)Usage Examples:
# Lint current directory
lightdash lint
# Lint specific directory
lightdash lint --path ./lightdash
# Lint specific file
lightdash lint --path ./lightdash/charts/revenue.yml
# Lint with verbose output
lightdash lint --verbose
# Lint with JSON output (SARIF format)
lightdash lint --format json
# Lint and save JSON output
lightdash lint --format json > lint-results.sarif.jsonFile Types Validated:
Models:
modelmodel/v1, model/v1betaCharts:
1metricQuery fieldDashboards:
1tiles fieldValidation Checks:
CLI Output Format:
lightdash lint --path ./lightdashSuccess Output:
Linting ./lightdash...
✓ charts/monthly-revenue.yml - Valid
✓ charts/customer-segmentation.yml - Valid
✓ dashboards/executive-dashboard.yml - Valid
3 files validated, 0 errorsError Output:
Linting ./lightdash...
✓ charts/monthly-revenue.yml - Valid
✗ charts/order-analysis.yml - Invalid
Error: Missing required field 'metricQuery.exploreName'
Line 5, column 3
✗ dashboards/sales-dashboard.yml - Invalid
Error: Invalid value for 'version'. Expected '1', got '2'
Line 1, column 10
1 valid, 2 errors foundJSON Output Format (SARIF):
lightdash lint --format jsonOutputs SARIF (Static Analysis Results Interchange Format):
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "Lightdash Lint",
"version": "0.2231.0"
}
},
"results": [
{
"ruleId": "schema-validation",
"level": "error",
"message": {
"text": "Missing required field 'metricQuery.exploreName'"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "charts/order-analysis.yml"
},
"region": {
"startLine": 5,
"startColumn": 3
}
}
}
]
}
]
}
]
}Use Cases:
# Git pre-commit hook
#!/bin/bash
if ! lightdash lint --path ./lightdash; then
echo "Lint errors found. Fix before committing."
exit 1
finame: Validate Lightdash Code
on:
pull_request:
paths:
- 'lightdash/**'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Lightdash CLI
run: npm install -g @lightdash/cli
- name: Lint Lightdash Code
run: lightdash lint --path ./lightdash
- name: Generate SARIF Report
if: always()
run: lightdash lint --path ./lightdash --format json > results.sarif.json
- name: Upload SARIF
if: always()
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: results.sarif.json# Before uploading
lightdash lint --path ./lightdash
# If valid, upload
if [ $? -eq 0 ]; then
lightdash upload --path ./lightdash
else
echo "Fix lint errors before uploading"
exit 1
fi# Daily validation
0 6 * * * cd /project && lightdash lint --path ./lightdash >> /var/log/lint.log 2>&1Common Validation Errors:
# Error: Missing 'exploreName'
metricQuery:
dimensions:
- orders_order_date
# Fix: Add exploreName
metricQuery:
exploreName: orders
dimensions:
- orders_order_date# Error: 'version' must be number, not string
version: "1"
# Fix: Use number
version: 1# Error: Invalid chart type
chartConfig:
type: invalid_type
# Fix: Use valid type
chartConfig:
type: cartesian# Error: Invalid YAML syntax
metricQuery:
exploreName orders # Missing colon
# Fix: Add colon
metricQuery:
exploreName: ordersExit Codes:
CI/CD Integration:
# Fail pipeline on lint errors
lightdash lint --path ./lightdash
if [ $? -ne 0 ]; then
echo "Lint failed!"
exit 1
fiSARIF Integration:
SARIF output integrates with:
GitHub Code Scanning Example:
- name: Lint
run: lightdash lint --format json > results.sarif.json
- name: Upload to GitHub
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: results.sarif.jsonResult: Lint errors appear as annotations in pull requests.
Best Practices:
# Add to .git/hooks/pre-commit
lightdash lint --path ./lightdash# Always lint in pipelines
steps:
- run: lightdash lint# When errors are unclear
lightdash lint --verbose# Create reports for review
lightdash lint --format json > report.sarif.json# Validate downloaded content
lightdash download --path ./lightdash
lightdash lint --path ./lightdashRefresh:
Deploy:
Generate Exposures:
Download:
Lint:
Validate:
Error: "Project not connected to git"
lightdash deploy insteadError: "Git authentication failed"
Error: "No charts or dashboards found"
Error: "Cannot write to output path"
Error: "Invalid YAML syntax"
Error: "Schema validation failed"
Error: "File not found"
Required permissions:
Required permissions:
Required permissions:
# Weekly cron job
0 0 * * 0 lightdash generate-exposures && git add models/lightdash_exposures.yml && git commit -m "Update exposures" && git push# Validation pipeline
lightdash lint --path ./lightdash && lightdash upload --path ./lightdash# After git push
git push origin main
lightdash refresh# VS Code task
{
"label": "Lint Lightdash",
"type": "shell",
"command": "lightdash lint --path ./lightdash",
"problemMatcher": []
}# dbt Project
## Lightdash Exposures
Lightdash exposures are auto-generated weekly:
- File: `models/lightdash_exposures.yml`
- Command: `lightdash generate-exposures`
- View in dbt docs: `dbt docs serve`#!/bin/bash
# .git/hooks/pre-commit
echo "Linting Lightdash Code..."
if ! lightdash lint --path ./lightdash; then
echo "❌ Lint failed. Fix errors before committing."
exit 1
fi
echo "✓ Lint passed".PHONY: lint exposures refresh
lint:
lightdash lint --path ./lightdash
exposures:
lightdash generate-exposures
git add models/lightdash_exposures.yml
refresh:
lightdash refresh
lightdash validate
all: lint exposures refresh{
"scripts": {
"lightdash:lint": "lightdash lint --path ./lightdash",
"lightdash:exposures": "lightdash generate-exposures",
"lightdash:refresh": "lightdash refresh",
"lightdash:validate": "lightdash lint && lightdash validate"
}
}