Refactoring item_user migration

Delete the separate value for item_user,
adding a primary key to the pivot table
and removing the timestamp as it is
not necessary.
This commit is contained in:
Bruno F. Fontes 2018-09-14 17:24:26 -03:00
parent ee9a01651d
commit e2942224db
2 changed files with 8 additions and 33 deletions

View File

@ -21,6 +21,13 @@ class CreateItemsTable extends Migration
$table->integer('waiting_user_id')->nullable(); $table->integer('waiting_user_id')->nullable();
$table->timestamps(); $table->timestamps();
}); });
Schema::create('item_user', function (Blueprint $table) {
$table->increments('id');
$table->integer('item_id');
$table->integer('user_id');
$table->primary(['item_id', 'user_id']);
});
} }
/** /**
@ -31,5 +38,6 @@ class CreateItemsTable extends Migration
public function down() public function down()
{ {
Schema::dropIfExists('items'); Schema::dropIfExists('items');
Schema::dropIfExists('item_user');
} }
} }

View File

@ -1,33 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ItemUser extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('item_user', function (Blueprint $table) {
$table->increments('id');
$table->integer('item_id');
$table->integer('user_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('item_user');
}
}