I found an interesting behavior today: I accidently named a data upgrade script data-upgrade-0.1.20-0.1.20.php where it should have been data-upgrade-0.1.19-0.1.20.php, and it actually has been applied.

And as I cannot find a question here that can be used as a reference for the setup script version logic (correct me if I'm wrong), let's use this one.

By which logic does Magento execute the install and upgrade scripts?

Especially interesting edge case: When and why are scripts like upgrade-1.0.0-1.0.0.php executed, where the "from" version number is equal to the "to" version number?

  • wow thats weird. Data upgrades are only executed if the version_compare returns 1. Equal should return 0. Commented Sep 1, 2015 at 15:19
  • That's what I would expect. But the current version was 0.1.19, so it makes sense that the version_compare check returned 1. Commented Sep 1, 2015 at 15:21

1 Answer 1


The method that calls the upgrades (at least one in the chain) is this in Mage_Core_Model_Resource_Setup

public function applyDataUpdates()
    $dataVer= $this->_getResource()->getDataVersion($this->_resourceName);
    $configVer = (string)$this->_moduleConfig->version;
    if ($dataVer !== false) {
         $status = version_compare($configVer, $dataVer);
         if ($status == self::VERSION_COMPARE_GREATER) {
             $this->_upgradeData($dataVer, $configVer);
    } elseif ($configVer) {
    return $this;

Your module had the version ($configVer) 0.1.19, so magento reads all the available scripts in the sql folder and the file 0.1.20-0.1.20 matched the condition if ($status == self::VERSION_COMPARE_GREATER) { because the $configVer variable is not incremented after each script executes.
So it always compares to 0.1.19 until the upgrade finishes.

Side note: this is a crazy one indeed.

  • 1
    nice one! But yeah, kinda weird it doesn't update the from during upgrade Commented Sep 1, 2015 at 15:28

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.