Loading...

CLI Overview

Quick Start Guide

wheels info

wheels reload

wheels deps

wheels destroy

wheels watch

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

wheels test

wheels test run

wheels test coverage

wheels test debug

wheels config list

wheels config set

wheels config env

wheels env

wheels env setup

wheels env list

wheels env switch

wheels environment

wheels console

wheels runner

wheels server

wheels server start

wheels server stop

wheels server restart

wheels server status

wheels server log

wheels server open

wheels plugins

wheels plugins list

wheels plugins install

wheels plugins remove

wheels analyze

wheels analyze code

wheels analyze performance

wheels analyze security

wheels security

wheels security scan

wheels optimize

wheels optimize performance

wheels docs

wheels docs generate

wheels docs serve

wheels ci init

wheels docker init

wheels docker deploy

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

Configuration Management

Creating Commands

Service Architecture

Migrations Guide

Testing Guide

Ask or search...
Ctrl K
Loading...

dbmigrate down

Rollback the last executed database migration.

Synopsis

wheels dbmigrate down

Alias: wheels db down

Description

The dbmigrate down command reverses the last executed migration by running its down() method. This is useful for undoing database changes when issues are discovered or when you need to modify a migration. The command ensures safe rollback of schema changes while maintaining database integrity.

Parameters

None.

Examples

Rollback the last migration

wheels dbmigrate down

This will execute the down() method of the most recently applied migration, reverting the database changes.

Use Cases

Fixing Migration Errors

When a migration contains errors or needs modification:

# Run the migration
wheels dbmigrate up

# Discover an issue
# Rollback the migration
wheels dbmigrate down

# Edit the migration file
# Re-run the migration
wheels dbmigrate up

Development Iteration

During development when refining migrations:

# Apply migration
wheels dbmigrate up

# Test the changes
# Need to modify? Rollback
wheels dbmigrate down

# Make changes to migration
# Apply again
wheels dbmigrate up

Emergency Rollback

When a migration causes issues:

# Check current migration status
wheels dbmigrate info

# Rollback the problematic migration
wheels dbmigrate down

# Verify rollback
wheels dbmigrate info

Important Considerations

Data Loss Warning

Rolling back migrations that drop columns or tables will result in data loss. Always ensure you have backups before rolling back destructive migrations.

Down Method Requirements

For a migration to be rolled back, it must have a properly implemented down() method that reverses the changes made in the up() method.

Migration Dependencies

Be cautious when rolling back migrations that other migrations depend on. This can break the migration chain.

Best Practices

  1. Always implement down() methods: Even if you think you'll never need to rollback
  2. Test rollbacks: In development, always test that your down() method works correctly
  3. Backup before rollback: Especially in production environments
  4. Document destructive operations: Clearly indicate when rollbacks will cause data loss

Notes

  • Only the last executed migration can be rolled back with this command
  • To rollback multiple migrations, run the command multiple times
  • If already at version 0, displays: "We're already on zero! No migrations to go to"
  • Automatically runs dbmigrate info after successful rollback
  • The migration version is removed from the database tracking table upon successful rollback
  • Some operations (like dropping columns with data) cannot be fully reversed
  • When migrating to version 0, displays: "Database should now be empty."