New migrations.

This commit is contained in:
James Cole 2016-06-18 07:36:15 +02:00
parent 5dc8620c43
commit 8ee1676f0a
6 changed files with 248 additions and 73 deletions

View File

@ -151,6 +151,7 @@ class Importer
$transactionType = $this->getTransactionType(); // defaults to deposit $transactionType = $this->getTransactionType(); // defaults to deposit
$errors = new MessageBag; $errors = new MessageBag;
$journal = TransactionJournal::create( $journal = TransactionJournal::create(
[ [
'user_id' => Auth::user()->id, 'user_id' => Auth::user()->id,

View File

@ -355,8 +355,6 @@ class PiggyBankController extends Controller
'startdate' => new Carbon, 'startdate' => new Carbon,
'account_id' => intval($request->get('account_id')), 'account_id' => intval($request->get('account_id')),
'targetamount' => round($request->get('targetamount'), 2), 'targetamount' => round($request->get('targetamount'), 2),
'remind_me' => false,
'reminder_skip' => 0,
'order' => $repository->getMaxOrder() + 1, 'order' => $repository->getMaxOrder() + 1,
'targetdate' => strlen($request->get('targetdate')) > 0 ? new Carbon($request->get('targetdate')) : null, 'targetdate' => strlen($request->get('targetdate')) > 0 ? new Carbon($request->get('targetdate')) : null,
]; ];
@ -391,8 +389,6 @@ class PiggyBankController extends Controller
'startdate' => is_null($piggyBank->startdate) ? $piggyBank->created_at : $piggyBank->startdate, 'startdate' => is_null($piggyBank->startdate) ? $piggyBank->created_at : $piggyBank->startdate,
'account_id' => intval($request->get('account_id')), 'account_id' => intval($request->get('account_id')),
'targetamount' => round($request->get('targetamount'), 2), 'targetamount' => round($request->get('targetamount'), 2),
'remind_me' => false,
'reminder_skip' => 0,
'targetdate' => strlen($request->get('targetdate')) > 0 ? new Carbon($request->get('targetdate')) : null, 'targetdate' => strlen($request->get('targetdate')) > 0 ? new Carbon($request->get('targetdate')) : null,
]; ];

View File

@ -31,8 +31,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property \Carbon\Carbon $targetdate * @property \Carbon\Carbon $targetdate
* @property integer $order * @property integer $order
* @property boolean $encrypted * @property boolean $encrypted
* @property boolean $remind_me
* @property integer $reminder_skip
* @property-read Account $account * @property-read Account $account
* @property-read \Illuminate\Database\Eloquent\Collection|PiggyBankRepetition[] $piggyBankRepetitions * @property-read \Illuminate\Database\Eloquent\Collection|PiggyBankRepetition[] $piggyBankRepetitions
* @property-read \Illuminate\Database\Eloquent\Collection|PiggyBankEvent[] $piggyBankEvents * @property-read \Illuminate\Database\Eloquent\Collection|PiggyBankEvent[] $piggyBankEvents
@ -59,7 +57,7 @@ class PiggyBank extends Model
use SoftDeletes; use SoftDeletes;
protected $fillable protected $fillable
= ['name', 'account_id', 'order', 'targetamount', 'startdate', 'targetdate', 'remind_me', 'reminder_skip']; = ['name', 'account_id', 'order', 'targetamount', 'startdate', 'targetdate'];
protected $hidden = ['targetamount_encrypted', 'encrypted']; protected $hidden = ['targetamount_encrypted', 'encrypted'];
protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'targetdate']; protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'targetdate'];

View File

@ -171,9 +171,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
*/ */
public function store(array $data): PiggyBank public function store(array $data): PiggyBank
{ {
$data['remind_me'] = false;
$data['reminder_skip'] = 0;
$piggyBank = PiggyBank::create($data); $piggyBank = PiggyBank::create($data);
return $piggyBank; return $piggyBank;

View File

@ -646,8 +646,6 @@ class TestData
'name' => Crypt::encrypt($piggyBank['name']), 'name' => Crypt::encrypt($piggyBank['name']),
'targetamount' => $piggyBank['targetamount'], 'targetamount' => $piggyBank['targetamount'],
'startdate' => $piggyBank['startdate'], 'startdate' => $piggyBank['startdate'],
'reminder_skip' => 0,
'remind_me' => 0,
'order' => $piggyBank['order'], 'order' => $piggyBank['order'],
'encrypted' => 1, 'encrypted' => 1,
] ]

