LogoLogo
HomeAPIBlog
3.0.0-SNAPSHOT
3.0.0-SNAPSHOT
  • INTRODUCTION
    • Getting Started
      • Running Local Development Servers
      • Beginner Tutorial: Hello World
      • Beginner Tutorial: Hello Database
      • Tutorial: Wheels, AJAX, and You
    • Frameworks and Wheels
    • Requirements
    • Manual Installation
    • Upgrading
    • Screencasts
  • Command Line Tools
    • CLI Overview
    • Quick Start Guide
    • Command Reference
      • Core Commands
        • wheels init
        • wheels info
        • wheels reload
        • wheels deps
        • wheels destroy
        • wheels watch
      • Code Generation
        • wheels generate app
        • wheels generate app-wizard
        • wheels generate controller
        • wheels generate model
        • wheels generate view
        • wheels generate property
        • wheels generate route
        • wheels generate resource
        • wheels generate api-resource
        • wheels generate frontend
        • wheels generate test
        • wheels generate snippets
        • wheels scaffold
      • Database Commands
        • wheels dbmigrate info
        • wheels dbmigrate latest
        • wheels dbmigrate up
        • wheels dbmigrate down
        • wheels dbmigrate reset
        • wheels dbmigrate exec
        • wheels dbmigrate create blank
        • wheels dbmigrate create table
        • wheels dbmigrate create column
        • wheels dbmigrate remove table
        • wheels db schema
        • wheels db seed
      • Testing Commands
        • wheels test
        • wheels test run
        • wheels test coverage
        • wheels test debug
      • Configuration Commands
        • wheels config list
        • wheels config set
        • wheels config env
      • Environment Management
        • wheels env
        • wheels env setup
        • wheels env list
        • wheels env switch
      • Plugin Management
        • wheels plugins
        • wheels plugins list
        • wheels plugins install
        • wheels plugins remove
      • Code Analysis
        • wheels analyze
        • wheels analyze code
        • wheels analyze performance
        • wheels analyze security
      • Security Commands
        • wheels security
        • wheels security scan
      • Performance Commands
        • wheels optimize
        • wheels optimize performance
      • Documentation Commands
        • wheels docs
        • wheels docs generate
        • wheels docs serve
      • CI/CD Commands
        • wheels ci init
      • Docker Commands
        • wheels docker init
        • wheels docker deploy
      • Deployment Commands
        • wheels deploy
        • wheels deploy audit
        • wheels deploy exec
        • wheels deploy hooks
        • wheels deploy init
        • wheels deploy lock
        • wheels deploy logs
        • wheels deploy proxy
        • wheels deploy push
        • wheels deploy rollback
        • wheels deploy secrets
        • wheels deploy setup
        • wheels deploy status
        • wheels deploy stop
    • CLI Development Guides
      • Creating Commands
      • Service Architecture
      • Migrations Guide
      • Testing Guide
  • Working with Wheels
    • Conventions
    • Configuration and Defaults
    • Directory Structure
    • Switching Environments
    • Testing Your Application
    • Using the Test Environment
    • Contributing to Wheels
    • Submitting Pull Requests
    • Documenting your Code
  • Handling Requests with Controllers
    • Request Handling
    • Rendering Content
    • Redirecting Users
    • Sending Files
    • Sending Email
    • Responding with Multiple Formats
    • Using the Flash
    • Using Filters
    • Verification
    • Event Handlers
    • Routing
    • URL Rewriting
      • Apache
      • IIS
      • Tomcat
      • Nginx
    • Obfuscating URLs
    • Caching
    • Nesting Controllers
    • CORS Requests
  • Displaying Views to Users
    • Pages
    • Partials
    • Linking Pages
    • Layouts
    • Form Helpers and Showing Errors
    • Displaying Links for Pagination
    • Date, Media, and Text Helpers
    • Creating Custom View Helpers
    • Localization
  • Database Interaction Through Models
    • Object Relational Mapping
    • Creating Records
    • Reading Records
    • Updating Records
    • Deleting Records
    • Column Statistics
    • Dynamic Finders
    • Getting Paginated Data
    • Associations
    • Nested Properties
    • Object Validation
    • Object Callbacks
    • Calculated Properties
    • Transactions
    • Dirty Records
    • Soft Delete
    • Automatic Time Stamps
    • Database Migrations
      • Migrations in Production
    • Using Multiple Data Sources
  • Plugins
    • Installing and Using Plugins
    • Developing Plugins
    • Publishing Plugins
  • Project Documentation
    • Overview
  • External Links
    • Source Code
    • Issue Tracker
    • Sponsor Us
    • Community
Powered by GitBook
LogoLogo
On this page
  • Synopsis
  • Description
  • Arguments
  • Options
  • Examples
  • Switch to staging
  • Switch with application restart
  • Force switch without validation
  • Switch with backup
  • Quiet switch for scripts
  • What It Does
  • Output Example
  • Environment File Updates
  • .wheels-env
  • Environment Variables
  • Validation Process
  • Switch Strategies
  • Safe Switch (Default)
  • Fast Switch
  • Zero-Downtime Switch
  • Backup and Restore
  • Create Backup
  • Restore from Backup
  • Manual Restore
  • Service Management
  • With Restart
  • Service-Specific
  • Pre/Post Hooks
  • Environment-Specific Actions
  • Development → Production
  • Production → Development
  • Integration
  • CI/CD Pipeline
  • Deployment Scripts
  • Rollback
  • Troubleshooting
  • Switch Failed
  • Application Not Responding
  • Database Connection Issues
  • Best Practices
  • Security Considerations
  • Notes
  • See Also

