Skip to content

Commit

Permalink
Improved version handling for double digit and minor version numbers
Browse files Browse the repository at this point in the history
Compare version properly for UpgradeController and Tests
Closes #663, closes #664
  • Loading branch information
mwilkie authored and ginatrapani committed Mar 8, 2011
1 parent 4d2e8a2 commit 189946c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
49 changes: 49 additions & 0 deletions tests/TestOfUpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,53 @@ public function testProcessOneMigrations() {
$this->assertEqual(count($data), 3);
}

public function testProcessMinorVersionMigration() {
$this->simulateLogin('me@example.com', true);
$config = Config::getInstance();
$config->setValue('THINKUP_VERSION', $config->getValue('THINKUP_VERSION') + 10.1); //set a high minor version
$controller = new UpgradeController(true);
$this->migrationFiles(1);
$_GET['migration_index'] = 1;
$results = $controller->go();
$obj = json_decode($results);
$this->assertTrue($obj->processed);
$this->assertEqual($obj->sql, file_get_contents($this->test_migrations[0]));

$sql = "show tables like 'tu_test1'";
$stmt = $this->pdo->query($sql);
$data = $stmt->fetch();
$this->assertEqual($data[0], 'tu_test1');
$sql = 'select * from tu_test1';
$stmt = $this->pdo->query($sql);
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$this->assertEqual(count($data), 3);
}

public function testProcessMinorBetaVersionMigration() {
$this->simulateLogin('me@example.com', true);
$config = Config::getInstance();
$test_version = $config->getValue('THINKUP_VERSION') + 10.1;
$test_version .= 'beta';
$config->setValue('THINKUP_VERSION', $test_version); //set a high minor version with beta string
$controller = new UpgradeController(true);
$this->migrationFiles(1);
$_GET['migration_index'] = 1;
$results = $controller->go();
$obj = json_decode($results);
$this->assertTrue($obj->processed);
$this->assertEqual($obj->sql, file_get_contents($this->test_migrations[0]));

$sql = "show tables like 'tu_test1'";
$stmt = $this->pdo->query($sql);
$data = $stmt->fetch();
$this->assertEqual($data[0], 'tu_test1');
$sql = 'select * from tu_test1';
$stmt = $this->pdo->query($sql);
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$this->assertEqual(count($data), 3);
}


public function testProcessSnowflakeMigration() {
$config = Config::getInstance();
$app_path = $config->getValue('source_root_path');
Expand Down Expand Up @@ -455,6 +502,8 @@ private function migrationFiles($count = 1) {
if($count == 2) {
$migration_test2 = $this->migrations_test_dir . $this->migrations_file2;
$migration_version--;
$migration_version += 0.12;
$migration_version .= 'beta';
$migration2 = $this->migrations_dir
. '2010-09-16_v' . $migration_version . '.sql.migration';
copy($migration_test2, $migration2);
Expand Down
10 changes: 8 additions & 2 deletions webapp/_lib/controller/class.UpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function __construct($session_started=false) {
}

public function authControl() {

$this->disableCaching();
Utils::defineConstants();
$config = Config::getInstance();
Expand Down Expand Up @@ -235,9 +236,14 @@ public function getMigrationList($version) {
$migrations = array();
$config = Config::getInstance();
for ($i = 0; $i < count($dir_list); $i++) {
if(preg_match('/_v(\d+\.\d+)\.sql\.migration/', $dir_list[$i], $matches)) {
if(preg_match('/_v(\d+\.\d+(\.\d+)?(\w+)?)\.sql\.migration/', $dir_list[$i], $matches)) {
$migration_version = $matches[1];
if($migration_version > $version && $migration_version <= $config->getValue('THINKUP_VERSION')) {
// skip early pre beta 1 versions...
if(preg_match('/^0\.00/', $migration_version)) {
continue;
}
if(version_compare($migration_version, $version) > 0 &&
version_compare($migration_version, $config->getValue('THINKUP_VERSION')) < 1 ) {
if($migration_version == 0.3) {
$install_dao = DAOFactory::getDAO('InstallerDAO');
if(! $install_dao->needsSnowflakeUpgrade() && ! $this->snowflakeSession(false) ) {
Expand Down

0 comments on commit 189946c

Please sign in to comment.