마이그레이션(migration) Sample

<?php
/**
 * Migration Class
 *
 * Created on 2011. 11. 16.
 * @author 불의회상 <hoksi2k@hanmail.net>
 * @package library
 * @subpackage controllers
 * @version 1.0
 */
class Migration_lib extends CI_Controller {
	function __construct() {
		parent::__construct();
	}
	
	function index($mode = NULL) {
		$this->load->library('migration');

		$data = array(
			'migration_error' => '',
			'blog' => '',
			'migration_config' => $this->load->file('sample/migrations/migration_config.txt', TRUE),
			'migration_file' => $this->load->file('sample/migrations/001_add_blog.txt', TRUE),
			'mode' => $mode
		);

		if($mode == 'migration') {
			// Migration
			if (!$this->migration->current()) {
				$data['migration_error'] = $this->migration->error_string();
			} else {
				if($this->db->table_exists('blog')) {
					$data['blog'] = $this->db->list_fields('blog');
				}
			}
		} elseif($mode == 'migration_latest') {
			// Migration latest
			if (!$this->migration->latest()) {
				$data['migration_error'] = $this->migration->error_string();
			} else {
				if($this->db->table_exists('blog')) {
					$data['blog'] = $this->db->list_fields('blog');
				}
			}
		} elseif($mode == 'rollback') {
			// Rollback
			if (!$this->migration->version(0)) {
				$data['migration_error'] = $this->migration->error_string();
			}
		}

		$this->load->view('migration_lib_sample', $data);
	}
}
<?php $this->load->view('inc/header')?>


<a class="btn btn-primary" href="<?=site_url('migration_lib/index/migration')?>">Migration</a>
<a class="btn btn-warning" href="<?=site_url('migration_lib/index/migration_latest')?>">Migration Latest</a>
<a class="btn" href="<?=site_url('migration_lib/index/rollback')?>">Rollback</a>
<hr/>
<table class="tablesorter" border="0" cellpadding="0" cellspacing="1">
<?php if($mode != NULL):?>
<thead>
<tr>
  <th style="text-align:center" colspan="2">
  	<?=($mode == 'migration' ? 'Migration' : ($mode == 'migration_latest' ? 'Migration Latest' : 'Migratioin Rollback'))?> 결과
  </th>
</tr>
</thead>
<tr>
	<td width="20%">$this->db->list_fields('blog')</td>
	<td><pre><?php print_r($blog)?></pre></td>
</tr>
<tr>
	<td>에러 여부</td>
	<td><?php echo $migration_error?></td>
</tr>
<?php endif;?>
<thead>
<tr>
  <th style="text-align:center" colspan="2">application/config/migration.php</th>
</tr>
</thead>
<tr>
  <td colspan="2"><pre><?=$migration_config?></pre></td>
</tr>
<thead>
<tr>
  <th style="text-align:center" colspan="2">application/migrations/001_add_blog.php</th>
</tr>
</thead>
<tr>
  <td colspan="2"><pre><?=$migration_file?></pre></td>
</tr>
</table>

<?php $this->load->view('inc/footer')?>

© Copyright by hoksi(Page rendered in 0.0051 seconds)