Skip to content

Instantly share code, notes, and snippets.

@kiebekierror
Created March 22, 2019 03:44
Show Gist options
  • Save kiebekierror/edcdc374c9e69ac7c48a6054b19db49e to your computer and use it in GitHub Desktop.
Save kiebekierror/edcdc374c9e69ac7c48a6054b19db49e to your computer and use it in GitHub Desktop.
lumen 数据库迁移工具

migration 的操作

创建 migration

php artisan make:migration [自定义名称]

PHP代码

<?php

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

class AddFdiTemInvToAlevel extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('alevel', function (Blueprint $table) {
            $table->bigInteger('fdiTeamInv')->comment('团队人数')->default(0)->after('fdiDirInv');
        });

        DB::unprepared("
            update alevel set fdiTeamInv=20 where ID=100;
            update alevel set fdiTeamInv=100 where ID=200;
            update alevel set fdiTeamInv=300 where ID=300;
            update alevel set fdiTeamInv=1000 where ID=400;
            update alevel set fdiTeamInv=5000 where ID=500;
        ");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}

执行 migration

php artisan migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment