public function testRunNewMigrationUpdateCompletedTable() { $this->simulateLogin('*****@*****.**', true); $controller = new UpgradeDatabaseController(true); $this->newMigrationFiles('some_stuff'); $this->newMigrationFiles('some_stuff', $old = true); // older already ran? $db_version = UpgradeDatabaseController::getCurrentDBVersion($cached = false); $list = $controller->getMigrationList($db_version); $this->assertEqual(count($list), 1); $this->assertTrue($list[0]['new_migration']); $this->assertPattern("/^2011-09-21_some_stuff_v\\d+\\.\\d+\\.sql\$/", $list[0]['filename']); // create completion table $com_sql_file = THINKUP_WEBAPP_PATH . 'install/sql/completed_migrations.sql'; //echo $com_sql_file; $com_sql = file_get_contents($com_sql_file); $com_sql = str_replace('tu_', $this->table_prefix, $com_sql); $this->pdo->query($com_sql); $this->pdo->query("alter table " . $this->table_prefix . "completed_migrations DROP column sql_ran"); $_GET['migration_index'] = 1; $results = $controller->go(); $obj = json_decode($results); $this->assertTrue($obj->processed); $sql = file_get_contents($this->test_migrations[0]); $sql = preg_replace('/\\-\\-.*/', '', $sql); $sql = str_replace('tu_', $this->table_prefix, $sql); $this->assertEqual($obj->sql, $sql); $stmt = $this->pdo->query("select * from " . $this->table_prefix . "completed_migrations"); $data2 = $stmt->fetchAll(PDO::FETCH_ASSOC); $this->assertEqual(count($data2), 3); $this->assertPattern('/CREATE TABLE `.*test1`/', $data2[0]['sql_ran']); }
$backup_dao = DAOFactory::getDAO('BackupDAO'); print "\nExporting data to: {$filename}\n\n"; $backup_dao->export($filename); print "\nBackup completed.\n\n"; } } } // run updates... // get migrations we need to run... if (!$no_version) { print "\nUpgrading Thinkup to version {$thinkup_db_version}...\n\n"; } $upgrade_start_time = microtime(true); putenv('CLI_BACKUP=true'); $upgrade_ctl = new UpgradeDatabaseController(); $migrations = $upgrade_ctl->getMigrationList($db_version, $no_version); $install_dao = DAOFactory::getDAO('InstallerDAO'); if ($no_version && count($migrations) > 0) { $s = count($migrations) > 1 ? 's' : ''; print "\nFound " . count($migrations) . " migration" . $s . " to process...\n"; } foreach ($migrations as $migration) { if ($no_version) { print "\n Running migration with file " . $migration['filename'] . "\n"; } else { print "\n Running migration " . $migration['version'] . "\n"; } $sql = preg_replace('/\\-\\-.*/', '', $migration['sql']); $install_dao->runMigrationSQL($sql, $migration['new_migration'], $migration['filename']); } if (count($migrations) == 0) {