firefly-iii/database/migrations/2014_06_27_164836_create_transactions_table.php
2015-02-11 07:35:10 +01:00

58 lines
1.4 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
* @SuppressWarnings(PHPMD.ShortMethodName)
*
* Class CreateTransactionsTable
*
*/
class CreateTransactionsTable extends Migration
{
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('transactions');
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create(
'transactions', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->softDeletes();
$table->integer('account_id')->unsigned();
$table->integer('piggybank_id')->nullable()->unsigned();
$table->integer('transaction_journal_id')->unsigned();
$table->string('description', 255)->nullable();
$table->decimal('amount', 10, 2);
// connect account id:
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
// connect piggy banks
$table->foreign('piggybank_id')->references('id')->on('piggybanks')->onDelete('set null');
// connect transactions to transaction journals
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
}
);
}
}