PHP code example of lingyun / think-migration

1. Go to this page and download the library: Download lingyun/think-migration library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lingyun / think-migration example snippets


php think migrate:create AnyClassNameYouWant

php think migrate:run

php think migrate:rollback

php think migrate:breakpoint


php think migrate:breakpoint -t 20120103083322


php think migrate:breakpoint -r


php think migrate:status  

php think seed:create UserSeeder



use think\migration\Seeder;

class UserSeeder extends Seeder
{
    public function run()
    {
       //填充一条数据
        $this->table('user')->insert([
            'username'          => 'example1',
            'email'       => '[email protected]',
            'password'          => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
        ])->save();

        //填充一条数据
        $this->insert('user', [
            'username'          => 'example2',
            'email'       => '[email protected]',
            'password'          => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
        ]);     
    }
}

php think seed:run

php think seed:run --seed=UserSeeder



use think\migration\Seeder;

class UserSeeder extends Seeder
{
    public function run()
    {
        $this->factory()->create(User::class); //使用工厂类填充1条数据
        $this->factory()->of(User::class)->times(2)->create(); //使用工厂类填充2条数据
        $this->factory()->of(User::class, 'example')->create();
    }
}

php think factory:create User



use Faker\Generator as Faker;
use think\migration\Factory;

/** @var Factory $factory */
$factory->state(\app\model\User::class, 'unverified', ['email_verified_at' => null]);
$factory->state(\app\model\User::class, 'unremember', ['remember_token' => null]);