From 07367c4f3aa4281c18992e963e8a6a181a445b74 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 2 Nov 2017 12:05:36 +0200 Subject: [PATCH] Checks to prevent migration errors --- ...016_11_03_113316_add_invoice_signature.php | 11 ++++++++-- .../2016_11_28_092904_add_task_projects.php | 22 +++++++++++++------ .../2017_01_01_214241_add_inclusive_taxes.php | 8 ++++--- ..._03_16_085702_add_gateway_fee_location.php | 8 ++++++- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/database/migrations/2016_11_03_113316_add_invoice_signature.php b/database/migrations/2016_11_03_113316_add_invoice_signature.php index b60ddacb51..3e61227e74 100644 --- a/database/migrations/2016_11_03_113316_add_invoice_signature.php +++ b/database/migrations/2016_11_03_113316_add_invoice_signature.php @@ -28,9 +28,17 @@ class AddInvoiceSignature extends Migration if (Utils::isNinja()) { Schema::table('payment_methods', function ($table) { $table->unsignedInteger('account_gateway_token_id')->nullable()->change(); - $table->dropForeign('payment_methods_account_gateway_token_id_foreign'); }); + // This may fail if the foreign key doesn't exist + try { + Schema::table('payment_methods', function ($table) { + $table->dropForeign('payment_methods_account_gateway_token_id_foreign'); + }); + } catch (Exception $e) { + // do nothing + } + Schema::table('payment_methods', function ($table) { $table->foreign('account_gateway_token_id')->references('id')->on('account_gateway_tokens')->onDelete('cascade'); }); @@ -41,7 +49,6 @@ class AddInvoiceSignature extends Migration Schema::table('payments', function ($table) { $table->foreign('payment_method_id')->references('id')->on('payment_methods')->onDelete('cascade'); - ; }); } } diff --git a/database/migrations/2016_11_28_092904_add_task_projects.php b/database/migrations/2016_11_28_092904_add_task_projects.php index b227ae92ef..539e9d99da 100644 --- a/database/migrations/2016_11_28_092904_add_task_projects.php +++ b/database/migrations/2016_11_28_092904_add_task_projects.php @@ -32,7 +32,7 @@ class AddTaskProjects extends Migration Schema::table('tasks', function ($table) { $table->unsignedInteger('project_id')->nullable()->index(); - + if (Schema::hasColumn('tasks', 'description')) { $table->text('description')->change(); } @@ -54,17 +54,25 @@ class AddTaskProjects extends Migration }); // add 'delete cascase' to resolve error when deleting an account - Schema::table('account_gateway_tokens', function ($table) { - $table->dropForeign('account_gateway_tokens_default_payment_method_id_foreign'); - }); + // This may fail if the foreign key doesn't exist + try { + Schema::table('account_gateway_tokens', function ($table) { + $table->dropForeign('account_gateway_tokens_default_payment_method_id_foreign'); + }); + } catch (Exception $e) { + // do nothing + } Schema::table('account_gateway_tokens', function ($table) { $table->foreign('default_payment_method_id')->references('id')->on('payment_methods')->onDelete('cascade'); }); - Schema::table('invoices', function ($table) { - $table->boolean('is_public')->default(false); - }); + if (! Schema::hasColumn('invoices', 'is_public')) { + Schema::table('invoices', function ($table) { + $table->boolean('is_public')->default(false); + }); + } + DB::table('invoices')->update(['is_public' => true]); } diff --git a/database/migrations/2017_01_01_214241_add_inclusive_taxes.php b/database/migrations/2017_01_01_214241_add_inclusive_taxes.php index accdbef9aa..d4a49e0e27 100644 --- a/database/migrations/2017_01_01_214241_add_inclusive_taxes.php +++ b/database/migrations/2017_01_01_214241_add_inclusive_taxes.php @@ -11,9 +11,11 @@ class AddInclusiveTaxes extends Migration */ public function up() { - Schema::table('tax_rates', function ($table) { - $table->boolean('is_inclusive')->default(false); - }); + if (! Schema::hasColumn('tax_rates', 'is_inclusive')) { + Schema::table('tax_rates', function ($table) { + $table->boolean('is_inclusive')->default(false); + }); + } Schema::table('companies', function ($table) { $table->enum('bluevine_status', ['ignored', 'signed_up'])->nullable(); diff --git a/database/migrations/2017_03_16_085702_add_gateway_fee_location.php b/database/migrations/2017_03_16_085702_add_gateway_fee_location.php index c1f114763d..07fad1e239 100644 --- a/database/migrations/2017_03_16_085702_add_gateway_fee_location.php +++ b/database/migrations/2017_03_16_085702_add_gateway_fee_location.php @@ -111,8 +111,14 @@ class AddGatewayFeeLocation extends Migration } }); + + if (! Schema::hasColumn('accounts', 'gateway_fee_enabled')) { + Schema::table('accounts', function ($table) { + $table->boolean('gateway_fee_enabled')->default(0); + }); + } + Schema::table('accounts', function ($table) { - $table->boolean('gateway_fee_enabled')->default(0); $table->date('reset_counter_date')->nullable(); });