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
  • <version>
  • Options
  • --env
  • --datasource
  • --direction
  • --force
  • --verbose
  • --dry-run
  • Examples
  • Execute a specific migration
  • Execute migration's down method
  • Force re-execution of a migration
  • Execute in production environment
  • Preview migration execution
  • Use Cases
  • Applying Hotfix Migrations
  • Re-running Failed Migrations
  • Testing Specific Migrations
  • Selective Migration Application
  • Important Considerations
  • Migration Order
  • Version Tracking
  • Down Direction
  • Best Practices
  • Version Number Format
  • Notes
  • Related Commands

Was this helpful?

Edit on GitHub
Export as PDF
  1. Command Line Tools
  2. Command Reference
  3. Database Commands

wheels dbmigrate exec

Execute a specific database migration by version number.

Synopsis

wheels dbmigrate exec <version> [options]

Description

The dbmigrate exec command allows you to run a specific migration identified by its version number, regardless of the current migration state. This is useful for applying individual migrations out of sequence during development or for special maintenance operations.

Arguments

<version>

  • Type: String

  • Required: Yes

  • Description: The version number of the migration to execute (e.g., 20240115123456)

Options

--env

  • Type: String

  • Default: development

  • Description: The environment to run the migration in

--datasource

  • Type: String

  • Default: Application default

  • Description: Specify a custom datasource for the migration

--direction

  • Type: String

  • Default: up

  • Values: up, down

  • Description: Direction to run the migration (up or down)

--force

  • Type: Boolean

  • Default: false

  • Description: Force execution even if migration is already run

--verbose

  • Type: Boolean

  • Default: false

  • Description: Display detailed output during execution

--dry-run

  • Type: Boolean

  • Default: false

  • Description: Preview the migration without executing it

Examples

Execute a specific migration

wheels dbmigrate exec 20240115123456

Execute migration's down method

wheels dbmigrate exec 20240115123456 --direction=down

Force re-execution of a migration

wheels dbmigrate exec 20240115123456 --force --verbose

Execute in production environment

wheels dbmigrate exec 20240115123456 --env=production

Preview migration execution

wheels dbmigrate exec 20240115123456 --dry-run --verbose

Use Cases

Applying Hotfix Migrations

Apply a critical fix out of sequence:

# Create hotfix migration
wheels dbmigrate create blank --name=hotfix_critical_issue

# Execute it immediately
wheels dbmigrate exec 20240115123456 --env=production

Re-running Failed Migrations

When a migration partially fails:

# Check migration status
wheels dbmigrate info

# Re-run the failed migration
wheels dbmigrate exec 20240115123456 --force --verbose

Testing Specific Migrations

Test individual migrations during development:

# Run specific migration up
wheels dbmigrate exec 20240115123456

# Test the changes
# Run it down
wheels dbmigrate exec 20240115123456 --direction=down

Selective Migration Application

Apply only certain migrations from a set:

# List all migrations
wheels dbmigrate info

# Execute only the ones you need
wheels dbmigrate exec 20240115123456
wheels dbmigrate exec 20240115134567

Important Considerations

Migration Order

Executing migrations out of order can cause issues if migrations have dependencies. Always ensure that any required preceding migrations have been run.

Version Tracking

The command updates the migration tracking table to reflect the execution status. Using --force will update the timestamp of execution.

Down Direction

When running with --direction=down, the migration must have already been executed (unless --force is used).

Best Practices

  1. Check Dependencies: Ensure required migrations are already applied

  2. Test First: Run in development/testing before production

  3. Use Sparingly: Prefer normal migration flow with up/latest

  4. Document Usage: Record when and why specific executions were done

  5. Verify State: Check migration status before and after execution

Version Number Format

Migration versions are typically timestamps in the format:

  • YYYYMMDDHHmmss (e.g., 20240115123456)

  • Year: 2024

  • Month: 01

  • Day: 15

  • Hour: 12

  • Minute: 34

  • Second: 56

Notes

  • The migration file must exist in the migrations directory

  • Using --force bypasses normal safety checks

  • The command will fail if the migration file has syntax errors

  • Both up() and down() methods should be defined in the migration

Related Commands

Previouswheels dbmigrate resetNextwheels dbmigrate create blank

Last updated 2 days ago

Was this helpful?

- Run the next migration

- Rollback last migration

- Run all pending migrations

- View migration status

- Create a new migration

wheels dbmigrate up
wheels dbmigrate down
wheels dbmigrate latest
wheels dbmigrate info
wheels dbmigrate create blank