now i'm trying to use migration into my Codeigniter project.
I have created a few migration files on application/migrations, and Migrate.php as a controller to make a table when i try to migrate a table.
I'll give the sample of migrations file and what is in Migrate.php at the and of this thread.
The problem happen when i run the migration, i run with cli php index.php migrate current. It shows that migration success, but only migrations table that is created. Anyone have same problem with me?
Migrate.php
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Migrate extends CI_Controller {
function __construct()
{
parent::__construct();
if(! $this->input->is_cli_request()) {
show_404();
exit;
}
$this->load->library('migration');
}
function current()
{
if ($this->migration->current()) {
log_message('error', 'Migration Success.');
echo "Migration Success";
} else {
log_message('error', $this->migration->error_string());
echo $this->migration->error_string();
}
}
function rollback($version)
{
if ($this->migration->version($version)) {
log_message('error', 'Migration Success.');
echo "Migration Success";
} else {
log_message('error', $this->migration->error_string());
echo $this->migration->error_string();
}
}
function latest()
{
if ($this->migration->latest()) {
log_message('error', 'Migration Success.');
echo "Migration Success";
} else {
log_message('error', $this->migration->error_string());
echo $this->migration->error_string();
}
}
}
Sample of migrations file.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_Add_Facility_Types extends CI_Migration {
public function up()
{
$this->dbforge->add_field(array(
'id' => array(
'type' => 'INT',
'constraint' => 5,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'name' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
));
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('facility_types');
}
public function down()
{
$this->dbforge->drop_table('facility_types');
}
}