diff --git a/database/migrations/2016_04_23_182223_payments_changes.php b/database/migrations/2016_04_23_182223_payments_changes.php index 2e6cdcb6ec05..c250c897333d 100644 --- a/database/migrations/2016_04_23_182223_payments_changes.php +++ b/database/migrations/2016_04_23_182223_payments_changes.php @@ -22,6 +22,37 @@ class PaymentsChanges extends Migration (new \PaymentStatusSeeder())->run(); + Schema::dropIfExists('payment_methods'); + + Schema::create('payment_methods', function($table) + { + $table->increments('id'); + $table->unsignedInteger('account_id'); + $table->unsignedInteger('contact_id')->nullable(); + $table->unsignedInteger('account_gateway_token_id'); + $table->unsignedInteger('payment_type_id'); + $table->string('source_reference'); + + $table->unsignedInteger('routing_number')->nullable(); + $table->smallInteger('last4')->unsigned()->nullable(); + $table->date('expiration')->nullable(); + $table->string('email')->nullable(); + $table->unsignedInteger('currency_id')->nullable(); + $table->string('status')->nullable(); + + $table->timestamps(); + $table->softDeletes(); + + $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); + $table->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade'); + $table->foreign('account_gateway_token_id')->references('id')->on('account_gateway_tokens'); + $table->foreign('payment_type_id')->references('id')->on('payment_types'); + $table->foreign('currency_id')->references('id')->on('currencies'); + + $table->unsignedInteger('public_id')->index(); + $table->unique( array('account_id','public_id') ); + }); + Schema::table('payments', function($table) { $table->decimal('refunded', 13, 2); @@ -33,6 +64,9 @@ class PaymentsChanges extends Migration $table->date('expiration')->nullable(); $table->text('gateway_error')->nullable(); $table->string('email')->nullable(); + + $table->unsignedInteger('payment_method_id')->nullable(); + $table->foreign('payment_method_id')->references('id')->on('payment_methods'); }); Schema::table('invoices', function($table) @@ -43,6 +77,17 @@ class PaymentsChanges extends Migration \DB::table('invoices') ->where('auto_bill', '=', 1) ->update(array('client_enable_auto_bill' => 1, 'auto_bill' => AUTO_BILL_OPT_OUT)); + + + Schema::table('account_gateway_tokens', function($table) + { + $table->unsignedInteger('default_payment_method_id')->nullable(); + $table->foreign('default_payment_method_id')->references('id')->on('payment_methods'); + + $table->boolean('uses_local_payment_methods')->defalut(true); + }); + + \DB::table('account_gateway_tokens')->update(array('uses_local_payment_methods' => false)); } /** @@ -63,6 +108,9 @@ class PaymentsChanges extends Migration $table->dropColumn('expiration'); $table->dropColumn('gateway_error'); $table->dropColumn('email'); + + $table->dropForeign('payments_payment_method_id_foreign'); + $table->dropColumn('payment_method_id'); }); \DB::table('invoices') @@ -84,5 +132,14 @@ class PaymentsChanges extends Migration }); Schema::dropIfExists('payment_statuses'); + + Schema::table('account_gateway_tokens', function($table) + { + $table->dropForeign('account_gateway_tokens_default_payment_method_id_foreign'); + $table->dropColumn('default_payment_method_id'); + $table->dropColumn('uses_local_payment_methods'); + }); + + Schema::dropIfExists('payment_methods'); } } diff --git a/database/migrations/2016_05_10_144219_wepay_integration.php b/database/migrations/2016_05_10_144219_wepay_integration.php deleted file mode 100644 index c2a48afd8098..000000000000 --- a/database/migrations/2016_05_10_144219_wepay_integration.php +++ /dev/null @@ -1,83 +0,0 @@ -increments('id'); - $table->unsignedInteger('account_id'); - $table->unsignedInteger('contact_id')->nullable(); - $table->unsignedInteger('account_gateway_token_id'); - $table->unsignedInteger('payment_type_id'); - $table->string('source_reference'); - - $table->unsignedInteger('routing_number')->nullable(); - $table->smallInteger('last4')->unsigned()->nullable(); - $table->date('expiration')->nullable(); - $table->string('email')->nullable(); - $table->unsignedInteger('currency_id')->nullable(); - $table->string('status')->nullable(); - - $table->timestamps(); - $table->softDeletes(); - - $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); - $table->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade'); - $table->foreign('account_gateway_token_id')->references('id')->on('account_gateway_tokens'); - $table->foreign('payment_type_id')->references('id')->on('payment_types'); - $table->foreign('currency_id')->references('id')->on('currencies'); - - $table->unsignedInteger('public_id')->index(); - $table->unique( array('account_id','public_id') ); - }); - - Schema::table('payments', function($table) - { - $table->unsignedInteger('payment_method_id')->nullable(); - $table->foreign('payment_method_id')->references('id')->on('payment_methods'); - }); - - Schema::table('account_gateway_tokens', function($table) - { - $table->unsignedInteger('default_payment_method_id')->nullable(); - $table->foreign('default_payment_method_id')->references('id')->on('payment_methods'); - - $table->boolean('uses_local_payment_methods')->defalut(true); - }); - - \DB::table('account_gateway_tokens')->update(array('uses_local_payment_methods' => false)); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('payments', function($table) - { - $table->dropForeign('payments_payment_method_id_foreign'); - $table->dropColumn('payment_method_id'); - }); - - Schema::table('account_gateway_tokens', function($table) - { - $table->dropForeign('account_gateway_tokens_default_payment_method_id_foreign'); - $table->dropColumn('default_payment_method_id'); - $table->dropColumn('uses_local_payment_methods'); - }); - - Schema::dropIfExists('payment_methods'); - } -}