So I'm becoming very familiar with codeigniter now and loving it, but I'm just wondering about the migration (for db tables and structures) class and how you would use it. Is it actually useable in a real world example. It sounds great in theory but I'm unsure.

Can someone clarify my doubts.

3 Years
Discussion Span
Last Post by veedeoo

Migration is an excellent tool in version upgrades of your distributable application.

For example, you distribute an application called iamthwee's fine CMS. Few months after your beta release, you've just relized that a beta version 2 needs to be released as an ultimate upgrade, and in this particular release you need to upgrade the database by adding new table to add your new ultimate features on the older version.

With migration, your user doesn't need to stay up all night to do upgrades. It will be just like how wordpress updates itself from time to time.

Let say on your old version, you have the following tables


Your latest version requires the following new tables

So instead of telling your application users to logon to phpMyAdmin to create those tables, you can just distribute an upgrade package with new configuration file and then the update controllers and new additional files.

Assuming that the upgrade package already includes new configuration file setting the config migration to true. Your update contoller can be very similar to this.

 class Migration_bookmark_vtwo extends CI_Migration{

    private $bookmarks = 'bookmarks';
    public function up(){

    $this_new_bookmark = array(
                                 b_id => array( 
                                           'type' => 'INT',
                                           'constraint' => 10
                                           'null' => FALSE,
                                           'auto_increment' => TRUE
                               url => array(
                                           /itimized rules here
       $this->dbforge->create_table($this->bookmarks, TRUE);


       public function down(){
       ## then the roll back method

       } //endof class

If the user want to fallback to the older version just run the down method.

It is nice to create a migration controller for each table.....

I highly favor doing this behind the CLI though.

I hope other people can add something. Frameworking is very interesting topic.

Edited by veedeoo: info added.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.