lawrence/fast-migrate

迁移更快!

v1.2 2015-11-04 02:53 UTC

This package is not auto-updated.

Last update: 2024-09-18 09:46:27 UTC


README

使用FastMigrate迁移更快!FastMigrate本质上是一个围绕Laravel迁移类的包装器。FastMigrate旨在使创建表更简单、更快。

FastMigrate需要Laravel >= 5.0

安装

要安装,只需运行composer require lawrence/fast-migrate:dev-master

示例

以下展示了FastMigrate的使用示例。

<?php

use FastMigrate\FastMigrator;
use Schema;

class ExampleMigration extends FastMigrator
{

    public function up()
    {
        $I = $this;
        $I->wantATable('users')
            ->withStrings('username', 'password');

        $I->wantATable('roles')
            ->withStrings('description');

        $I->wantATable('posts')
            ->withStrings('title', 'content')
            ->withIntegers('score');

        $I->want('users')
            ->toHaveMany('posts');
        $I->want('users')
            ->toHaveOne('roles');

        $I->amReadyForMigration();
    }

    public function down()
    {
        Schema::dropIfExists('users');
        Schema::dropIfExists('posts');
        Schema::dropIfExists('roles');
    }
}

运行上述迁移将生成以下三个表

- users:
    - id
    - created_at
    - updated_at
    - username
    - password
    - role_id

- roles:
    - id
    - created_at
    - updated_at
    - description

- posts:
    - id
    - created_at
    - updated_at
    - title
    - content
    - score
    - user_id