GithubHelp home page GithubHelp logo

migrator-1's Introduction

artesaos/migrator

Latest Stable Version Total Downloads Monthly Downloads License

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.

There is no timestamp previews since the run order is based on how you register the migrations.

Warning

This Package Supports Laravel starting on 5.2 up to the latest stable version.

Installing

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

composer require artesaos/migrator

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

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

And publish configuration: with

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.

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

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.

Either should work.

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

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.

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.

php artisan migrator:make 'MyApp\MyModule\Database\Migrations\CreateOrdersTable' --create=orders

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

<?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.

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.

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:

<?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,
        ]);
    }
}

migrator-1's People

Contributors

cenoura avatar emtudo avatar fraterblack avatar hernandev avatar vinicius73 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.