invoiceninja/database/migrations/2018_03_08_150414_add_slack_notifications.php

121 lines
4.4 KiB
PHP
Raw Permalink Normal View History

2018-03-08 17:51:09 +02:00
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddSlackNotifications extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
2018-03-18 11:09:04 +02:00
Schema::table('activities', function ($table) {
$table->integer('task_id')->unsigned()->change();
$table->integer('client_id')->unsigned()->nullable()->change();
});
DB::statement('UPDATE activities SET client_id = NULL WHERE client_id = 0');
2018-05-03 07:37:26 +03:00
if (! Schema::hasColumn('users', 'slack_webhook_url')) {
Schema::table('users', function ($table) {
$table->string('slack_webhook_url')->nullable();
$table->string('accepted_terms_version')->nullable();
$table->timestamp('accepted_terms_timestamp')->nullable();
$table->string('accepted_terms_ip')->nullable();
});
}
if (! Schema::hasColumn('accounts', 'auto_archive_invoice')) {
Schema::table('accounts', function ($table) {
$table->boolean('auto_archive_invoice')->default(false)->nullable();
$table->boolean('auto_archive_quote')->default(false)->nullable();
$table->boolean('auto_email_invoice')->default(true)->nullable();
$table->boolean('send_item_details')->default(false)->nullable();
});
}
2018-03-13 22:05:57 +02:00
2018-05-03 07:37:26 +03:00
try {
Schema::table('expenses', function ($table) {
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
});
2018-03-14 19:51:49 +02:00
2018-05-03 07:37:26 +03:00
Schema::table('activities', function ($table) {
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
$table->index('payment_id');
});
2018-03-14 19:51:49 +02:00
2018-04-26 22:10:49 +03:00
Schema::table('companies', function ($table) {
$table->dropForeign('companies_payment_id_foreign');
});
2018-03-14 20:41:18 +02:00
2018-04-26 22:10:49 +03:00
Schema::table('companies', function ($table) {
$table->index('payment_id');
});
2018-03-14 20:41:18 +02:00
2018-04-26 22:10:49 +03:00
Schema::table('user_accounts', function ($table) {
$table->dropForeign('user_accounts_user_id1_foreign');
$table->dropForeign('user_accounts_user_id2_foreign');
$table->dropForeign('user_accounts_user_id3_foreign');
$table->dropForeign('user_accounts_user_id4_foreign');
$table->dropForeign('user_accounts_user_id5_foreign');
});
2018-03-14 20:41:18 +02:00
2018-04-26 22:10:49 +03:00
Schema::table('user_accounts', function ($table) {
$table->index('user_id1');
$table->index('user_id2');
$table->index('user_id3');
$table->index('user_id4');
$table->index('user_id5');
});
} catch (Exception $exception) {
// do nothing, change only needed for invoiceninja servers
}
2018-03-20 12:37:57 +02:00
Schema::table('jobs', function (Blueprint $table) {
$table->dropIndex('jobs_queue_reserved_reserved_at_index');
$table->dropColumn('reserved');
$table->index(['queue', 'reserved_at']);
});
Schema::table('failed_jobs', function (Blueprint $table) {
$table->longText('exception')->after('payload');
});
2018-03-08 17:51:09 +02:00
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function ($table) {
$table->dropColumn('slack_webhook_url');
2018-03-12 15:37:05 +02:00
$table->dropColumn('accepted_terms_version');
$table->dropColumn('accepted_terms_timestamp');
$table->dropColumn('accepted_terms_ip');
2018-03-08 17:51:09 +02:00
});
2018-03-13 22:05:57 +02:00
Schema::table('accounts', function ($table) {
$table->dropColumn('auto_archive_invoice');
2018-03-13 23:04:24 +02:00
$table->dropColumn('auto_archive_quote');
2018-03-13 22:05:57 +02:00
$table->dropColumn('auto_email_invoice');
$table->dropColumn('send_item_details');
2018-03-13 22:05:57 +02:00
});
2018-03-20 12:37:57 +02:00
Schema::table('jobs', function (Blueprint $table) {
$table->tinyInteger('reserved')->unsigned();
$table->index(['queue', 'reserved', 'reserved_at']);
$table->dropIndex('jobs_queue_reserved_at_index');
});
Schema::table('failed_jobs', function (Blueprint $table) {
$table->dropColumn('exception');
2018-03-25 13:29:30 +03:00
});
2018-03-08 17:51:09 +02:00
}
}