cakephp / cakephp/phinx

Suggestion: Throw `IrreversibleMigrationException` also when migrating up

Open
#1,636 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
PHP
Stars
4.5k
Forks
884
PR merge metrics
No merged PRs in 30d

Description

Hi,

a quote from the docs that describe the change() method (scroll down a little bit after clicking the link):

If a command cannot be reversed then Phinx will throw an IrreversibleMigrationException when it’s migrating down.

As I usually only run migrations up, it might be that I will not notice if I happen to create migrations that accidentally use some irreversible actions in the change() method. Could it be possible to make Phinx throw this exception also when migrating up, so it would be easier to spot these mistakes earlier? Maybe this behaviour could be toggled on/off by a setting in phinx.yml?

This would reduce a risk that a "downwards broken" migration would end up to be used in a production deployment process which for some reason needs to be rolled back, and then the rollback would fail due to a mistake that was not spotted in the development phase, causing that the mistake would have to be fixed by manually editing the migration file on a production server and usually in a big hurry. :D

Thanks! :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the change() migration behavior and the phinx.yml configuration mentioned in the issue, then review how irreversible actions are detected during up and down migrations. Define whether up migrations should always raise IrreversibleMigrationException or support a configuration toggle. Done means the chosen behavior is implemented and covered for both migration directions.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.