Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run CodeIgniter migrations?

I know how to create them via http://codeigniter.com/user_guide/libraries/migration.html

But once I've created my migration files, how do I run them?

like image 659
Shamoon Avatar asked Feb 05 '12 23:02

Shamoon


People also ask

How do you run a migration in CI?

The database table migration tracks which migrations have already been run so all you have to do is update your application files and call $this->migration->current() to work out which migrations should be run. The current version is found in application/config/migration. php.

What is migration in CodeIgniter?

Migrations are a convenient way for you to alter your database in a structured and organized manner. You could edit fragments of SQL by hand but you would then be responsible for telling other developers that they need to go and run them.

What is migration in CodeIgniter 4?

The migration library can automatically scan all namespaces you have defined within app/Config/Autoload. php or loaded from an external source like Composer, using the $psr4 property for matching directory names.

What are php migrations?

Migrations are a type of version control for your database. They allow a team to modify the database schema and stay up to date on the current schema state. Migrations are typically paired with the Schema Builder to easily manage your application's schema.


1 Answers

Using these pages as references: Running via the CLI and Migration Class you're able to restrict access to your migration controller to command line with something along these lines (application/controllers/migrate.php):

<?php  if ( ! defined('BASEPATH')) exit("No direct script access allowed");  class Migrate extends CI_Controller {    public function __construct()   {     parent::__construct();      $this->input->is_cli_request()        or exit("Execute via command line: php index.php migrate");      $this->load->library('migration');   }    public function index()   {     if(!$this->migration->latest())      {       show_error($this->migration->error_string());     }   } } 

then to execute your latest migration, cd into the root of your project directory and run:

php index.php migrate 

but when you attempt to access via webserver domain.com/migrate you will see the text in the script above.

like image 97
skilleo Avatar answered Oct 07 '22 18:10

skilleo