Database: Migrations

Introduction

Migrations are like version control for your database, allowing your team to define and share the application's database schema definition. If you have ever had to tell a teammate to manually add a column to their local database schema after pulling in your changes from source control, you've faced the problem that database migrations solve.

Generating Migrations

You may use the migration:create command to generate a database migration.

The new migration will be placed in your databases\migrations directory.

php kiaan migration:create Pages

Migration Structure

A migration class contains handle method.

Method is used to add new tables or columns to your database.

class Users implements MigrateBuild {

    /**
     * Handle
     * 
    **/
    public function handle()
    {
        Schema::createTable('users')
        ->id()
        ->string('name')->notNullable()
        ->string('email')->notNullable()
        ->string('password')->notNullable()
        ->string('token')->nullable()
        ->string('jwt')->nullable()
        ->timestamp('created_at')->current()
        ->timestamp('updated_at')->current()->updateCurrent()
        ->submit();
    }  

}

Running Migrations

To run of your migration class, execute the migration:run Artisan command:

php kiaan migration:run Pages

Running All Migrations

To run all of your outstanding migrations, execute the migration:all Artisan command:

php kiaan migration:all

Last updated