Skip to content

Instantly share code, notes, and snippets.

@duan-li
Created February 5, 2018 05:49
Show Gist options
  • Save duan-li/5d058a9ce401919415270d0adae898cf to your computer and use it in GitHub Desktop.
Save duan-li/5d058a9ce401919415270d0adae898cf to your computer and use it in GitHub Desktop.
basic database migration for a simple laravel project
<?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