Was this helpful?

Edit on GitHub
Export as PDF
  1. Command Line Tools
  2. Command Reference
  3. Environment Management

wheels env switch

Switch to a different environment in your Wheels application.

Synopsis

wheels env switch [name] [options]

Description

The wheels env switch command changes the active environment for your Wheels application. It updates configuration files, environment variables, and optionally restarts services to apply the new environment settings.

Arguments

Argument
Description
Default

name

Target environment name

Required

Options

Option
Description
Default

--check

Validate before switching

true

--restart

Restart application after switch

false

--backup

Backup current environment

false

--force

Force switch even with issues

false

--quiet

Suppress output

false

--help

Show help information

Examples

Switch to staging

wheels env switch staging

Switch with application restart

wheels env switch production --restart

Force switch without validation

wheels env switch testing --force

Switch with backup

wheels env switch production --backup

Quiet switch for scripts

wheels env switch development --quiet

What It Does

  1. Validates Target Environment:

    • Checks if environment exists

    • Verifies configuration

    • Tests database connection

  2. Updates Configuration:

    • Sets WHEELS_ENV variable

    • Updates .wheels-env file

    • Modifies environment.cfm if needed

  3. Applies Changes:

    • Clears caches

    • Reloads configuration

    • Restarts services (if requested)

  4. Verifies Switch:

    • Confirms environment active

    • Checks application health

    • Reports status

Output Example

Switching environment...

Current: development
Target:  staging

✓ Validating staging environment
✓ Configuration valid
✓ Database connection successful
✓ Updating environment settings
✓ Clearing caches
✓ Environment switched successfully

New Environment: staging
Database: wheels_staging
Debug: Enabled
Cache: Partial

Environment File Updates

.wheels-env

Before:

development

After:

staging

Environment Variables

Updates system environment:

export WHEELS_ENV=staging
export WHEELS_DATASOURCE=wheels_staging

Validation Process

Before switching, validates:

  1. Configuration:

    • File exists

    • Syntax valid

    • Required settings present

  2. Database:

    • Connection works

    • Tables accessible

    • Migrations current

  3. Dependencies:

    • Required services available

    • File permissions correct

    • Resources accessible

Switch Strategies

Safe Switch (Default)

wheels env switch production
  • Full validation

  • Graceful transition

  • Rollback on error

Fast Switch

wheels env switch staging --force --no-check
  • Skip validation

  • Immediate switch

  • Use with caution

Zero-Downtime Switch

wheels env switch production --strategy=blue-green
  • Prepare new environment

  • Switch load balancer

  • No service interruption

Backup and Restore

Create Backup

wheels env switch production --backup
# Creates: .wheels-env-backup-20240115-103045

Restore from Backup

wheels env restore --from=.wheels-env-backup-20240115-103045

Manual Restore

# If switch fails
cp .wheels-env-backup-20240115-103045 .wheels-env
wheels reload

Service Management

With Restart

wheels env switch production --restart

Restarts:

  • Application server

  • Cache services

  • Background workers

Service-Specific

wheels env switch staging --restart-services=app,cache

Pre/Post Hooks

Configure in .wheels-cli.json:

{
  "env": {
    "switch": {
      "pre": [
        "wheels test run --quick",
        "git stash"
      ],
      "post": [
        "wheels dbmigrate latest",
        "wheels cache clear",
        "npm run build"
      ]
    }
  }
}

Environment-Specific Actions

Development → Production

wheels env switch production
# Warning: Switching from development to production
# - Debug will be disabled
# - Caching will be enabled
# - Error details will be hidden
# Continue? (y/N)

Production → Development

wheels env switch development
# Warning: Switching from production to development
# - Debug will be enabled
# - Caching will be disabled
# - Sensitive data may be exposed
# Continue? (y/N)

Integration

CI/CD Pipeline

- name: Switch to staging
  run: |
    wheels env switch staging --check
    wheels test run
    wheels deploy exec staging

Deployment Scripts

#!/bin/bash
# deploy.sh

# Switch environment
wheels env switch $1 --backup

# Run migrations
wheels dbmigrate latest

# Clear caches
wheels cache clear

# Verify
wheels env | grep $1

Rollback

If switch fails or causes issues:

# Automatic rollback
wheels env switch production --auto-rollback

# Manual rollback
wheels env switch:rollback

# Force previous environment
wheels env switch development --force

Troubleshooting

Switch Failed

  • Check validation errors

  • Verify target environment exists

  • Use --force if necessary

Application Not Responding

  • Check service status

  • Review error logs

  • Manually restart services

Database Connection Issues

  • Verify credentials

  • Check network access

  • Test connection manually

Best Practices

  1. Always Validate: Don't skip checks in production

  2. Use Backups: Enable backup for critical switches

  3. Test First: Switch in staging before production

  4. Monitor After: Check application health post-switch

  5. Document Changes: Log environment switches

Security Considerations

  • Production switches require confirmation

  • Sensitive configs protected

  • Audit trail maintained

  • Access controls enforced

Notes

  • Some changes require application restart

  • Database connections may need reset

  • Cached data cleared on switch

  • Background jobs may need restart

See Also

Previouswheels env listNextPlugin Management

Last updated 2 days ago

Was this helpful?

- Environment management overview

- List environments

- Setup environments

- Reload application

wheels env
wheels env list
wheels env setup
wheels reload