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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With