public function testProcessMigrationsDifferentPrefix() {

        $config = Config::getInstance();
        $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("/tu_/", " new_prefix_", $value);
                $sql = "RENAME TABLE $value TO $new_value";
                $this->pdo->query($sql);
            }
        }

        $this->simulateLogin('*****@*****.**', true);
        $controller = new UpgradeController(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("/\s`tu_/", " `new_prefix_", $updated_file);
        $updated_file = preg_replace("/\stu_/", " new_prefix_", $updated_file);
        $this->assertEqual($obj->sql, $updated_file);
        $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);
    }
Example #2
0
 *
 * ThinkUp/webapp/install/upgrade.php
 *
 * Copyright (c) 2009-2010 Mark Wilkie
 *
 * LICENSE:
 *
 * This file is part of ThinkUp (http://thinkupapp.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-2010 Mark Wilkie
 * @author Mark Wilkie <mwilkie[at]gmail[dot]com>
 *
 */
chdir("..");
require_once 'init.php';
$controller = new UpgradeController();
echo $controller->go();