Create temporary preview projects for testing changes before deploying to production.
Creates a temporary preview project, watches for changes, and waits for user input to cleanup.
lightdash preview [options]Inherits all compilation options (see dbt Compilation), plus:
Preview Configuration:
--name <preview name> - Custom preview name (default: random name)--vars <vars> - dbt variables as JSON string--start-of-week <number> - First day of week for date functions: 0 (Monday) to 6 (Sunday)--use-dbt-list [true|false] - Use dbt list instead of dbt compile to generate manifest (default: true)--ignore-errors - Deploy with compilation errors (default: false)--table-configuration <prod|all> - Copy table configuration from production (default: 'all')--skip-copy-content - Don't copy content from source project (default: false)--disable-timestamp-conversion [true|false] - Disable timestamp conversion to UTC for Snowflake warehouses (default: false)--organization-credentials <name> - Use organization warehouse credentials (Enterprise Edition feature)Note: The source code contains a duplicate definition of --disable-timestamp-conversion in the preview command (lines 471-475 and 481-485 in index.ts). This appears to be a copy-paste error in the source code.
Usage Examples:
# Create preview with random name (interactive mode)
lightdash preview
# Create preview with custom name
lightdash preview --name feature-123
# Create preview for specific models
lightdash preview --name test-orders --select orders
# Create preview without copying content
lightdash preview --skip-copy-content
# Create preview with table configuration from prod only
lightdash preview --table-configuration prod
# Create preview with start of week setting
lightdash preview --start-of-week 6 # Sunday
# Create preview with organization credentials
lightdash preview --organization-credentials "prod-warehouse"
# Create preview with custom dbt directories
lightdash preview --project-dir ./dbt --profiles-dir ./profilesBehavior:
target/manifest.json for changesCreates or updates a preview project without watching for changes (CI-friendly).
lightdash start-preview --name <name> [options]Inherits all compilation options (see dbt Compilation), plus:
Preview Configuration:
--name [preview name] - [REQUIRED] Preview name (alphanumeric, hyphens, underscores)--vars <vars> - dbt variables as JSON string--start-of-week <number> - First day of week for date functions: 0-6--use-dbt-list [true|false] - Use dbt list instead of dbt compile (default: true)--ignore-errors - Deploy with compilation errors (default: false)--table-configuration <prod|all> - Copy table configuration from production (default: 'all')--skip-copy-content - Don't copy content from source project (default: false)--disable-timestamp-conversion [true|false] - Disable timestamp conversion to UTC for Snowflake warehouses (default: false)Note: Unlike the preview command, start-preview does NOT support --organization-credentials. Use the regular preview command if you need organization credentials.
Usage Examples:
# Create or update preview (CI mode)
lightdash start-preview --name pr-123
# Create preview for specific models
lightdash start-preview --name feature-customers --select customers
# Create preview without content copy
lightdash start-preview --name clean-preview --skip-copy-content
# Create preview with only prod table config
lightdash start-preview --name test --table-configuration prod
# CI/CD: Create preview with environment variables
export CI=true
export LIGHTDASH_API_KEY="token"
lightdash start-preview --name ci-previewCI/CD Integration:
When CI=true, sets GitHub Actions outputs:
url - Preview project URLproject_uuid - Preview project UUIDBehavior:
preview)stop-preview to delete)Deletes a preview project by name.
lightdash stop-preview --name <name>Options:
--name [preview name] - [REQUIRED] Preview name to delete--verbose - Enable debug logging (default: false)Usage Examples:
# Delete preview by name
lightdash stop-preview --name feature-123
# Delete preview with verbose output
lightdash stop-preview --name test-preview --verbose
# CI/CD: Delete preview after testing
lightdash stop-preview --name pr-${PR_NUMBER}Behavior:
Error Handling:
# 1. Make changes to dbt models
vim models/customers.sql
# 2. Create preview environment
lightdash preview --name test-customers
# Preview URL displayed:
# https://app.lightdash.cloud/projects/preview-abc-123
# 3. CLI watches for changes
# Make more changes to models...
# 4. Changes auto-deploy to preview
# Review changes in browser
# 5. Press ENTER when done
# Preview is automatically cleaned up# In pull request workflow:
# 1. Start preview
lightdash start-preview --name pr-${PR_NUMBER}
# 2. Run tests against preview
lightdash validate --preview
# 3. Post preview URL to PR comments
# (Use GitHub Actions outputs)
# 4. On PR close, cleanup preview
lightdash stop-preview --name pr-${PR_NUMBER}--project)[Preview] <name>Controlled by --skip-copy-content and --table-configuration:
With content copy (default):
With --skip-copy-content:
Table configuration modes:
all (default) - Copy all table configurationsprod - Copy only production table configurationsSaves to ~/.config/lightdash/config.yaml:
context:
previewProject: preview-uuid
previewName: preview-nameThe preview command watches for changes and auto-redeploys:
Watched File:
target/manifest.json (or custom --target-path)Triggers Redeployment:
How to Trigger:
# In another terminal, run dbt commands:
dbt compile
dbt run
# Preview automatically detects changes and redeploysStop Watching:
previewWhen --name not provided:
lightdash preview
# Creates: preview-1234567890 (random)Valid characters:
Examples:
# Good names
lightdash preview --name feature-123
lightdash preview --name test_orders
lightdash preview --name pr-456
# Invalid names (will error)
lightdash preview --name "Feature 123" # spaces
lightdash preview --name Feature-123 # uppercase
lightdash preview --name feature/123 # slashesIf preview name already exists:
preview - Creates with different random namestart-preview - Updates existing previewControls what table configuration is copied from source project:
lightdash preview --table-configuration allCopies:
Use when:
lightdash preview --table-configuration prodCopies:
Use when:
Prevent copying charts and dashboards:
lightdash preview --skip-copy-contentResult:
Use when:
Preview commands inherit all compilation options:
# Preview only specific models
lightdash preview --select customers orders
# Preview models with tag
lightdash preview --select tag:staging
# Preview with exclusions
lightdash preview --exclude test_*
# Use predefined dbt selector
lightdash preview --selector my_selector# Use state directory for state-based selection
lightdash preview --state ./prod-state
# Defer to production for unselected nodes
lightdash preview --state ./prod-state --defer
# Don't defer (compile everything)
lightdash preview --state ./prod-state --no-defer
# Preview only modified models
lightdash preview --state ./prod-state --select state:modified+ --defer# Use more threads for faster compilation
lightdash preview --threads 8
# Skip dbt version check
lightdash preview --no-version-check
# Full refresh for incremental models
lightdash preview --full-refresh# Skip warehouse catalog
lightdash preview --skip-warehouse-catalog
# Use existing manifest
lightdash preview --skip-dbt-compile
# Both (fastest)
lightdash preview --no-warehouse-credentials# Custom directories
lightdash preview --project-dir ./dbt --profiles-dir ./profiles
# Custom target
lightdash preview --target staging
# dbt variables
lightdash preview --vars '{"env": "dev"}'name: Lightdash Preview
on:
pull_request:
types: [opened, synchronize]
jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install Lightdash CLI
run: npm install -g @lightdash/cli
- name: Create Preview
id: preview
env:
LIGHTDASH_API_KEY: ${{ secrets.LIGHTDASH_API_KEY }}
LIGHTDASH_PROJECT: ${{ secrets.LIGHTDASH_PROJECT }}
CI: true
run: lightdash start-preview --name pr-${{ github.event.pull_request.number }}
- name: Comment PR
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Preview ready: ${{ steps.preview.outputs.url }}`
})name: Cleanup Preview
on:
pull_request:
types: [closed]
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Install Lightdash CLI
run: npm install -g @lightdash/cli
- name: Stop Preview
env:
LIGHTDASH_API_KEY: ${{ secrets.LIGHTDASH_API_KEY }}
CI: true
run: lightdash stop-preview --name pr-${{ github.event.pull_request.number }}Controls first day of week for week-related date functions:
--start-of-week <number>Values:
0 - Monday1 - Tuesday2 - Wednesday3 - Thursday4 - Friday5 - Saturday6 - SundayUsage:
# Monday as first day
lightdash preview --start-of-week 0
# Sunday as first day
lightdash preview --start-of-week 6Affects:
Enterprise Edition feature for using shared warehouse credentials:
--organization-credentials <name>Usage:
# Use org credentials
lightdash preview --organization-credentials "dev-warehouse"Benefits:
Requirements:
Test preview before merging:
# 1. Create preview
lightdash start-preview --name test-feature
# 2. Validate preview
lightdash validate --preview
# 3. Check specific elements
lightdash validate --preview --only charts dashboards
# 4. If valid, deploy to production
lightdash deploy
# 5. Cleanup preview
lightdash stop-preview --name test-featureRequired permissions:
Required permissions:
Error if insufficient permissions:
ForbiddenError: You don't have permission to delete this projectExit Code 0: Preview command succeeded Exit Code 1: Preview command failed
Success Output (preview):
✓ Created preview project: feature-123
✓ Preview URL: https://app.lightdash.cloud/projects/abc-123
Watching for changes... (Press ENTER to stop)Success Output (start-preview):
✓ Created preview project: pr-456
✓ Preview URL: https://app.lightdash.cloud/projects/def-789
✓ Project UUID: def-789Success Output (stop-preview):
✓ Deleted preview project: feature-123Error: "Failed to create preview"
--verbose for detailsError: "Preview project not found"
Issue: Changes not detected
dbt compile manuallyError: "Failed to copy content"
--skip-copy-content as alternativeError: "Invalid preview name"
Good naming conventions:
# Feature branches
lightdash preview --name feature-user-auth
# Bug fixes
lightdash preview --name fix-orders-bug
# Pull requests
lightdash preview --name pr-123Don't leave previews running:
# After testing, always cleanup
lightdash stop-preview --name feature-123Use preview workflow:
# 1. Create preview
lightdash preview --name test-changes
# 2. Review in browser
# 3. Validate
lightdash validate --preview
# 4. If good, deploy
lightdash deploy
# 5. Cleanup preview (automatic with interactive preview)Automate preview creation:
# On pull request, create preview
# Post URL to PR
# On PR merge, cleanup previewPreview only changed models:
# If changing orders model
lightdash preview --name test-orders --select orders
# Faster preview creation
# Focused testingWhen testing models only:
# Skip content copy for faster preview
lightdash preview --skip-copy-contentAlways validate previews:
lightdash validate --preview --only tables