2017 © Pedro Peláez
 

library migrator

Namespaced Migrations for Laravel 5.1+

image

artesaos/migrator

Namespaced Migrations for Laravel 5.1+

  • Sunday, May 20, 2018
  • by hernandev
  • Repository
  • 11 Watchers
  • 25 Stars
  • 6,740 Installations
  • PHP
  • 10 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 12 Versions
  • 7 % Grown

The README.md

artesaos/migrator

Latest Stable Version Total Downloads Monthly Downloads License, (*1)

This package is a customized version of Laravel's default database migrator, it was designed to register migrations on services providers and support namespacing as well., (*2)

There is no timestamp previews since the run order is based on how you register the migrations., (*3)

Warning

This Package Supports Laravel starting on 5.2 up to the latest stable version., (*4)

Installing

In order to install Migrator, run the following command into your Laravel 5.2+ project:, (*5)

composer require artesaos/migrator

After installing the Package, you can now register it's provider into your config/app.php file:, (*6)

'providers' => [
    // other providers omitted.
    Migrator\MigrationServiceProvider::class,
]

And publish configuration: with, (*7)

php artisan vendor:publish --provider="Migrator\MigrationServiceProvider"

Upgrading from v1.x to v2.0.

On v1.x, this package uses the same table name as the default migration engine., (*8)

On version v2, there is a separate table used for tracking migrations, and it defaults to: migrator_table, (*9)

If you are upgrading from v1, you may either rename the migrations table to migrator_table OR publish the config file and set the migrator table name to migrations., (*10)

Either should work., (*11)

v2 works alongside default migrations, for projects who want to namespace migrations but already have many migrations in place., (*12)

Usage

As the default Laravel migrator, this one has all the original commands, to list the available options, you can see all the available options using php artisan command., (*13)

migrator            Run the database migrations
migrator:fresh      Drop all tables and re-run all migrations
migrator:install    Create the migration repository
migrator:make       Create a new migration file
migrator:refresh    Reset and re-run all migrations
migrator:reset      Rollback all database migrations
migrator:rollback   Rollback the last database migration
migrator:status     Show the status of each migration

Creating Migrations

In order to generate an empty migration, please provide the migrator with the full qualified class name, as the example., (*14)

php artisan migrator:make 'MyApp\MyModule\Database\Migrations\CreateOrdersTable' --create=orders, (*15)

This will create a migration class into the right directory, the resulting file is slightly different from the default Laravel generated:, (*16)

<?php

namespace MyApp\MyModule\Database\Migrations;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{
    /**
     * @var \Illuminate\Database\Schema\Builder
     */
    protected $schema;

    /**
     * Migration constructor.
     */
     public function __construct()
     {
         $this->schema = app('db')->connection()->getSchemaBuilder();
     }

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $this->schema->create('orders', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $this->schema->drop('orders');
    }
}

To declare your table fields, just follow the usual schema build practices, this package don't make anything different there., (*17)

As the normal migrator, you can pass the option --table instead of --create in order to generate a update migration instead of a create one. Also, you can create a empty migration not passing any of those options., (*18)

Registering migrations.

Inside any service provider of your choice (usually on the same namespace that you're storing the migrations), you easily register the migrations using the Migrator\MigratorTrait:, (*19)

<?php

namespace MyApp\MyModule\Providers;

use Illuminate\Support\ServiceProvider;
use Migrator\MigratorTrait;
use MyApp\MyModule\Database\Migrations\CreateOrdersTable;
use MyApp\MyModule\Database\Migrations\CreateProductsTable;

class MyModuleServiceProvider extends ServiceProvider
{
    use MigratorTrait;

    public function register()
    {
        $this->migrations([
            CreateOrdersTable::class,
            CreateProductsTable::class,
        ]);
    }
}

The Versions

20/05 2018

dev-master

9999999-dev

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes

20/05 2018

1.3.3

1.3.3.0

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes

28/11 2017

1.3.2

1.3.2.0

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes

09/09 2017

dev-develop

dev-develop

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes

09/09 2017

1.3.1

1.3.1.0

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes

09/09 2017

1.3.0

1.3.0.0

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes

01/03 2017

dev-revert-3-master

dev-revert-3-master

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes

21/01 2017

1.2.0

1.2.0.0

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes

25/08 2016

1.1.0

1.1.0.0

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes

25/08 2016

1.0.2

1.0.2.0

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes

02/06 2016

1.0.1

1.0.1.0

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes

02/06 2016

1.0.0

1.0.0.0

Namespaced Migrations for Laravel 5.1+

  Sources   Download

MIT

by Diego Hernandes