Member Avatar for iamthwee

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.

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

users
media
messages
comments
article
favorites

Your latest version requires the following new tables
bookmarks
friends
websites

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);
       $this->dbforge->add_field($this_new_bookmark);



       }

       public function down(){
       ## then the roll back method
       $this->dbforge->drop_table($this->bookmarks);
       }

       } //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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.