3

Currently in the source down migrations are not supported by Craft CMS.

public function safeDown()
{
    Craft::log('Down migrations are not supported.', LogLevel::Warning);
}

Why are they not supported? Also, how can I implement this for my own plugins?

1 Answer 1

4

The main reason down migrations aren't officially supported is because of the additional support overhead they would incur.

Just one simple example: a down migration would have to "undo" what the up migration did. If that happened to be something destructive, like removing a database column that was storing content on your site, and you waited long enough for users to enter content that used that column, now you've lost the content they've entered.

It gets more complicated if you take into account dependencies. Plugin A depends on Craft schema version B to be in place to work, but if you down migrate Craft to schema version A, plugin A will break despite any schema version checks they might have done on installation.

Same goes for dependencies between plugin A and plugin B as well.

If you really want to support this in your plugin, your migration is probably already extending BaseMigration and you can extend the safeDown method.

Just note that there's no way to trigger this through the Craft CP natively. You'd have to write a plugin that exposed a controller action to trigger it or if you wanted it from the command line, you'd have to create a custom console command that exposed it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.