6. Migrations


development journey, step 1

This is magic:

gristech@serv01 [~]# alias art=”/usr/local/php53/bin/php-cli artisan”

Now, just type:

# art make:foo (whatever)

Nifty!


foo

php artisan migrate:make users_table

…blah

fancier:

php artisan migrate:make add_company_to_users_table

class Add_Company_To_Users_Table {

/**
* Make changes to the database.
*
* @return void
*/
public function up() //add column
{
Schema::table(‘users’, function ($table){
$table->string(‘company’);
});
}

/**
* Revert the changes to the database.
*
* @return void
*/
public function down() //drop column
{
Schema::table(‘users’, function ($table){
$table->drop_column(‘company’);//can pass string or array
});
}

}

php artisan migrate

mysql> describe users;
+————+——————+——+—–+———+—————-+
| Field      | Type             | Null | Key | Default | Extra          |
+————+——————+——+—–+———+—————-+
| id         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name       | varchar(50)      | NO   |     | NULL    |                |
| age        | int(11)          | YES  |     | NULL    |                |
| email      | varchar(200)     | NO   |     | NULL   …

View original post 218 more words

Advertisements

One thought on “6. Migrations

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s