View File

@ -3,8 +3,46 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
/**
* Class CreateMainTables
*/
class CreateMainTables extends Migration class CreateMainTables extends Migration
{ {
/**
* Reverse the migrations.
*/
public function down()
{
//
Schema::drop('account_meta');
Schema::drop('piggy_bank_repetitions');
Schema::drop('attachments');
Schema::drop('limit_repetitions');
Schema::drop('budget_limits');
Schema::drop('export_jobs');
Schema::drop('preferences');
Schema::drop('role_user');
Schema::drop('rule_actions');
Schema::drop('rule_triggers');
Schema::drop('rules');
Schema::drop('rule_groups');
Schema::drop('category_transaction');
Schema::drop('budget_transaction');
Schema::drop('transactions');
Schema::drop('piggy_bank_events');
Schema::drop('piggy_banks');
Schema::drop('accounts');
Schema::drop('category_transaction_journal');
Schema::drop('budget_transaction_journal');
Schema::drop('categories');
Schema::drop('budgets');
Schema::drop('tag_transaction_journal');
Schema::drop('tags');
Schema::drop('journal_meta');
Schema::drop('transaction_journals');
Schema::drop('bills');
}
/** /**
* Run the migrations. * Run the migrations.
*/ */
@ -22,44 +60,8 @@ class CreateMainTables extends Migration
$this->createPreferencesTable(); $this->createPreferencesTable();
$this->createRoleTable(); $this->createRoleTable();
$this->createRuleTables(); $this->createRuleTables();
// $this->createTagsTable(); $this->createTagsTable();
// $this->createTransactionTables(); $this->createTransactionTables();
}
/**
* Reverse the migrations.
*/
public function down()
{
//
Schema::drop('account_meta');
Schema::drop('accounts');
Schema::drop('piggy_bank_repetitions');
Schema::drop('piggy_banks');
Schema::drop('attachments');
Schema::drop('bills');
Schema::drop('limit_repetitions');
Schema::drop('budget_limits');
Schema::drop('budgets');
Schema::drop('categories');
Schema::drop('export_jobs');
Schema::drop('preferences');
Schema::drop('role_user');
Schema::drop('rule_actions');
Schema::drop('rule_triggers');
Schema::drop('rules');
Schema::drop('rule_groups');
} }
/** /**
@ -79,8 +81,8 @@ class CreateMainTables extends Migration
$table->decimal('virtual_balance', 10, 4); $table->decimal('virtual_balance', 10, 4);
$table->string('iban', 255); $table->string('iban', 255);
$table->tinyInteger('active', false, true)->default(1); $table->boolean('active')->default(1);
$table->tinyInteger('encrypted', false, true)->default(0); $table->boolean('encrypted')->default(0);
// link user id to users table // link user id to users table
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@ -118,7 +120,7 @@ class CreateMainTables extends Migration
$table->softDeletes(); $table->softDeletes();
$table->integer('user_id', false, true); $table->integer('user_id', false, true);
$table->integer('attachable_id', false, true); $table->integer('attachable_id', false, true);
$table->string('attachable_name', 255); $table->string('attachable_type', 255);
$table->string('md5', 32); $table->string('md5', 32);
$table->string('filename', 1024); $table->string('filename', 1024);
$table->string('title', 1024); $table->string('title', 1024);
@ -126,7 +128,7 @@ class CreateMainTables extends Migration
$table->text('notes'); $table->text('notes');
$table->string('mime', 200); $table->string('mime', 200);
$table->integer('size', false, true); $table->integer('size', false, true);
$table->tinyInteger('uploaded', false, true)->default(1); $table->boolean('uploaded')->default(1);
// link user id to users table // link user id to users table
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@ -153,9 +155,10 @@ class CreateMainTables extends Migration
$table->date('date'); $table->date('date');
$table->string('repeat_freq', 30); $table->string('repeat_freq', 30);
$table->smallInteger('skip', false, true)->default(0); $table->smallInteger('skip', false, true)->default(0);
$table->tinyInteger('active', false, true)->default(1); $table->boolean('automatch')->default(1);
$table->tinyInteger('name_encrypted', false, true)->default(0); $table->boolean('active')->default(1);
$table->tinyInteger('match_encrypted', false, true)->default(0); $table->boolean('name_encrypted')->default(0);
$table->boolean('match_encrypted')->default(0);
// link user id to users table // link user id to users table
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@ -176,8 +179,8 @@ class CreateMainTables extends Migration
$table->softDeletes(); $table->softDeletes();
$table->integer('user_id', false, true); $table->integer('user_id', false, true);
$table->string('name', 1024); $table->string('name', 1024);
$table->tinyInteger('active', false, true)->default(1); $table->boolean('active')->default(1);
$table->tinyInteger('encrypted', false, true)->default(0); $table->boolean('encrypted')->default(0);
// link user id to users table // link user id to users table
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@ -196,7 +199,7 @@ class CreateMainTables extends Migration
$table->date('startdate'); $table->date('startdate');
$table->decimal('amount', 10, 4); $table->decimal('amount', 10, 4);
$table->string('repeat_freq', 30); $table->string('repeat_freq', 30);
$table->tinyInteger('repeats', false, true)->default(0); $table->boolean('repeats')->default(0);
// link budget id to budgets table // link budget id to budgets table
$table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade'); $table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade');
@ -232,7 +235,7 @@ class CreateMainTables extends Migration
$table->softDeletes(); $table->softDeletes();
$table->integer('user_id', false, true); $table->integer('user_id', false, true);
$table->string('name', 1024); $table->string('name', 1024);
$table->tinyInteger('encrypted', false, true)->default(0); $table->boolean('encrypted')->default(0);
// link user id to users table // link user id to users table
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@ -275,7 +278,8 @@ class CreateMainTables extends Migration
$table->date('startdate'); $table->date('startdate');
$table->date('targetdate'); $table->date('targetdate');
$table->integer('order', false, true); $table->integer('order', false, true);
$table->tinyInteger('active', false, true)->default(0); $table->boolean('active')->default(0);
$table->boolean('encrypted')->default(1);
// link to account_id to accounts // link to account_id to accounts
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
@ -293,7 +297,6 @@ class CreateMainTables extends Migration
$table->date('targetdate'); $table->date('targetdate');
$table->decimal('currentamount', 10, 4); $table->decimal('currentamount', 10, 4);
// link to account_id to accounts
$table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade'); $table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade');
} }
@ -313,7 +316,6 @@ class CreateMainTables extends Migration
$table->string('name', 1024); $table->string('name', 1024);
$table->text('data'); $table->text('data');
// link user id to users table
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
} }
); );
@ -352,7 +354,7 @@ class CreateMainTables extends Migration
$table->string('title', 255); $table->string('title', 255);
$table->text('description'); $table->text('description');
$table->integer('order', false, true); $table->integer('order', false, true);
$table->tinyInteger('active', false, true)->default(1); $table->boolean('active')->default(1);
// link user id to users table // link user id to users table
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@ -370,8 +372,8 @@ class CreateMainTables extends Migration
$table->string('title', 255); $table->string('title', 255);
$table->text('description'); $table->text('description');
$table->integer('order', false, true); $table->integer('order', false, true);
$table->tinyInteger('active', false, true)->default(1); $table->boolean('active')->default(1);
$table->tinyInteger('stop_processing', false, true)->default(0); $table->boolean('stop_processing')->default(0);
// link user id to users table // link user id to users table
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@ -392,9 +394,8 @@ class CreateMainTables extends Migration
$table->string('action_value', 255); $table->string('action_value', 255);
$table->integer('order', false, true); $table->integer('order', false, true);
$table->tinyInteger('active', false, true)->default(1); $table->boolean('active')->default(1);
$table->tinyInteger('stop_processing', false, true)->default(0); $table->boolean('stop_processing')->default(0);
// link rule id to rules table // link rule id to rules table
@ -413,9 +414,8 @@ class CreateMainTables extends Migration
$table->string('trigger_value', 255); $table->string('trigger_value', 255);
$table->integer('order', false, true); $table->integer('order', false, true);
$table->tinyInteger('active', false, true)->default(1); $table->boolean('active')->default(1);
$table->tinyInteger('stop_processing', false, true)->default(0); $table->boolean('stop_processing')->default(0);
// link rule id to rules table // link rule id to rules table
@ -424,4 +424,189 @@ class CreateMainTables extends Migration
); );
} }
} }
/**
*
*/
private function createTagsTable()
{
if (!Schema::hasTable('tags')) {
Schema::create(
'tags', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->softDeletes();
$table->integer('user_id', false, true);
$table->string('tag', 1024);
$table->string('tagMode', 1024);
$table->date('date');
$table->text('description');
$table->decimal('latitude', 18, 12);
$table->decimal('longitude', 18, 12);
$table->boolean('zoomLevel');
// link user id to users table
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
}
);
}
}
private function createTransactionTables()
{
if (!Schema::hasTable('transaction_journals')) {
Schema::create(
'transaction_journals', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->softDeletes();
$table->integer('user_id', false, true);
$table->integer('transaction_type_id', false, true);
$table->integer('bill_id', false, true)->nullable();
$table->integer('transaction_currency_id', false, true);
$table->string('description', 1024);
$table->date('date');
$table->date('interest_date')->nullable();
$table->date('book_date')->nullable();
$table->date('process_date')->nullable();
$table->integer('order', false, true);
$table->integer('tag_count', false, true);
$table->boolean('encrypted')->default(1);
$table->boolean('completed')->default(1);
// links to other tables:
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('transaction_type_id')->references('id')->on('transaction_types')->onDelete('cascade');
$table->foreign('bill_id')->references('id')->on('bills')->onDelete('set null');
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade');
}
);
}
if (!Schema::hasTable('journal_meta')) {
Schema::create(
'journal_meta', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('transaction_journal_id', false, true);
$table->string('name', 255);
$table->text('data');
$table->string('hash', 64);
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
}
);
}
if (!Schema::hasTable('tag_transaction_journal')) {
Schema::create(
'tag_transaction_journal', function (Blueprint $table) {
$table->increments('id');
$table->integer('tag_id', false, true);
$table->integer('transaction_journal_id', false, true);
$table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
}
);
}
if (!Schema::hasTable('budget_transaction_journal')) {
Schema::create(
'budget_transaction_journal', function (Blueprint $table) {
$table->increments('id');
$table->integer('budget_id', false, true);
$table->integer('transaction_journal_id', false, true);
$table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade');
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
}
);
}
if (!Schema::hasTable('category_transaction_journal')) {
Schema::create(
'category_transaction_journal', function (Blueprint $table) {
$table->increments('id');
$table->integer('category_id', false, true);
$table->integer('transaction_journal_id', false, true);
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
}
);
}
if (!Schema::hasTable('piggy_bank_events')) {
Schema::create(
'piggy_bank_events', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('piggy_bank_id', false, true);
$table->integer('transaction_journal_id', false, true)->nullable();
$table->date('date');
$table->decimal('amount', 10, 4);
$table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade');
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('set null');
}
);
}
if (!Schema::hasTable('transactions')) {
Schema::create(
'transactions', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->softDeletes();
$table->integer('account_id', false, true);
$table->integer('transaction_journal_id', false, true);
$table->string('description', 255);
$table->decimal('amount', 10, 4);
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
$table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');
}
);
}
if (!Schema::hasTable('budget_transaction')) {
Schema::create(
'budget_transaction', function (Blueprint $table) {
$table->increments('id');
$table->integer('budget_id', false, true);
$table->integer('transaction_id', false, true);
$table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade');
$table->foreign('transaction_id')->references('id')->on('transactions')->onDelete('cascade');
}
);
}
if (!Schema::hasTable('')) {
Schema::create(
'category_transaction', function (Blueprint $table) {
$table->increments('id');
$table->integer('category_id', false, true);
$table->integer('transaction_id', false, true);
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
$table->foreign('transaction_id')->references('id')->on('transactions')->onDelete('cascade');
}
);
}
}
} }