2017 © Pedro Peláez
 

framework-extension laravel-versionia

Version based database migration system for Laravel 5.

image

jumilla/laravel-versionia

Version based database migration system for Laravel 5.

  • Tuesday, September 19, 2017
  • by jumilla
  • Repository
  • 3 Watchers
  • 24 Stars
  • 2,447 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 17 Versions
  • 1 % Grown

The README.md

LARAVEL VERSIONIA

Build Status Quality Score Code Coverage Latest Stable Version Total Downloads Software License, (*1)

日本語ドキュメント - Japanese, (*2)

Version based database migration system for Laravel 5., (*3)

Laravel Versionia is version based database migration system. It can be used in Laravel 5 and Lumen 5., (*4)

Concepts

The feature as "migration" loads standards into Laravel 4 and 5 for management of a database (RDB) schema., (*5)

Migration is the mechanism that making of a schema and change are being managed by time series. A PHP class for the mounting of "seed" as which data is defined an early stage of a data base and the artisan command are also offered., (*6)

Versionia makes standard migration easier to use., (*7)

  • Add the programmer specified "version" to migration of Laravel 5.
  • As Seeder class of Laravel 5 can be distinguished under the name, more than one seed is changed easily.
  • It's offered by a service provider along architecture of Laravel 5.
  • Migration and seed classes can be arranged under the app directory.

A service provider is employed as Laravel 5 application and the mechanism that a Composer package offers the function. The definition which are routing and an event listener by a service provider is given, but migrations and seeds can be defined now here., (*8)

Installation method

[A] Include Laravel Extension (Laravel).

When using Laravel 5, it's recommendation here. Note: Pacakge Discovery supported., (*9)

Use Composer., (*10)

composer require laravel-plus/extension

Please read the explanation of Laravel Extension for more information., (*11)

[B] Include Versionia (Laravel)

Note: Pacakge Discovery supported., (*12)

Use Composer., (*13)

composer require jumilla/laravel-versionia

[C] Include Versionia (Lumen)

When using Lumen, it's recommendation here., (*14)

Use Composer., (*15)

composer require jumilla/laravel-versionia

Next the next code is added to boostrap/app.php., (*16)

$app->register(Jumilla\Versionia\Laravel\ServiceProvider::class);

Migration version definition

There was Naming Rule in the file name of migration class so far, and an order of migration had been decided by the file generation date and time when you were embedded in the file name. A group and the version are given specifically every migration class and it's defined by the DatabaseServiceProvider class in Versionia., (*17)

<?php

namespace App\Providers;

use Jumilla\Versionia\Laravel\Support\DatabaseServiceProvider as ServiceProvider;
use App\Database\Migrations;
use App\Database\Seeds;

class DatabaseServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $this->migrations('framework', [
            '1.0' => Migrations\Framework_1_0::class,
        ]);

        $this->migrations('app', [
            '1.0' => Migrations\App_1_0::class,
        ]);

        // ... seed definition ...
    }
}

Registration of DatabaseServiceProvider

When making a service provider newly, please register. When using Laravel Extension it's included already, so addition is unnecessary., (*18)

Laravel

App\Providers\DatabaseServiceProvider::class is added to app\config.php., (*19)

    'providers' => [
        ...
        App\Providers\ConfigServiceProvider::class,
        App\Providers\DatabaseServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        ...
    ],

Lumen

The next code is added to bootstrap\app.php., (*20)

$app->register(App\Providers\DatabaseServiceProvider::class);

Version Number

Versionia is using PHP standard function version_compare() for comparison of a version number. Please designate a character string of a dot end as a version number., (*21)

Migration class

The one generated by make:migration of Laravel 5 standard can use migration class just as it is., (*22)

When arranging in app\Database\Migrations directory of recommendation, please add namespace App\Database\Migrations., (*23)

The next code is a sample of migration definition., (*24)

<?php

namespace App\Database\Migrations;

use Jumilla\Versionia\Laravel\Support\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class App_1_0 extends Migration
{
    /**
     * Migrate the database to forward.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->text('content');
            $table->json('properties');
            $table->timestamps();
        });
    }

    /**
     * Migrate the database to backword.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}

Seed class

A seed defines test, staging, production by the next sample code. The 2nd argument of method seeds() designates test by designation of a default seed., (*25)

<?php

namespace App\Providers;

use Jumilla\Versionia\Laravel\Support\DatabaseServiceProvider as ServiceProvider;
use App\Database\Migrations;
use App\Database\Seeds;

class DatabaseServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //... migration definition ...

        $this->seeds([
            'test' => Seeds\Test::class,
            'staging' => Seeds\Staging::class,
            'production' => Seeds\Production::class,
        ], 'test');
    }
}

A seed class is described as follows., (*26)

<?php

namespace App\Database\Seeds;

use Jumilla\Versionia\Laravel\Support\Seeder;
use Carbon\Carbon;

class Staging extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $now = Carbon::now();

        app('db')->table('posts')->truncate();

        app('db')->table('posts')->insert([
            'title' => 'Sample post',
            'content' => 'Hello laravel world.',
            'properties' => json_encode([
                'author' => 'Seeder',
            ], JSON_PRETTY_PRINT),
            'created_at' => $now,
            'updated_at' => $now,
        ]);
    }
}

Commands

database:status

Migration and seed definition, installation state are displayed., (*27)

php artisan database:status

database:upgrade

Run migration method up() of all groups, then up-to-date。, (*28)

php artisan database:upgrade

It's possible to make them seed after migration., (*29)

php artisan database:upgrade --seed <seed>

database:clean

Run migation method down() of all groups, then clean state., (*30)

php artisan database:clean

database:refresh

Migration of all groups is redone., (*31)

It's same run database:clean and database:upgrade., (*32)

php artisan database:refresh

It's possible to run seed after migration., (*33)

php artisan database:refresh --seed <seed>

database:rollback

The version of the designation group is returned one., (*34)

php artisan database:rollback <group>

When --all option specified, remove all version of group., (*35)

php artisan database:rollback <group> --all

database:again

Re-run latest migration version of group., (*36)

It's same effect as run database:rollback <group> and database:upgrade., (*37)

php artisan database:again <group>

It's possible to run seed after migration., (*38)

php artisan database:again <group> --seed <seed>

database:seed

Run specified seed., (*39)

php artisan database:seed <seed>

When omitting <seed>, run default seed., (*40)

php artisan database:seed

古川 文生 / Fumio Furukawa (fumio@jumilla.me), (*41)

License

MIT, (*42)

The Versions

19/09 2017

dev-master

9999999-dev http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

19/09 2017

dev-develop

dev-develop http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

19/09 2017

2.0.0

2.0.0.0 http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

29/01 2017

1.3.5

1.3.5.0 http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

27/01 2017

1.3.4

1.3.4.0 http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

26/12 2015

v1.2

1.2.0.0 http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

16/10 2015

v1.1.1

1.1.1.0 http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

15/10 2015

v1.1.0

1.1.0.0 http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

08/10 2015

v1.0.4

1.0.4.0 http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

24/08 2015

v1.0.3

1.0.3.0 http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

08/08 2015

v1.0.2

1.0.2.0 http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

28/07 2015

v1.0.1

1.0.1.0 http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes

22/07 2015

v1.0

1.0.0.0 http://jumilla.me

Version based database migration system for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Fumio Furukawa

laravel migration laravel 5 databaes