Created
November 8, 2013 21:25
-
-
Save CMCDragonkai/7377935 to your computer and use it in GitHub Desktop.
PHP: Codeigniter Migrate Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Migrate extends CI_Controller { | |
public function __construct(){ | |
parent::__construct(); | |
if(!$this->input->is_cli_request()){ | |
exit; | |
} | |
$this->load->library('migration'); | |
} | |
public function index(){ | |
echo "Migration is initialised. Make sure this is not accessible in production!\n"; | |
echo "Currently available migrations:\n"; | |
print_r($this->migration->find_migrations()); | |
} | |
public function latest(){ | |
if(!$this->migration->latest()){ | |
echo $this->migration->error_string(); | |
} | |
echo 'Migrated to latest'; | |
} | |
public function current(){ | |
if(!$this->migration->current()){ | |
echo $this->migration->error_string(); | |
} | |
echo 'Migrated to current'; | |
} | |
public function version($num){ | |
if(!$this->migration->version($num)){ | |
echo $this->migration->error_string(); | |
} | |
echo 'Migrated to version ' . $num; | |
} | |
//restarts the migration from 0 to the number specified or latest | |
public function restart($num = false){ | |
$this->migration->version(0); | |
if(!empty($num)){ | |
if(!$this->migration->version($num)){ | |
echo $this->migration->error_string(); | |
} | |
echo 'Restarted migration to ' . $num; | |
}else{ | |
if(!$this->migration->latest()){ | |
echo $this->migration->error_string(); | |
} | |
echo 'Restarted migration to latest'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment