Welcome Guest, Not a member yet? Register   Sign In
Refinery - "Ready-to-eat" migrations for CodeIgniter
#1

(This post was last modified: 03-12-2016, 08:09 PM by rougin. Edit Reason: Update documentation )

Hello! I'm using Migrations Class for quite some time now but I'm having a hard time to create migrations and creating a controller that will migrate them all (especially the timestamps Big Grin). So that's why I've created this library, Refinery, with a goal to supplement the features of the Migrations Class and help you save time in creating migrations for your web applications built in CodeIgniter. https://github.com/rougin/refinery

To install this library, you will need to use Composer for that because it's easy to install it there:

Code:
$ composer require rougin/refinery

Here are some examples on how to use it.

Creating a table named user:

Code:
$ php vendor/bin/refinery create create_user_table
"20150607123241_create_user_table.php" has been created.

20150607123241_create_user_table.php

PHP Code:
class Migration_create_user_table extends CI_Migration {

    /**
     * Run the migrations
     */
    public function up()
    {
        $this->dbforge->add_field('id');
        $this->dbforge->create_table('user');
    }

    /**
     * Reverse the migrations
     */
    public function down()
    {
        $this->dbforge->drop_table('user');
    }



Adding column named name in user table:

Code:
$ php vendor/bin/refinery create add_name_in_user_table
"20150607123510_add_name_in_user_table.php" has been created.

20150607123510_add_name_in_user_table.php

PHP Code:
class Migration_add_name_in_user_table extends CI_Migration {

    /**
     * Run the migrations
     */
    public function up()
    {
        $this->dbforge->add_column('user', array(
            'name' => array(
                'type' => 'VARCHAR',
                'constraint' => '50',
                'auto_increment' => FALSE,
                'null' => FALSE,
                'unsigned' => FALSE
            
)
        ));
    }

    /**
     * Reverse the migrations
     */
    public function down()
    {
        $this->dbforge->drop_column('user''name');
    }



Migrating all files from application/migrations directory:

Code:
$ php vendor/bin/refinery migrate
"20150607123241_create_user_table" has been migrated to the database.
"20150607123510_add_name_in_user_table" has been migrated to the database.

You can also revert back if you want:

Code:
$ php vendor/bin/refinery migrate --revert=1

Database is reverted back to version 20150607123241. (20150607123241_create_user_table)

Or reset them back:

Code:
$ php vendor/bin/refinery migrate:reset
Database has been resetted.
Reply
#2

Hello! I've released an update recently for this library. Have fun! Smile
Reply
#3

Hi! I've made some fixes for the latest release. Thanks for the ones who helped. Smile
Reply
#4

Hello! It is now updated with unit tests. Big Grin
Reply




Theme © iAndrew 2016 - Forum software by © MyBB