コード例 #1
0
 /**
  * Allows you to change the database schema version by specifying the desired version. If you are
  * upgrading (choosing a higher version), it will update to the highest version that is available. 
  * If you are downgrading, it will go to the highest version that is equal to or lower than the 
  * version you specified.
  * 
  * @param string $version Version to change to
  * @param string $env     Environment to retrieve database credentials from, default is development
  * @param string $dir     Directory containing migration files, default is ./scripts/migrations
  * 
  * @return boolean
  */
 public function updateTo($version, $env = 'development', $dir = './scripts/migrations')
 {
     $this->_init($env);
     $response = $this->_registry->getResponse();
     try {
         $db = $this->_getDbAdapter();
         $manager = new Akrabat_Db_Schema_Manager($dir, $db, $this->getTablePrefix());
         $result = $manager->updateTo($version);
         switch ($result) {
             case Akrabat_Db_Schema_Manager::RESULT_AT_CURRENT_VERSION:
                 if (!$version) {
                     $version = $manager->getCurrentSchemaVersion();
                 }
                 $response->appendContent("Already at version {$version}");
                 break;
             case Akrabat_Db_Schema_Manager::RESULT_NO_MIGRATIONS_FOUND:
                 $response->appendContent("No migration files found to migrate from {$manager->getCurrentSchemaVersion()} to {$version}");
                 break;
             default:
                 $response->appendContent('Schema updated to version ' . $manager->getCurrentSchemaVersion());
         }
         return true;
     } catch (Exception $e) {
         $response->appendContent('AN ERROR HAS OCCURED:');
         $response->appendContent($e->getMessage());
         return false;
     }
 }
コード例 #2
0
 public function main()
 {
     try {
         $dir = realpath(dirname(__FILE__) . '/../../scripts/migrations');
         $db = Zend_Db::factory($this->_adapter, array('host' => $this->_host, 'username' => $this->_username, 'password' => $this->_password, 'dbname' => $this->_dbname));
         $manager = new Akrabat_Db_Schema_Manager($dir, $db);
         $this->log('Current database schema version is ' . $manager->getCurrentSchemaVersion());
         $manager->updateTo(null);
         $this->log('Updated database schema version updated to ' . $manager->getCurrentSchemaVersion());
     } catch (Zend_Exception $e) {
         $this->log('Failed executing database migration - ' . $e->getMessage(), Project::MSG_ERR);
     }
 }