public function testProcessMigrationsDifferentPrefix()
 {
     $config = Config::getInstance();
     $old_table_prefix = $config->getValue('table_prefix');
     $config->setValue('table_prefix', 'new_prefix_');
     $stmt = $this->pdo->query("show tables");
     $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     //var_dump($data);
     foreach ($data as $table) {
         foreach ($table as $key => $value) {
             $new_value = preg_replace("/^" . $old_table_prefix . "/", " new_prefix_", $value);
             $sql = "RENAME TABLE {$value} TO {$new_value}";
             $this->pdo->query($sql);
         }
     }
     $this->simulateLogin('*****@*****.**', true);
     $controller = new UpgradeDatabaseController(true);
     $this->migrationFiles(1);
     $_GET['migration_index'] = 1;
     $results = $controller->go();
     $obj = json_decode($results);
     $this->assertTrue($obj->processed);
     $updated_file = file_get_contents($this->test_migrations[0]);
     $updated_file = preg_replace('/\\-\\-.*/', '', $updated_file);
     $updated_file = str_replace('tu_', 'new_prefix_', $updated_file);
     $this->debug($obj->sql);
     $this->assertEqual($obj->sql, $updated_file);
     $this->assertFalse(strrpos($obj->sql, 'tu_'));
     $sql = "show tables like 'new_prefix_test1'";
     $stmt = $this->pdo->query($sql);
     $data = $stmt->fetch();
     $this->assertEqual($data[0], 'new_prefix_test1');
     $sql = 'select * from new_prefix_test1';
     $stmt = $this->pdo->query($sql);
     $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $this->assertEqual(count($data), 3);
 }
Beispiel #2
0
 *
 * ThinkUp/webapp/install/upgrade-database.php
 *
 * Copyright (c) 2009-2013 Mark Wilkie
 *
 * LICENSE:
 *
 * This file is part of ThinkUp (http://thinkup.com).
 *
 * ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
 * later version.
 *
 * ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with ThinkUp.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 *
 * @license http://www.gnu.org/licenses/gpl.html
 * @copyright 2009-2013 Mark Wilkie
 * @author Mark Wilkie <mwilkie[at]gmail[dot]com>
 *
 */
chdir("..");
require_once 'init.php';
$controller = new UpgradeDatabaseController();
echo $controller->go();