Created
February 5, 2018 05:49
-
-
Save duan-li/5d058a9ce401919415270d0adae898cf to your computer and use it in GitHub Desktop.
basic database migration for a simple laravel project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// up users | |
$table = 'users'; | |
if (!Schema::hasTable($table)) { | |
Schema::create($table, function (Blueprint $table) { | |
$table->increments('id'); | |
$table->string('display_name'); | |
$table->string('email'); | |
$table->timestamps(); | |
$table->softDeletes(); | |
}); | |
} | |
// down users | |
Schema::dropIfExists($table); | |
// up credentials | |
$table = 'credentials'; | |
if (!Schema::hasTable($table)) { | |
Schema::create($table, function (Blueprint $table) { | |
$table->increments('id'); | |
$table->integer('user_id')->unsigned(); | |
$table->foreign('user_id')->references('id')->on('users'); | |
$table->string('username'); | |
$table->string('password'); | |
$table->datetime('last_login_at'); | |
$table->timestamps(); | |
$table->softDeletes(); | |
}); | |
} | |
// down credentials | |
Schema::dropIfExists($table); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment