Skip to content

Instantly share code, notes, and snippets.

@stevebauman
Last active August 29, 2015 14:16
Show Gist options
  • Save stevebauman/9dac869eb860b5918804 to your computer and use it in GitHub Desktop.
Save stevebauman/9dac869eb860b5918804 to your computer and use it in GitHub Desktop.
Transaction Tables
Schema::create('inventory_transactions', function (Blueprint $table)
{
$table->increments('id');
$table->timestamps();
$table->integer('stock_id')->unsigned();
$table->string('state');
$table->decimal('quantity', 8, 2)->default(0);
$table->foreign('stock_id')->references('id')->on('inventory_stocks')
->onUpdate('restrict')
->onDelete('cascade');
});
Schema::create('inventory_transaction_histories', function (Blueprint $table)
{
$table->increments('id');
$table->timestamps();
$table->integer('transaction_id')->unsigned();
/*
* Allows tracking states for each transaction
*/
$table->string('state_before');
$table->string('state_after');
/*
* Allows tracking the quantities of each transaction
*/
$table->string('quantity_before');
$table->string('quantity_after');
$table->foreign('transaction_id')->references('id')->on('inventory_transactions')
->onUpdate('restrict')
->onDelete('cascade');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment