1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-19 16:01:34 +02:00

Checks to prevent migration errors

This commit is contained in:
Hillel Coren 2017-11-02 12:05:36 +02:00
parent 9dcc3af5ad
commit 07367c4f3a
4 changed files with 36 additions and 13 deletions

View File

@ -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');
;
});
}
}

View File

@ -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]);
}

View File

@ -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();

View File

@ -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();
});