Catch DB errors

This commit is contained in:
James Cole
2023-04-07 19:33:19 +02:00
parent dd11f98be7
commit 79a4eec96e
26 changed files with 985 additions and 656 deletions

View File

@@ -22,7 +22,6 @@
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/** /**
* Class ChangesFor3101. * Class ChangesFor3101.
@@ -36,14 +35,6 @@ class ChangesFor3101 extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table(
'import_jobs',
static function (Blueprint $table) {
if (Schema::hasColumn('import_jobs', 'extended_status')) {
$table->dropColumn('extended_status');
}
}
);
} }
/** /**
@@ -53,13 +44,5 @@ class ChangesFor3101 extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table(
'import_jobs',
static function (Blueprint $table) {
if (!Schema::hasColumn('import_jobs', 'extended_status')) {
$table->text('extended_status')->nullable();
}
}
);
} }
} }

View File

@@ -22,6 +22,7 @@
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
/** /**
@@ -45,18 +46,28 @@ class FixNullables extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'rule_groups', Schema::table(
static function (Blueprint $table) { 'rule_groups',
$table->text('description')->nullable()->change(); static function (Blueprint $table) {
} $table->text('description')->nullable()->change();
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not update table: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
Schema::table( try {
'rules', Schema::table(
static function (Blueprint $table) { 'rules',
$table->text('description')->nullable()->change(); static function (Blueprint $table) {
} $table->text('description')->nullable()->change();
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -21,7 +21,9 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
/** /**
@@ -36,12 +38,17 @@ class ExpandTransactionsTable extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'transactions', Schema::table(
static function (Blueprint $table) { 'transactions',
$table->dropColumn('identifier'); static function (Blueprint $table) {
} $table->dropColumn('identifier');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not drop column "extended_status": %s', $e->getMessage()));
Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -51,11 +58,16 @@ class ExpandTransactionsTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'transactions', Schema::table(
static function (Blueprint $table) { 'transactions',
$table->smallInteger('identifier', false, true)->default(0); static function (Blueprint $table) {
} $table->smallInteger('identifier', false, true)->default(0);
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -22,6 +22,7 @@
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
/** /**
@@ -36,12 +37,17 @@ class ChangesForV420 extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'journal_meta', Schema::table(
static function (Blueprint $table) { 'journal_meta',
$table->dropSoftDeletes(); static function (Blueprint $table) {
} $table->dropSoftDeletes();
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -51,11 +57,16 @@ class ChangesForV420 extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'journal_meta', Schema::table(
static function (Blueprint $table) { 'journal_meta',
$table->softDeletes(); static function (Blueprint $table) {
} $table->softDeletes();
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -21,7 +21,9 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
/** /**
@@ -37,41 +39,66 @@ class ChangesForV431 extends Migration
public function down(): void public function down(): void
{ {
// reinstate "repeats" and "repeat_freq". // reinstate "repeats" and "repeat_freq".
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
$table->string('repeat_freq', 30)->nullable(); static function (Blueprint $table) {
} $table->string('repeat_freq', 30)->nullable();
); }
Schema::table( );
'budget_limits', } catch (QueryException $e) {
static function (Blueprint $table) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
$table->boolean('repeats')->default(0); Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
} }
); try {
Schema::table(
'budget_limits',
static function (Blueprint $table) {
$table->boolean('repeats')->default(0);
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
// change field "start_date" to "startdate" // change field "start_date" to "startdate"
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
$table->renameColumn('start_date', 'startdate'); static function (Blueprint $table) {
} $table->renameColumn('start_date', 'startdate');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
// remove date field "end_date" // remove date field "end_date"
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
$table->dropColumn('end_date'); static function (Blueprint $table) {
} $table->dropColumn('end_date');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
// remove decimal places // remove decimal places
Schema::table( try {
'transaction_currencies', Schema::table(
static function (Blueprint $table) { 'transaction_currencies',
$table->dropColumn('decimal_places'); static function (Blueprint $table) {
} $table->dropColumn('decimal_places');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -83,41 +110,66 @@ class ChangesForV431 extends Migration
public function up(): void public function up(): void
{ {
// add decimal places to "transaction currencies". // add decimal places to "transaction currencies".
Schema::table( try {
'transaction_currencies', Schema::table(
static function (Blueprint $table) { 'transaction_currencies',
$table->smallInteger('decimal_places', false, true)->default(2); static function (Blueprint $table) {
} $table->smallInteger('decimal_places', false, true)->default(2);
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
// change field "startdate" to "start_date" // change field "startdate" to "start_date"
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
$table->renameColumn('startdate', 'start_date'); static function (Blueprint $table) {
} $table->renameColumn('startdate', 'start_date');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
// add date field "end_date" after "start_date" // add date field "end_date" after "start_date"
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
$table->date('end_date')->nullable()->after('start_date'); static function (Blueprint $table) {
} $table->date('end_date')->nullable()->after('start_date');
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
// drop "repeats" and "repeat_freq". // drop "repeats" and "repeat_freq".
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
$table->dropColumn('repeats'); static function (Blueprint $table) {
} $table->dropColumn('repeats');
); }
Schema::table( );
'budget_limits', } catch (QueryException|ColumnDoesNotExist $e) {
static function (Blueprint $table) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
$table->dropColumn('repeat_freq'); Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
} }
); try {
Schema::table(
'budget_limits',
static function (Blueprint $table) {
$table->dropColumn('repeat_freq');
}
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -21,6 +21,7 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
@@ -37,22 +38,24 @@ class ChangesForV440 extends Migration
*/ */
public function down(): void public function down(): void
{ {
if (Schema::hasTable('currency_exchange_rates')) { Schema::dropIfExists('currency_exchange_rates');
Schema::dropIfExists('currency_exchange_rates'); try {
} Schema::table(
'transactions',
Schema::table( static function (Blueprint $table) {
'transactions', if (Schema::hasColumn('transactions', 'transaction_currency_id')) {
static function (Blueprint $table) { // cannot drop foreign keys in SQLite:
if (Schema::hasColumn('transactions', 'transaction_currency_id')) { if ('sqlite' !== config('database.default')) {
// cannot drop foreign keys in SQLite: $table->dropForeign('transactions_transaction_currency_id_foreign');
if ('sqlite' !== config('database.default')) { }
$table->dropForeign('transactions_transaction_currency_id_foreign'); $table->dropColumn('transaction_currency_id');
} }
$table->dropColumn('transaction_currency_id');
} }
} );
); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -88,14 +91,19 @@ class ChangesForV440 extends Migration
} }
} }
Schema::table( try {
'transactions', Schema::table(
static function (Blueprint $table) { 'transactions',
if (!Schema::hasColumn('transactions', 'transaction_currency_id')) { static function (Blueprint $table) {
$table->integer('transaction_currency_id', false, true)->after('description')->nullable(); if (!Schema::hasColumn('transactions', 'transaction_currency_id')) {
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); $table->integer('transaction_currency_id', false, true)->after('description')->nullable();
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null');
}
} }
} );
); } catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -21,7 +21,9 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
/** /**
@@ -37,29 +39,44 @@ class ChangesForV450 extends Migration
public function down(): void public function down(): void
{ {
// split up for sqlite compatibility // split up for sqlite compatibility
Schema::table( try {
'transactions', Schema::table(
static function (Blueprint $table) { 'transactions',
$table->dropColumn('foreign_amount'); static function (Blueprint $table) {
} $table->dropColumn('foreign_amount');
);
Schema::table(
'transactions',
static function (Blueprint $table) {
// cannot drop foreign keys in SQLite:
if ('sqlite' !== config('database.default')) {
$table->dropForeign('transactions_foreign_currency_id_foreign');
} }
} );
); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
Schema::table( try {
'transactions', Schema::table(
static function (Blueprint $table) { 'transactions',
$table->dropColumn('foreign_currency_id'); static function (Blueprint $table) {
} // cannot drop foreign keys in SQLite:
); if ('sqlite' !== config('database.default')) {
$table->dropForeign('transactions_foreign_currency_id_foreign');
}
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
try {
Schema::table(
'transactions',
static function (Blueprint $table) {
$table->dropColumn('foreign_currency_id');
}
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -70,20 +87,30 @@ class ChangesForV450 extends Migration
public function up(): void public function up(): void
{ {
// add "foreign_amount" to transactions // add "foreign_amount" to transactions
Schema::table( try {
'transactions', Schema::table(
static function (Blueprint $table) { 'transactions',
$table->decimal('foreign_amount', 32, 12)->nullable()->after('amount'); static function (Blueprint $table) {
} $table->decimal('foreign_amount', 32, 12)->nullable()->after('amount');
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
// add foreign transaction currency id to transactions (is nullable): // add foreign transaction currency id to transactions (is nullable):
Schema::table( try {
'transactions', Schema::table(
static function (Blueprint $table) { 'transactions',
$table->integer('foreign_currency_id', false, true)->default(null)->after('foreign_amount')->nullable(); static function (Blueprint $table) {
$table->foreign('foreign_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); $table->integer('foreign_currency_id', false, true)->default(null)->after('foreign_amount')->nullable();
} $table->foreign('foreign_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null');
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -21,7 +21,9 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@@ -37,12 +39,17 @@ class ChangesForV470a extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'transactions', Schema::table(
static function (Blueprint $table) { 'transactions',
$table->dropColumn('reconciled'); static function (Blueprint $table) {
} $table->dropColumn('reconciled');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -52,11 +59,16 @@ class ChangesForV470a extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'transactions', Schema::table(
static function (Blueprint $table) { 'transactions',
$table->boolean('reconciled')->after('deleted_at')->default(0); static function (Blueprint $table) {
} $table->boolean('reconciled')->after('deleted_at')->default(0);
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -22,7 +22,9 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
/** /**
@@ -39,18 +41,29 @@ class ChangesForV472 extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'attachments', Schema::table(
static function (Blueprint $table) { 'attachments',
$table->text('notes')->nullable(); static function (Blueprint $table) {
} $table->text('notes')->nullable();
); }
Schema::table( );
'budgets', } catch (QueryException $e) {
static function (Blueprint $table) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
$table->dropColumn('order'); Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
} }
);
try {
Schema::table(
'budgets',
static function (Blueprint $table) {
$table->dropColumn('order');
}
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -61,18 +74,28 @@ class ChangesForV472 extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'attachments', Schema::table(
static function (Blueprint $table) { 'attachments',
$table->dropColumn('notes'); static function (Blueprint $table) {
} $table->dropColumn('notes');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
Schema::table( try {
'budgets', Schema::table(
static function (Blueprint $table) { 'budgets',
$table->mediumInteger('order', false, true)->default(0); static function (Blueprint $table) {
} $table->mediumInteger('order', false, true)->default(0);
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -22,7 +22,9 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@@ -40,23 +42,34 @@ class ChangesForV473 extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'bills', Schema::table(
static function (Blueprint $table) { 'bills',
// cannot drop foreign keys in SQLite: static function (Blueprint $table) {
if ('sqlite' !== config('database.default')) { // cannot drop foreign keys in SQLite:
$table->dropForeign('bills_transaction_currency_id_foreign'); if ('sqlite' !== config('database.default')) {
$table->dropForeign('bills_transaction_currency_id_foreign');
}
$table->dropColumn('transaction_currency_id');
} }
$table->dropColumn('transaction_currency_id'); );
} } catch (QueryException|ColumnDoesNotExist $e) {
); Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
Schema::table(
'rules', try {
static function (Blueprint $table) { Schema::table(
$table->dropColumn('strict'); 'rules',
} static function (Blueprint $table) {
); $table->dropColumn('strict');
}
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -67,18 +80,28 @@ class ChangesForV473 extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'bills', Schema::table(
static function (Blueprint $table) { 'bills',
$table->integer('transaction_currency_id', false, true)->nullable()->after('user_id'); static function (Blueprint $table) {
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); $table->integer('transaction_currency_id', false, true)->nullable()->after('user_id');
} $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null');
); }
Schema::table( );
'rules', } catch (QueryException $e) {
static function (Blueprint $table) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
$table->boolean('strict')->default(true); Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
} }
); try {
Schema::table(
'rules',
static function (Blueprint $table) {
$table->boolean('strict')->default(true);
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -23,7 +23,6 @@
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/** /**
* Class ChangesForV474. * Class ChangesForV474.
@@ -34,57 +33,11 @@ class ChangesForV474 extends Migration
{ {
/** /**
* Reverse the migrations. * Reverse the migrations.
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* *
* @return void * @return void
*/ */
public function down(): void public function down(): void
{ {
// split up for sqlite compatibility.
Schema::table(
'import_jobs',
static function (Blueprint $table) {
// cannot drop foreign keys in SQLite:
if ('sqlite' !== config('database.default')) {
$table->dropForeign('import_jobs_tag_id_foreign');
}
}
);
Schema::table(
'import_jobs',
static function (Blueprint $table) {
$table->dropColumn('provider');
}
);
Schema::table(
'import_jobs',
static function (Blueprint $table) {
$table->dropColumn('stage');
}
);
Schema::table(
'import_jobs',
static function (Blueprint $table) {
$table->dropColumn('transactions');
}
);
Schema::table(
'import_jobs',
static function (Blueprint $table) {
$table->dropColumn('errors');
}
);
Schema::table(
'import_jobs',
static function (Blueprint $table) {
$table->dropColumn('tag_id');
}
);
} }
/** /**
@@ -95,17 +48,5 @@ class ChangesForV474 extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table(
'import_jobs',
static function (Blueprint $table) {
$table->string('provider', 50)->after('file_type')->default('');
$table->string('stage', 50)->after('status')->default('');
$table->longText('transactions')->after('extended_status')->nullable();
$table->longText('errors')->after('transactions')->nullable();
$table->integer('tag_id', false, true)->nullable()->after('user_id');
$table->foreign('tag_id')->references('id')->on('tags')->onDelete('set null');
}
);
} }
} }

View File

@@ -85,93 +85,93 @@ class ChangesForV475 extends Migration
Log::error(sprintf('Could not create table "recurrences": %s', $e->getMessage())); Log::error(sprintf('Could not create table "recurrences": %s', $e->getMessage()));
Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.'); Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.');
} }
try { try {
Schema::create( Schema::create(
'recurrences_transactions', 'recurrences_transactions',
static function (Blueprint $table) { static function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();
$table->integer('recurrence_id', false, true); $table->integer('recurrence_id', false, true);
$table->integer('transaction_currency_id', false, true); $table->integer('transaction_currency_id', false, true);
$table->integer('foreign_currency_id', false, true)->nullable(); $table->integer('foreign_currency_id', false, true)->nullable();
$table->integer('source_id', false, true); $table->integer('source_id', false, true);
$table->integer('destination_id', false, true); $table->integer('destination_id', false, true);
$table->decimal('amount', 32, 12); $table->decimal('amount', 32, 12);
$table->decimal('foreign_amount', 32, 12)->nullable(); $table->decimal('foreign_amount', 32, 12)->nullable();
$table->string('description', 1024); $table->string('description', 1024);
$table->foreign('recurrence_id')->references('id')->on('recurrences')->onDelete('cascade'); $table->foreign('recurrence_id')->references('id')->on('recurrences')->onDelete('cascade');
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade'); $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade');
$table->foreign('foreign_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); $table->foreign('foreign_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null');
$table->foreign('source_id')->references('id')->on('accounts')->onDelete('cascade'); $table->foreign('source_id')->references('id')->on('accounts')->onDelete('cascade');
$table->foreign('destination_id')->references('id')->on('accounts')->onDelete('cascade'); $table->foreign('destination_id')->references('id')->on('accounts')->onDelete('cascade');
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not create table "recurrences_transactions": %s', $e->getMessage()));
Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.');
} }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not create table "recurrences_transactions": %s', $e->getMessage()));
Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.');
}
try { try {
Schema::create( Schema::create(
'recurrences_repetitions', 'recurrences_repetitions',
static function (Blueprint $table) { static function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();
$table->integer('recurrence_id', false, true); $table->integer('recurrence_id', false, true);
$table->string('repetition_type', 50); $table->string('repetition_type', 50);
$table->string('repetition_moment', 50); $table->string('repetition_moment', 50);
$table->smallInteger('repetition_skip', false, true); $table->smallInteger('repetition_skip', false, true);
$table->smallInteger('weekend', false, true); $table->smallInteger('weekend', false, true);
$table->foreign('recurrence_id')->references('id')->on('recurrences')->onDelete('cascade'); $table->foreign('recurrence_id')->references('id')->on('recurrences')->onDelete('cascade');
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not create table "recurrences_repetitions": %s', $e->getMessage()));
Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.');
} }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not create table "recurrences_repetitions": %s', $e->getMessage()));
Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.');
}
try { try {
Schema::create( Schema::create(
'recurrences_meta', 'recurrences_meta',
static function (Blueprint $table) { static function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();
$table->integer('recurrence_id', false, true); $table->integer('recurrence_id', false, true);
$table->string('name', 50); $table->string('name', 50);
$table->text('value'); $table->text('value');
$table->foreign('recurrence_id')->references('id')->on('recurrences')->onDelete('cascade'); $table->foreign('recurrence_id')->references('id')->on('recurrences')->onDelete('cascade');
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not create table "recurrences_meta": %s', $e->getMessage()));
Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.');
} }
); try {
} catch (QueryException $e) { Schema::create(
Log::error(sprintf('Could not create table "recurrences_meta": %s', $e->getMessage())); 'rt_meta',
Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.'); static function (Blueprint $table) {
} $table->increments('id');
try { $table->timestamps();
Schema::create( $table->softDeletes();
'rt_meta', $table->integer('rt_id', false, true);
static function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->softDeletes();
$table->integer('rt_id', false, true);
$table->string('name', 50); $table->string('name', 50);
$table->text('value'); $table->text('value');
$table->foreign('rt_id')->references('id')->on('recurrences_transactions')->onDelete('cascade'); $table->foreign('rt_id')->references('id')->on('recurrences_transactions')->onDelete('cascade');
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not create table "rt_meta": %s', $e->getMessage()));
Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.');
} }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not create table "rt_meta": %s', $e->getMessage()));
Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.');
}
} }
} }

View File

@@ -22,7 +22,9 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
/** /**
@@ -39,17 +41,22 @@ class ChangesForV477 extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
// cannot drop foreign keys in SQLite: static function (Blueprint $table) {
if ('sqlite' !== config('database.default')) { // cannot drop foreign keys in SQLite:
$table->dropForeign('budget_limits_transaction_currency_id_foreign'); if ('sqlite' !== config('database.default')) {
} $table->dropForeign('budget_limits_transaction_currency_id_foreign');
}
$table->dropColumn(['transaction_currency_id']); $table->dropColumn(['transaction_currency_id']);
} }
); );
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -60,12 +67,17 @@ class ChangesForV477 extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
$table->integer('transaction_currency_id', false, true)->nullable()->after('budget_id'); static function (Blueprint $table) {
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); $table->integer('transaction_currency_id', false, true)->nullable()->after('budget_id');
} $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null');
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -22,7 +22,9 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
/** /**
@@ -39,12 +41,17 @@ class ChangesForV479 extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'transaction_currencies', Schema::table(
static function (Blueprint $table) { 'transaction_currencies',
$table->dropColumn(['enabled']); static function (Blueprint $table) {
} $table->dropColumn(['enabled']);
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -55,11 +62,16 @@ class ChangesForV479 extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'transaction_currencies', Schema::table(
static function (Blueprint $table) { 'transaction_currencies',
$table->boolean('enabled')->default(0)->after('deleted_at'); static function (Blueprint $table) {
} $table->boolean('enabled')->default(0)->after('deleted_at');
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -23,6 +23,7 @@
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@@ -59,18 +60,28 @@ class ChangesForV4711 extends Migration
* datetime (without a time zone) for all database engines because MySQL refuses to play * datetime (without a time zone) for all database engines because MySQL refuses to play
* nice. * nice.
*/ */
Schema::table( try {
'transaction_journals', Schema::table(
static function (Blueprint $table) { 'transaction_journals',
$table->dateTime('date')->change(); static function (Blueprint $table) {
} $table->dateTime('date')->change();
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
Schema::table( try {
'preferences', Schema::table(
static function (Blueprint $table) { 'preferences',
$table->text('data')->nullable()->change(); static function (Blueprint $table) {
} $table->text('data')->nullable()->change();
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -22,6 +22,7 @@
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@@ -58,11 +59,16 @@ class ChangesForV4712 extends Migration
* datetime (without a time zone) for all database engines because MySQL refuses to play * datetime (without a time zone) for all database engines because MySQL refuses to play
* nice. * nice.
*/ */
Schema::table( try {
'transaction_journals', Schema::table(
static function (Blueprint $table) { 'transaction_journals',
$table->dateTime('date')->change(); static function (Blueprint $table) {
} $table->dateTime('date')->change();
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -21,7 +21,9 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@@ -39,12 +41,17 @@ class FixLdapConfiguration extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'users', Schema::table(
static function (Blueprint $table) { 'users',
$table->dropColumn(['objectguid']); static function (Blueprint $table) {
} $table->dropColumn(['objectguid']);
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -59,11 +66,16 @@ class FixLdapConfiguration extends Migration
* ADLdap2 appears to require the ability to store an objectguid for LDAP users * ADLdap2 appears to require the ability to store an objectguid for LDAP users
* now. To support this, we add the column. * now. To support this, we add the column.
*/ */
Schema::table( try {
'users', Schema::table(
static function (Blueprint $table) { 'users',
$table->uuid('objectguid')->nullable()->after('id'); static function (Blueprint $table) {
} $table->uuid('objectguid')->nullable()->after('id');
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -21,7 +21,9 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
/** /**
@@ -38,30 +40,66 @@ class ChangesForV480 extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'transaction_journals', Schema::table(
static function (Blueprint $table) { 'transaction_journals',
// drop transaction_group_id + foreign key. static function (Blueprint $table) {
// cannot drop foreign keys in SQLite: // drop transaction_group_id + foreign key.
if ('sqlite' !== config('database.default')) { // cannot drop foreign keys in SQLite:
$table->dropForeign('transaction_journals_transaction_group_id_foreign'); if ('sqlite' !== config('database.default')) {
try {
$table->dropForeign('transaction_journals_transaction_group_id_foreign');
} catch (QueryException $e) {
Log::error(sprintf('Could not drop foreign ID: %s', $e->getMessage()));
Log::error('If the foreign ID does not exist (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
}
try {
$table->dropColumn('transaction_group_id');
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not drop column: %s', $e->getMessage()));
Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
$table->dropColumn('transaction_group_id'); );
} } catch (QueryException $e) {
); Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Schema::table( Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
'rule_groups', }
static function (Blueprint $table) {
$table->dropColumn('stop_processing');
}
);
Schema::table( try {
'users', Schema::table(
static function (Blueprint $table) { 'rule_groups',
$table->dropColumn('mfa_secret'); static function (Blueprint $table) {
} try {
); $table->dropColumn('stop_processing');
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not drop column: %s', $e->getMessage()));
Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.');
}
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
try {
Schema::table(
'users',
static function (Blueprint $table) {
try {
$table->dropColumn('mfa_secret');
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not drop column: %s', $e->getMessage()));
Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.');
}
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -72,30 +110,52 @@ class ChangesForV480 extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'transaction_journals', Schema::table(
static function (Blueprint $table) { 'transaction_journals',
$table->integer('transaction_currency_id', false, true)->nullable()->change(); static function (Blueprint $table) {
$table->integer('transaction_currency_id', false, true)->nullable()->change();
// add column "group_id" after "transaction_type_id" // add column "group_id" after "transaction_type_id"
$table->integer('transaction_group_id', false, true) $table->integer('transaction_group_id', false, true)
->nullable()->default(null)->after('transaction_type_id'); ->nullable()->default(null)->after('transaction_type_id');
// add foreign key for "transaction_group_id" // add foreign key for "transaction_group_id"
$table->foreign('transaction_group_id')->references('id')->on('transaction_groups')->onDelete('cascade'); try {
} $table->foreign('transaction_group_id')->references('id')->on('transaction_groups')->onDelete('cascade');
); } catch (QueryException $e) {
Schema::table( Log::error(sprintf('Could not create foreign index: %s', $e->getMessage()));
'rule_groups', Log::error(
static function (Blueprint $table) { 'If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.'
$table->boolean('stop_processing')->default(false); );
} }
); }
Schema::table( );
'users', } catch (QueryException $e) {
static function (Blueprint $table) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
$table->string('mfa_secret', 50)->nullable(); Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
} }
); try {
Schema::table(
'rule_groups',
static function (Blueprint $table) {
$table->boolean('stop_processing')->default(false);
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
try {
Schema::table(
'users',
static function (Blueprint $table) {
$table->string('mfa_secret', 50)->nullable();
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -22,7 +22,9 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@@ -40,12 +42,17 @@ class ChangesForV530a extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'bills', Schema::table(
static function (Blueprint $table) { 'bills',
$table->dropColumn('order'); static function (Blueprint $table) {
} $table->dropColumn('order');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -55,11 +62,16 @@ class ChangesForV530a extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'bills', Schema::table(
static function (Blueprint $table) { 'bills',
$table->integer('order', false, true)->default(0); static function (Blueprint $table) {
} $table->integer('order', false, true)->default(0);
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -22,7 +22,9 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@@ -40,27 +42,43 @@ class ChangesForV540 extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'oauth_clients', Schema::table(
static function (Blueprint $table) { 'oauth_clients',
$table->dropColumn('provider'); static function (Blueprint $table) {
} $table->dropColumn('provider');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
Schema::table( try {
'accounts', Schema::table(
static function (Blueprint $table) { 'accounts',
$table->dropColumn('order'); static function (Blueprint $table) {
} $table->dropColumn('order');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
Schema::table( try {
'bills', Schema::table(
static function (Blueprint $table) { 'bills',
$table->dropColumn('end_date'); static function (Blueprint $table) {
$table->dropColumn('extension_date'); $table->dropColumn('end_date');
}
); $table->dropColumn('extension_date');
}
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -70,31 +88,51 @@ class ChangesForV540 extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'accounts', Schema::table(
static function (Blueprint $table) { 'accounts',
$table->integer('order', false, true)->default(0); static function (Blueprint $table) {
} $table->integer('order', false, true)->default(0);
); }
Schema::table( );
'oauth_clients', } catch (QueryException $e) {
static function (Blueprint $table) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
$table->string('provider')->nullable(); Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
} }
); try {
Schema::table( Schema::table(
'bills', 'oauth_clients',
static function (Blueprint $table) { static function (Blueprint $table) {
$table->date('end_date')->nullable()->after('date'); $table->string('provider')->nullable();
$table->date('extension_date')->nullable()->after('end_date'); }
} );
); } catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
try {
Schema::table(
'bills',
static function (Blueprint $table) {
$table->date('end_date')->nullable()->after('date');
$table->date('extension_date')->nullable()->after('end_date');
}
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
// make column nullable: // make column nullable:
Schema::table( try {
'oauth_clients', Schema::table(
function (Blueprint $table) { 'oauth_clients',
$table->string('secret', 100)->nullable()->change(); function (Blueprint $table) {
} $table->string('secret', 100)->nullable()->change();
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -22,6 +22,7 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
@@ -64,25 +65,35 @@ class ChangesForV550 extends Migration
} }
// expand budget / transaction journal table. // expand budget / transaction journal table.
Schema::table( try {
'budget_transaction_journal', Schema::table(
function (Blueprint $table) { 'budget_transaction_journal',
$table->dropForeign('budget_id_foreign'); function (Blueprint $table) {
$table->dropColumn('budget_limit_id'); $table->dropForeign('budget_id_foreign');
} $table->dropColumn('budget_limit_id');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
// drop failed jobs table. // drop failed jobs table.
Schema::dropIfExists('failed_jobs'); Schema::dropIfExists('failed_jobs');
// drop fields from budget limits // drop fields from budget limits
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
$table->dropColumn('period'); static function (Blueprint $table) {
$table->dropColumn('generated'); $table->dropColumn('period');
} $table->dropColumn('generated');
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
Schema::dropIfExists('webhook_attempts'); Schema::dropIfExists('webhook_attempts');
Schema::dropIfExists('webhook_messages'); Schema::dropIfExists('webhook_messages');
Schema::dropIfExists('webhooks'); Schema::dropIfExists('webhooks');
@@ -138,29 +149,39 @@ class ChangesForV550 extends Migration
} }
// update budget / transaction journal table. // update budget / transaction journal table.
Schema::table( try {
'budget_transaction_journal', Schema::table(
function (Blueprint $table) { 'budget_transaction_journal',
if (!Schema::hasColumn('budget_transaction_journal', 'budget_limit_id')) { function (Blueprint $table) {
$table->integer('budget_limit_id', false, true)->nullable()->default(null)->after('budget_id'); if (!Schema::hasColumn('budget_transaction_journal', 'budget_limit_id')) {
$table->foreign('budget_limit_id', 'budget_id_foreign')->references('id')->on('budget_limits')->onDelete('set null'); $table->integer('budget_limit_id', false, true)->nullable()->default(null)->after('budget_id');
$table->foreign('budget_limit_id', 'budget_id_foreign')->references('id')->on('budget_limits')->onDelete('set null');
}
} }
} );
); } catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
// append budget limits table. // append budget limits table.
// i swear I dropped & recreated this field 15 times already. // i swear I dropped & recreated this field 15 times already.
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
if (!Schema::hasColumn('budget_limits', 'period')) { static function (Blueprint $table) {
$table->string('period', 12)->nullable(); if (!Schema::hasColumn('budget_limits', 'period')) {
$table->string('period', 12)->nullable();
}
if (!Schema::hasColumn('budget_limits', 'generated')) {
$table->boolean('generated')->default(false);
}
} }
if (!Schema::hasColumn('budget_limits', 'generated')) { );
$table->boolean('generated')->default(false); } catch (QueryException $e) {
} Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
} Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
); }
// new webhooks table // new webhooks table
if (!Schema::hasTable('webhooks')) { if (!Schema::hasTable('webhooks')) {

View File

@@ -22,7 +22,9 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@@ -38,15 +40,20 @@ class ChangesForV550b2 extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'recurrences_transactions', Schema::table(
function (Blueprint $table) { 'recurrences_transactions',
$table->dropForeign('type_foreign'); function (Blueprint $table) {
if (Schema::hasColumn('recurrences_transactions', 'transaction_type_id')) { $table->dropForeign('type_foreign');
$table->dropColumn('transaction_type_id'); if (Schema::hasColumn('recurrences_transactions', 'transaction_type_id')) {
$table->dropColumn('transaction_type_id');
}
} }
} );
); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -57,14 +64,19 @@ class ChangesForV550b2 extends Migration
public function up(): void public function up(): void
{ {
// expand recurrence transaction table // expand recurrence transaction table
Schema::table( try {
'recurrences_transactions', Schema::table(
function (Blueprint $table) { 'recurrences_transactions',
if (!Schema::hasColumn('recurrences_transactions', 'transaction_type_id')) { function (Blueprint $table) {
$table->integer('transaction_type_id', false, true)->nullable()->after('transaction_currency_id'); if (!Schema::hasColumn('recurrences_transactions', 'transaction_type_id')) {
$table->foreign('transaction_type_id', 'type_foreign')->references('id')->on('transaction_types')->onDelete('set null'); $table->integer('transaction_type_id', false, true)->nullable()->after('transaction_currency_id');
$table->foreign('transaction_type_id', 'type_foreign')->references('id')->on('transaction_types')->onDelete('set null');
}
} }
} );
); } catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -22,7 +22,9 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@@ -33,12 +35,17 @@ class AddLdapColumnsToUsersTable extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'users', Schema::table(
function (Blueprint $table) { 'users',
$table->dropColumn(['domain']); function (Blueprint $table) {
} $table->dropColumn(['domain']);
); }
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -46,11 +53,16 @@ class AddLdapColumnsToUsersTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'users', Schema::table(
function (Blueprint $table) { 'users',
$table->string('domain')->nullable(); function (Blueprint $table) {
} $table->string('domain')->nullable();
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -23,6 +23,7 @@
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@@ -48,12 +49,17 @@ class ExtendCurrencyInfo extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'transaction_currencies', Schema::table(
function (Blueprint $table) { 'transaction_currencies',
$table->string('code', 51)->change(); function (Blueprint $table) {
$table->string('symbol', 51)->change(); $table->string('code', 51)->change();
} $table->string('symbol', 51)->change();
); }
);
} catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }

View File

@@ -22,6 +22,7 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
@@ -59,27 +60,37 @@ class UserGroups extends Migration
// remove columns from tables // remove columns from tables
/** @var string $tableName */ /** @var string $tableName */
foreach ($this->tables as $tableName) { foreach ($this->tables as $tableName) {
try {
Schema::table(
$tableName,
function (Blueprint $table) use ($tableName) {
$table->dropForeign(sprintf('%s_to_ugi', $tableName));
if (Schema::hasColumn($tableName, 'user_group_id')) {
$table->dropColumn('user_group_id');
}
}
);
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
}
try {
Schema::table( Schema::table(
$tableName, 'users',
function (Blueprint $table) use ($tableName) { function (Blueprint $table) {
$table->dropForeign(sprintf('%s_to_ugi', $tableName)); $table->dropForeign('type_user_group_id');
if (Schema::hasColumn($tableName, 'user_group_id')) { if (Schema::hasColumn('users', 'user_group_id')) {
$table->dropColumn('user_group_id'); $table->dropColumn('user_group_id');
} }
} }
); );
} catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
} }
Schema::table(
'users',
function (Blueprint $table) {
$table->dropForeign('type_user_group_id');
if (Schema::hasColumn('users', 'user_group_id')) {
$table->dropColumn('user_group_id');
}
}
);
Schema::dropIfExists('group_memberships'); Schema::dropIfExists('group_memberships');
Schema::dropIfExists('user_roles'); Schema::dropIfExists('user_roles');
Schema::dropIfExists('user_groups'); Schema::dropIfExists('user_groups');
@@ -150,30 +161,40 @@ class UserGroups extends Migration
Log::error(sprintf('Could not create table "group_memberships": %s', $e->getMessage())); Log::error(sprintf('Could not create table "group_memberships": %s', $e->getMessage()));
Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.'); Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.');
} }
Schema::table( try {
'users', Schema::table(
function (Blueprint $table) { 'users',
if (!Schema::hasColumn('users', 'user_group_id')) { function (Blueprint $table) {
$table->bigInteger('user_group_id', false, true)->nullable(); if (!Schema::hasColumn('users', 'user_group_id')) {
$table->foreign('user_group_id', 'type_user_group_id')->references('id')->on('user_groups')->onDelete('set null')->onUpdate('cascade'); $table->bigInteger('user_group_id', false, true)->nullable();
$table->foreign('user_group_id', 'type_user_group_id')->references('id')->on('user_groups')->onDelete('set null')->onUpdate('cascade');
}
} }
} );
); } catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
// ADD columns from tables // ADD columns from tables
/** @var string $tableName */ /** @var string $tableName */
foreach ($this->tables as $tableName) { foreach ($this->tables as $tableName) {
Schema::table( try {
$tableName, Schema::table(
function (Blueprint $table) use ($tableName) { $tableName,
if (!Schema::hasColumn($tableName, 'user_group_id')) { function (Blueprint $table) use ($tableName) {
$table->bigInteger('user_group_id', false, true)->nullable()->after('user_id'); if (!Schema::hasColumn($tableName, 'user_group_id')) {
$table->foreign('user_group_id', sprintf('%s_to_ugi', $tableName))->references('id')->on('user_groups')->onDelete('set null')->onUpdate( $table->bigInteger('user_group_id', false, true)->nullable()->after('user_id');
'cascade' $table->foreign('user_group_id', sprintf('%s_to_ugi', $tableName))->references('id')->on('user_groups')->onDelete(
); 'set null'
)->onUpdate('cascade');
}
} }
} );
); } catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }
} }

View File

@@ -22,6 +22,7 @@
declare(strict_types=1); declare(strict_types=1);
use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
@@ -39,25 +40,20 @@ return new class () extends Migration {
*/ */
public function up(): void public function up(): void
{ {
Schema::table( try {
'currency_exchange_rates', Schema::table(
function (Blueprint $table) { 'currency_exchange_rates',
if (!Schema::hasColumn('currency_exchange_rates', 'user_group_id')) { function (Blueprint $table) {
try { if (!Schema::hasColumn('currency_exchange_rates', 'user_group_id')) {
$table->bigInteger('user_group_id', false, true)->nullable()->after('user_id'); $table->bigInteger('user_group_id', false, true)->nullable()->after('user_id');
} catch (QueryException $e) {
Log::error(sprintf('Could not add column "user_group_id" to table "currency_exchange_rates": %s', $e->getMessage()));
Log::error('If the column exists already (see error), this is not a problem. Otherwise, please create a GitHub discussion.');
}
try {
$table->foreign('user_group_id', 'cer_to_ugi')->references('id')->on('user_groups')->onDelete('set null')->onUpdate('cascade'); $table->foreign('user_group_id', 'cer_to_ugi')->references('id')->on('user_groups')->onDelete('set null')->onUpdate('cascade');
} catch (QueryException $e) {
Log::error(sprintf('Could not add foreign key "cer_to_ugi" to table "currency_exchange_rates": %s', $e->getMessage()));
Log::error('If the foreign key exists already (see error), this is not a problem. Otherwise, please create a GitHub discussion.');
} }
} }
} );
); } catch (QueryException $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
/** /**
@@ -67,24 +63,19 @@ return new class () extends Migration {
*/ */
public function down(): void public function down(): void
{ {
Schema::table( try {
'currency_exchange_rates', Schema::table(
function (Blueprint $table) { 'currency_exchange_rates',
try { function (Blueprint $table) {
$table->dropForeign('cer_to_ugi'); $table->dropForeign('cer_to_ugi');
} catch (QueryException $e) { if (Schema::hasColumn('currency_exchange_rates', 'user_group_id')) {
Log::error(sprintf('Could not drop foreign key "cer_to_ugi" from table "currency_exchange_rates": %s', $e->getMessage()));
Log::error('If the foreign key does not exist (see error message), this is not a problem. Otherwise, please create a GitHub discussion.');
}
if (Schema::hasColumn('currency_exchange_rates', 'user_group_id')) {
try {
$table->dropColumn('user_group_id'); $table->dropColumn('user_group_id');
} catch (QueryException $e) {
Log::error(sprintf('Could not drop column "user_group_id" from table "currency_exchange_rates": %s', $e->getMessage()));
Log::error('If the column does not exist (see error message), this is not a problem. Otherwise, please create a GitHub discussion.');
} }
} }
} );
); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
}; };