Merge pull request #7353 from firefly-iii/migration-checks

Catch all possible migration errors
This commit is contained in:
James Cole 2023-04-10 08:29:49 +02:00 committed by GitHub
commit b91e019416
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 1213 additions and 1035 deletions

View File

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace FireflyIII\Console\Commands; namespace FireflyIII\Console\Commands;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@ -9,7 +11,7 @@ use Illuminate\Support\Facades\Log;
class ForceDecimalSize extends Command class ForceDecimalSize extends Command
{ {
use VerifiesAccessToken; use VerifiesAccessToken;
/** /**
* The name and signature of the console command. * The name and signature of the console command.
* *

View File

@ -52,6 +52,7 @@ use Illuminate\Support\Carbon;
* @property-read Collection<int, \FireflyIII\Models\Account> $accounts * @property-read Collection<int, \FireflyIII\Models\Account> $accounts
* @property-read int|null $accounts_count * @property-read int|null $accounts_count
* @property-read Collection<int, \FireflyIII\Models\Account> $accounts * @property-read Collection<int, \FireflyIII\Models\Account> $accounts
* @property-read Collection<int, \FireflyIII\Models\Account> $accounts
* @mixin Eloquent * @mixin Eloquent
*/ */
class UserGroup extends Model class UserGroup extends Model

15
composer.lock generated
View File

@ -4075,16 +4075,16 @@
}, },
{ {
"name": "nyholm/psr7", "name": "nyholm/psr7",
"version": "1.5.1", "version": "1.6.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Nyholm/psr7.git", "url": "https://github.com/Nyholm/psr7.git",
"reference": "f734364e38a876a23be4d906a2a089e1315be18a" "reference": "bf4aebd170fadf5fd808c70b90535de327e81a50"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Nyholm/psr7/zipball/f734364e38a876a23be4d906a2a089e1315be18a", "url": "https://api.github.com/repos/Nyholm/psr7/zipball/bf4aebd170fadf5fd808c70b90535de327e81a50",
"reference": "f734364e38a876a23be4d906a2a089e1315be18a", "reference": "bf4aebd170fadf5fd808c70b90535de327e81a50",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4094,6 +4094,7 @@
"psr/http-message": "^1.0" "psr/http-message": "^1.0"
}, },
"provide": { "provide": {
"php-http/message-factory-implementation": "1.0",
"psr/http-factory-implementation": "1.0", "psr/http-factory-implementation": "1.0",
"psr/http-message-implementation": "1.0" "psr/http-message-implementation": "1.0"
}, },
@ -4106,7 +4107,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.4-dev" "dev-master": "1.6-dev"
} }
}, },
"autoload": { "autoload": {
@ -4136,7 +4137,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/Nyholm/psr7/issues", "issues": "https://github.com/Nyholm/psr7/issues",
"source": "https://github.com/Nyholm/psr7/tree/1.5.1" "source": "https://github.com/Nyholm/psr7/tree/1.6.0"
}, },
"funding": [ "funding": [
{ {
@ -4148,7 +4149,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2022-06-22T07:13:36+00:00" "time": "2023-04-09T08:34:27+00:00"
}, },
{ {
"name": "paragonie/constant_time_encoding", "name": "paragonie/constant_time_encoding",

View File

@ -45,28 +45,32 @@ class FixNullables extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if (!Schema::hasColumn('rule_groups', 'description')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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.');
}
} }
try { if (!Schema::hasColumn('rules', 'description')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -38,16 +38,18 @@ class ExpandTransactionsTable extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if (Schema::hasColumn('transactions', 'identifier')) {
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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.'); Log::error(sprintf('Could not drop column "identifier": %s', $e->getMessage()));
Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }
@ -57,16 +59,18 @@ class ExpandTransactionsTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if (!Schema::hasColumn('transactions', 'identifier')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -46,22 +46,24 @@ class ChangesForV410 extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasTable('notes')) {
Schema::create( try {
'notes', Schema::create(
static function (Blueprint $table) { 'notes',
$table->increments('id'); static function (Blueprint $table) {
$table->timestamps(); $table->increments('id');
$table->softDeletes(); $table->timestamps();
$table->integer('noteable_id', false, true); $table->softDeletes();
$table->string('noteable_type'); $table->integer('noteable_id', false, true);
$table->string('title')->nullable(); $table->string('noteable_type');
$table->text('text')->nullable(); $table->string('title')->nullable();
} $table->text('text')->nullable();
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not create table "notes": %s', $e->getMessage())); } catch (QueryException $e) {
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(sprintf('Could not create table "notes": %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

@ -37,16 +37,18 @@ class ChangesForV420 extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if (Schema::hasColumn('journal_meta', 'deleted_at')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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.');
}
} }
} }
@ -56,16 +58,18 @@ class ChangesForV420 extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if (!Schema::hasColumn('journal_meta', 'deleted_at')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -46,26 +46,28 @@ class ChangesForV430 extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if (!Schema::hasTable('available_budgets')) {
Schema::create( try {
'available_budgets', Schema::create(
static function (Blueprint $table) { 'available_budgets',
$table->increments('id'); static function (Blueprint $table) {
$table->timestamps(); $table->increments('id');
$table->softDeletes(); $table->timestamps();
$table->integer('user_id', false, true); $table->softDeletes();
$table->integer('transaction_currency_id', false, true); $table->integer('user_id', false, true);
$table->decimal('amount', 32, 12); $table->integer('transaction_currency_id', false, true);
$table->date('start_date'); $table->decimal('amount', 32, 12);
$table->date('end_date'); $table->date('start_date');
$table->date('end_date');
$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('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
} }
); );
} catch (QueryException $e) { } catch (QueryException $e) {
Log::error(sprintf('Could not create table "available_budgets": %s', $e->getMessage())); Log::error(sprintf('Could not create table "available_budgets": %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.');
}
} }
} }
} }

View File

@ -39,65 +39,74 @@ class ChangesForV431 extends Migration
public function down(): void public function down(): void
{ {
// reinstate "repeats" and "repeat_freq". // reinstate "repeats" and "repeat_freq".
try { if (!Schema::hasColumn('budget_limits', '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();
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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 { if (!Schema::hasColumn('budget_limits', 'repeats')) {
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
$table->boolean('repeats')->default(0); static function (Blueprint $table) {
} $table->boolean('repeats')->default(0);
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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"
try { if (Schema::hasColumn('budget_limits', 'start_date') && !Schema::hasColumn('budget_limits', '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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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"
try { if (Schema::hasColumn('budget_limits', '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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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
try { if (Schema::hasColumn('transaction_currencies', '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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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.');
}
} }
} }
@ -108,66 +117,76 @@ class ChangesForV431 extends Migration
public function up(): void public function up(): void
{ {
// add decimal places to "transaction currencies". // add decimal places to "transaction currencies".
try { if (!Schema::hasColumn('transaction_currencies', 'decimal_places')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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"
try { if (Schema::hasColumn('budget_limits', 'startdate') && !Schema::hasColumn('budget_limits', '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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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"
try { if (!Schema::hasColumn('budget_limits', 'end_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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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".
try { if (Schema::hasColumn('budget_limits', 'repeats')) {
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
$table->dropColumn('repeats'); static function (Blueprint $table) {
} $table->dropColumn('repeats');
); }
} catch (QueryException|ColumnDoesNotExist $e) { );
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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 { if (Schema::hasColumn('budget_limits', 'repeat_freq')) {
Schema::table( try {
'budget_limits', Schema::table(
static function (Blueprint $table) { 'budget_limits',
$table->dropColumn('repeat_freq'); static function (Blueprint $table) {
} $table->dropColumn('repeat_freq');
); }
} catch (QueryException|ColumnDoesNotExist $e) { );
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -89,20 +89,21 @@ class ChangesForV440 extends Migration
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.');
} }
} }
if(!Schema::hasColumn('transactions', 'transaction_currency_id')) {
try { try {
Schema::table( Schema::table(
'transactions', 'transactions',
static function (Blueprint $table) { static function (Blueprint $table) {
if (!Schema::hasColumn('transactions', 'transaction_currency_id')) { if (!Schema::hasColumn('transactions', 'transaction_currency_id')) {
$table->integer('transaction_currency_id', false, true)->after('description')->nullable(); $table->integer('transaction_currency_id', false, true)->after('description')->nullable();
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null');
}
} }
} );
); } catch (QueryException $e) {
} catch (QueryException $e) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
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.');
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); }
} }
} }
} }

View File

@ -39,16 +39,18 @@ class ChangesForV450 extends Migration
public function down(): void public function down(): void
{ {
// split up for sqlite compatibility // split up for sqlite compatibility
try { if(Schema::hasColumn('transactions', 'foreign_amount')) {
Schema::table( try {
'transactions', Schema::table(
static function (Blueprint $table) { 'transactions',
$table->dropColumn('foreign_amount'); static function (Blueprint $table) {
} $table->dropColumn('foreign_amount');
); }
} catch (QueryException|ColumnDoesNotExist $e) { );
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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 { try {
@ -65,17 +67,18 @@ class ChangesForV450 extends Migration
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); 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.'); Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
} }
if(Schema::hasColumn('transactions', 'foreign_currency_id')) {
try { try {
Schema::table( Schema::table(
'transactions', 'transactions',
static function (Blueprint $table) { static function (Blueprint $table) {
$table->dropColumn('foreign_currency_id'); $table->dropColumn('foreign_currency_id');
} }
); );
} catch (QueryException|ColumnDoesNotExist $e) { } catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); 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.'); Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }
@ -86,30 +89,34 @@ class ChangesForV450 extends Migration
public function up(): void public function up(): void
{ {
// add "foreign_amount" to transactions // add "foreign_amount" to transactions
try { if(!Schema::hasColumn('transactions', 'foreign_amount')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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):
try { if(!Schema::hasColumn('transactions', 'foreign_currency_id')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -39,16 +39,18 @@ class ChangesForV470a extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if (Schema::hasColumn('transactions', 'reconciled')) {
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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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.');
}
} }
} }
@ -58,16 +60,18 @@ class ChangesForV470a extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if (!Schema::hasColumn('transactions', 'reconciled')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -47,21 +47,23 @@ class CreateOauthAuthCodesTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasTable('oauth_auth_codes')) {
Schema::create( try {
'oauth_auth_codes', Schema::create(
static function (Blueprint $table) { 'oauth_auth_codes',
$table->string('id', 100)->primary(); static function (Blueprint $table) {
$table->integer('user_id'); $table->string('id', 100)->primary();
$table->integer('client_id'); $table->integer('user_id');
$table->text('scopes')->nullable(); $table->integer('client_id');
$table->boolean('revoked'); $table->text('scopes')->nullable();
$table->dateTime('expires_at')->nullable(); $table->boolean('revoked');
} $table->dateTime('expires_at')->nullable();
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not create table "oauth_auth_codes": %s', $e->getMessage())); } catch (QueryException $e) {
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(sprintf('Could not create table "oauth_auth_codes": %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

@ -47,23 +47,25 @@ class CreateOauthAccessTokensTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasTable('oauth_access_tokens')) {
Schema::create( try {
'oauth_access_tokens', Schema::create(
static function (Blueprint $table) { 'oauth_access_tokens',
$table->string('id', 100)->primary(); static function (Blueprint $table) {
$table->integer('user_id')->index()->nullable(); $table->string('id', 100)->primary();
$table->integer('client_id'); $table->integer('user_id')->index()->nullable();
$table->string('name')->nullable(); $table->integer('client_id');
$table->text('scopes')->nullable(); $table->string('name')->nullable();
$table->boolean('revoked'); $table->text('scopes')->nullable();
$table->timestamps(); $table->boolean('revoked');
$table->dateTime('expires_at')->nullable(); $table->timestamps();
} $table->dateTime('expires_at')->nullable();
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not create table "oauth_access_tokens": %s', $e->getMessage())); } catch (QueryException $e) {
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(sprintf('Could not create table "oauth_access_tokens": %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

@ -47,19 +47,21 @@ class CreateOauthRefreshTokensTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasTable('oauth_refresh_tokens')) {
Schema::create( try {
'oauth_refresh_tokens', Schema::create(
static function (Blueprint $table) { 'oauth_refresh_tokens',
$table->string('id', 100)->primary(); static function (Blueprint $table) {
$table->string('access_token_id', 100)->index(); $table->string('id', 100)->primary();
$table->boolean('revoked'); $table->string('access_token_id', 100)->index();
$table->dateTime('expires_at')->nullable(); $table->boolean('revoked');
} $table->dateTime('expires_at')->nullable();
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not create table "oauth_refresh_tokens": %s', $e->getMessage())); } catch (QueryException $e) {
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(sprintf('Could not create table "oauth_refresh_tokens": %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

@ -47,24 +47,26 @@ class CreateOauthClientsTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasTable('oauth_clients')) {
Schema::create( try {
'oauth_clients', Schema::create(
static function (Blueprint $table) { 'oauth_clients',
$table->increments('id'); static function (Blueprint $table) {
$table->integer('user_id')->index()->nullable(); $table->increments('id');
$table->string('name'); $table->integer('user_id')->index()->nullable();
$table->string('secret', 100); $table->string('name');
$table->text('redirect'); $table->string('secret', 100);
$table->boolean('personal_access_client'); $table->text('redirect');
$table->boolean('password_client'); $table->boolean('personal_access_client');
$table->boolean('revoked'); $table->boolean('password_client');
$table->timestamps(); $table->boolean('revoked');
} $table->timestamps();
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not create table "oauth_clients": %s', $e->getMessage())); } catch (QueryException $e) {
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(sprintf('Could not create table "oauth_clients": %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

@ -47,18 +47,20 @@ class CreateOauthPersonalAccessClientsTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasTable('oauth_personal_access_clients')) {
Schema::create( try {
'oauth_personal_access_clients', Schema::create(
static function (Blueprint $table) { 'oauth_personal_access_clients',
$table->increments('id'); static function (Blueprint $table) {
$table->integer('client_id')->index(); $table->increments('id');
$table->timestamps(); $table->integer('client_id')->index();
} $table->timestamps();
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not create table "oauth_personal_access_clients": %s', $e->getMessage())); } catch (QueryException $e) {
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(sprintf('Could not create table "oauth_personal_access_clients": %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

@ -41,28 +41,32 @@ class ChangesForV472 extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if(!Schema::hasColumn('attachments', 'notes')) {
Schema::table( try {
'attachments', Schema::table(
static function (Blueprint $table) { 'attachments',
$table->text('notes')->nullable(); static function (Blueprint $table) {
} $table->text('notes')->nullable();
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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 { if(Schema::hasColumn('transactions', 'order')) {
Schema::table( try {
'budgets', Schema::table(
static function (Blueprint $table) { 'budgets',
$table->dropColumn('order'); static function (Blueprint $table) {
} $table->dropColumn('order');
); }
} catch (QueryException|ColumnDoesNotExist $e) { );
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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.');
}
} }
} }
@ -73,28 +77,32 @@ class ChangesForV472 extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(Schema::hasColumn('attachments', 'notes')) {
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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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 { if(!Schema::hasColumn('budgets', 'order')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -42,33 +42,36 @@ class ChangesForV473 extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if(!Schema::hasColumn('bills', 'transaction_currency_id')) {
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()));
} catch (QueryException|ColumnDoesNotExist $e) { Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
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.');
} }
if(!Schema::hasColumn('rules', 'strict')) {
try { try {
Schema::table( Schema::table(
'rules', 'rules',
static function (Blueprint $table) { static function (Blueprint $table) {
$table->dropColumn('strict'); $table->dropColumn('strict');
} }
); );
} catch (QueryException|ColumnDoesNotExist $e) { } catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); 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.'); Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }
@ -79,28 +82,32 @@ class ChangesForV473 extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasColumn('bills', 'transaction_currency_id')) {
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');
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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 { if(!Schema::hasColumn('rules', 'strict')) {
Schema::table( try {
'rules', Schema::table(
static function (Blueprint $table) { 'rules',
$table->boolean('strict')->default(true); static function (Blueprint $table) {
} $table->boolean('strict')->default(true);
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -54,122 +54,133 @@ class ChangesForV475 extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if (!Schema::hasTable('recurrences')) {
Schema::create( try {
'recurrences', Schema::create(
static function (Blueprint $table) { 'recurrences',
$table->increments('id'); static function (Blueprint $table) {
$table->timestamps(); $table->increments('id');
$table->softDeletes(); $table->timestamps();
$table->integer('user_id', false, true); $table->softDeletes();
$table->integer('transaction_type_id', false, true); $table->integer('user_id', false, true);
$table->integer('transaction_type_id', false, true);
$table->string('title', 1024); $table->string('title', 1024);
$table->text('description'); $table->text('description');
$table->date('first_date'); $table->date('first_date');
$table->date('repeat_until')->nullable(); $table->date('repeat_until')->nullable();
$table->date('latest_date')->nullable(); $table->date('latest_date')->nullable();
$table->smallInteger('repetitions', false, true); $table->smallInteger('repetitions', false, true);
$table->boolean('apply_rules')->default(true); $table->boolean('apply_rules')->default(true);
$table->boolean('active')->default(true); $table->boolean('active')->default(true);
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('transaction_type_id')->references('id')->on('transaction_types')->onDelete('cascade'); $table->foreign('transaction_type_id')->references('id')->on('transaction_types')->onDelete('cascade');
} }
); );
} catch (QueryException $e) { } catch (QueryException $e) {
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 { if (!Schema::hasTable('recurrences_transactions')) {
Schema::create( try {
'recurrences_transactions', Schema::create(
static function (Blueprint $table) { 'recurrences_transactions',
$table->increments('id'); static function (Blueprint $table) {
$table->timestamps(); $table->increments('id');
$table->softDeletes(); $table->timestamps();
$table->integer('recurrence_id', false, true); $table->softDeletes();
$table->integer('transaction_currency_id', false, true); $table->integer('recurrence_id', false, true);
$table->integer('foreign_currency_id', false, true)->nullable(); $table->integer('transaction_currency_id', false, true);
$table->integer('source_id', false, true); $table->integer('foreign_currency_id', false, true)->nullable();
$table->integer('destination_id', false, true); $table->integer('source_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) { } catch (QueryException $e) {
Log::error(sprintf('Could not create table "recurrences_transactions": %s', $e->getMessage())); 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.'); 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 { if (!Schema::hasTable('recurrences_repetitions')) {
Schema::create( try {
'recurrences_repetitions', Schema::create(
static function (Blueprint $table) { 'recurrences_repetitions',
$table->increments('id'); static function (Blueprint $table) {
$table->timestamps(); $table->increments('id');
$table->softDeletes(); $table->timestamps();
$table->integer('recurrence_id', false, true); $table->softDeletes();
$table->string('repetition_type', 50); $table->integer('recurrence_id', false, true);
$table->string('repetition_moment', 50); $table->string('repetition_type', 50);
$table->smallInteger('repetition_skip', false, true); $table->string('repetition_moment', 50);
$table->smallInteger('weekend', false, true); $table->smallInteger('repetition_skip', 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) { } catch (QueryException $e) {
Log::error(sprintf('Could not create table "recurrences_repetitions": %s', $e->getMessage())); 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.'); 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 { if (!Schema::hasTable('recurrences_meta')) {
Schema::create( try {
'recurrences_meta', Schema::create(
static function (Blueprint $table) { 'recurrences_meta',
$table->increments('id'); static function (Blueprint $table) {
$table->timestamps(); $table->increments('id');
$table->softDeletes(); $table->timestamps();
$table->integer('recurrence_id', false, true); $table->softDeletes();
$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) { } catch (QueryException $e) {
Log::error(sprintf('Could not create table "recurrences_meta": %s', $e->getMessage())); 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.'); 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 {
Schema::create(
'rt_meta',
static function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->softDeletes();
$table->integer('rt_id', false, true);
$table->string('name', 50); if (!Schema::hasTable('rt_meta')) {
$table->text('value'); try {
Schema::create(
'rt_meta',
static function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->softDeletes();
$table->integer('rt_id', false, true);
$table->foreign('rt_id')->references('id')->on('recurrences_transactions')->onDelete('cascade'); $table->string('name', 50);
} $table->text('value');
);
} catch (QueryException $e) { $table->foreign('rt_id')->references('id')->on('recurrences_transactions')->onDelete('cascade');
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

@ -41,21 +41,23 @@ class ChangesForV477 extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if(Schema::hasColumn('budget_limits', 'transaction_currency_id')) {
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) { } catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); 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.'); Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.');
}
} }
} }
@ -66,17 +68,19 @@ class ChangesForV477 extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasColumn('budget_limits', 'transaction_currency_id')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -41,16 +41,18 @@ class ChangesForV479 extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if(Schema::hasColumn('transaction_currencies', 'enabled')) {
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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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,16 +63,18 @@ class ChangesForV479 extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasColumn('transaction_currencies', 'enabled')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -41,16 +41,18 @@ class FixLdapConfiguration extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if(Schema::hasColumn('users', 'objectguid')) {
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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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.');
}
} }
} }
@ -65,16 +67,18 @@ 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.
*/ */
try { if(!Schema::hasColumn('users', 'objectguid')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -40,65 +40,74 @@ class ChangesForV480 extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { // remove group ID
Schema::table( if(Schema::hasColumn('transaction_journals', 'transaction_group_id')) {
'transaction_journals', try {
static function (Blueprint $table) { Schema::table(
// drop transaction_group_id + foreign key. 'transaction_journals',
// cannot drop foreign keys in SQLite: static function (Blueprint $table) {
if ('sqlite' !== config('database.default')) { // drop transaction_group_id + foreign key.
// cannot drop foreign keys in SQLite:
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 { try {
$table->dropForeign('transaction_journals_transaction_group_id_foreign'); $table->dropColumn('transaction_group_id');
} catch (QueryException $e) { } catch (QueryException|ColumnDoesNotExist $e) {
Log::error(sprintf('Could not drop foreign ID: %s', $e->getMessage())); Log::error(sprintf('Could not drop column: %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.'); Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.');
} }
} }
try { );
$table->dropColumn('transaction_group_id'); } catch (QueryException $e) {
} catch (QueryException|ColumnDoesNotExist $e) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
Log::error(sprintf('Could not drop column: %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.');
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 { // remove 'stop processing' column
Schema::table( if(Schema::hasColumn('rule_groups', 'stop_processing')) {
'rule_groups', try {
static function (Blueprint $table) { Schema::table(
try { 'rule_groups',
$table->dropColumn('stop_processing'); static function (Blueprint $table) {
} catch (QueryException|ColumnDoesNotExist $e) { try {
Log::error(sprintf('Could not drop column: %s', $e->getMessage())); $table->dropColumn('stop_processing');
Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.'); } 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) {
} catch (QueryException $e) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
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.');
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); }
} }
try { // remove 'mfa_secret' column
Schema::table( if(Schema::hasColumn('users', 'mfa_secret')) {
'users', try {
static function (Blueprint $table) { Schema::table(
try { 'users',
$table->dropColumn('mfa_secret'); static function (Blueprint $table) {
} catch (QueryException|ColumnDoesNotExist $e) { try {
Log::error(sprintf('Could not drop column: %s', $e->getMessage())); $table->dropColumn('mfa_secret');
Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.'); } 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) {
} catch (QueryException $e) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
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.');
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); }
} }
} }
@ -109,52 +118,63 @@ class ChangesForV480 extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { // add currency_id
Schema::table( if(!Schema::hasColumn('transaction_journals', 'transaction_group_id')) {
'transaction_journals', try {
static function (Blueprint $table) { Schema::table(
$table->integer('transaction_currency_id', false, true)->nullable()->change(); 'transaction_journals',
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"
try { try {
$table->foreign('transaction_group_id')->references('id')->on('transaction_groups')->onDelete('cascade'); $table->foreign('transaction_group_id')->references('id')->on('transaction_groups')->onDelete('cascade');
} catch (QueryException $e) { } catch (QueryException $e) {
Log::error(sprintf('Could not create foreign index: %s', $e->getMessage())); Log::error(sprintf('Could not create foreign index: %s', $e->getMessage()));
Log::error( Log::error(
'If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.' '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) {
} catch (QueryException $e) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
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.');
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( // add 'stop processing' column
'rule_groups', if(!Schema::hasColumn('rule_groups', 'stop_processing')) {
static function (Blueprint $table) { try {
$table->boolean('stop_processing')->default(false); Schema::table(
} 'rule_groups',
); static function (Blueprint $table) {
} catch (QueryException $e) { $table->boolean('stop_processing')->default(false);
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.'); );
} 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( // add 'mfa_secret' column
'users', if(!Schema::hasColumn('users', 'mfa_secret')) {
static function (Blueprint $table) { try {
$table->string('mfa_secret', 50)->nullable(); Schema::table(
} 'users',
); static function (Blueprint $table) {
} catch (QueryException $e) { $table->string('mfa_secret', 50)->nullable();
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.'); );
} 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

@ -51,25 +51,27 @@ class MakeLocationsTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if (!Schema::hasTable('locations')) {
Schema::create( try {
'locations', Schema::create(
static function (Blueprint $table) { 'locations',
$table->bigIncrements('id'); static function (Blueprint $table) {
$table->timestamps(); $table->bigIncrements('id');
$table->softDeletes(); $table->timestamps();
$table->softDeletes();
$table->integer('locatable_id', false, true); $table->integer('locatable_id', false, true);
$table->string('locatable_type', 255); $table->string('locatable_type', 255);
$table->decimal('latitude', 12, 8)->nullable(); $table->decimal('latitude', 12, 8)->nullable();
$table->decimal('longitude', 12, 8)->nullable(); $table->decimal('longitude', 12, 8)->nullable();
$table->smallInteger('zoom_level', false, true)->nullable(); $table->smallInteger('zoom_level', false, true)->nullable();
} }
); );
} catch (QueryException $e) { } catch (QueryException $e) {
Log::error(sprintf('Could not create table "locations": %s', $e->getMessage())); Log::error(sprintf('Could not create table "locations": %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.');
}
} }
} }
} }

View File

@ -42,16 +42,18 @@ class ChangesForV530a extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if(Schema::hasColumn('bills', 'order')) {
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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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.');
}
} }
} }
@ -62,16 +64,18 @@ class ChangesForV530a extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasColumn('bills', 'order')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -42,42 +42,47 @@ class ChangesForV540 extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if(Schema::hasColumn('oauth_clients', 'provider')) {
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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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 { if(Schema::hasColumn('accounts', 'order')) {
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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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.');
}
} }
if(Schema::hasColumn('bills', 'end_date') && Schema::hasColumn('bills', 'extension_date')) {
try {
Schema::table(
'bills',
static function (Blueprint $table) {
$table->dropColumn('end_date');
try { $table->dropColumn('extension_date');
Schema::table( }
'bills', );
static function (Blueprint $table) { } catch (QueryException|ColumnDoesNotExist $e) {
$table->dropColumn('end_date'); 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.');
$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.');
} }
} }
@ -88,40 +93,49 @@ class ChangesForV540 extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasColumn('accounts', 'order')) {
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);
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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( if(!Schema::hasColumn('oauth_clients', 'provider')) {
'oauth_clients', try {
static function (Blueprint $table) { Schema::table(
$table->string('provider')->nullable(); 'oauth_clients',
} static function (Blueprint $table) {
); $table->string('provider')->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.'); } 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( if(!Schema::hasColumn('bills', 'end_date') && !Schema::hasColumn('bills', 'extension_date')) {
'bills', try {
static function (Blueprint $table) { Schema::table(
$table->date('end_date')->nullable()->after('date'); 'bills',
$table->date('extension_date')->nullable()->after('end_date'); 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.'); } 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:
try { try {
Schema::table( Schema::table(

View File

@ -43,57 +43,65 @@ class ChangesForV550 extends Migration
// recreate jobs table. // recreate jobs table.
Schema::dropIfExists('jobs'); Schema::dropIfExists('jobs');
try { if (!Schema::hasTable('jobs')) {
Schema::create( try {
'jobs', Schema::create(
static function (Blueprint $table) { 'jobs',
// straight from Laravel (this is the OLD table) static function (Blueprint $table) {
$table->bigIncrements('id'); // straight from Laravel (this is the OLD table)
$table->string('queue'); $table->bigIncrements('id');
$table->longText('payload'); $table->string('queue');
$table->tinyInteger('attempts')->unsigned(); $table->longText('payload');
$table->tinyInteger('reserved')->unsigned(); $table->tinyInteger('attempts')->unsigned();
$table->unsignedInteger('reserved_at')->nullable(); $table->tinyInteger('reserved')->unsigned();
$table->unsignedInteger('available_at'); $table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('created_at'); $table->unsignedInteger('available_at');
$table->index(['queue', 'reserved', 'reserved_at']); $table->unsignedInteger('created_at');
} $table->index(['queue', 'reserved', 'reserved_at']);
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not create table "jobs": %s', $e->getMessage())); } catch (QueryException $e) {
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(sprintf('Could not create table "jobs": %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.');
}
} }
// expand budget / transaction journal table. // expand budget / transaction journal table.
try { if(Schema::hasColumn('budget_transaction_journal', 'budget_limit_id')) {
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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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
try { if(Schema::hasColumn('budget_limits', 'period') && Schema::hasColumn('budget_limits', 'generated')) {
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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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 other tables
Schema::dropIfExists('webhook_attempts'); Schema::dropIfExists('webhook_attempts');
Schema::dropIfExists('webhook_messages'); Schema::dropIfExists('webhook_messages');
Schema::dropIfExists('webhooks'); Schema::dropIfExists('webhooks');
@ -109,63 +117,70 @@ class ChangesForV550 extends Migration
// drop and recreate jobs table. // drop and recreate jobs table.
Schema::dropIfExists('jobs'); Schema::dropIfExists('jobs');
// this is the NEW table // this is the NEW table
try { if (!Schema::hasTable('jobs')) {
Schema::create( try {
'jobs', Schema::create(
function (Blueprint $table) { 'jobs',
$table->bigIncrements('id'); function (Blueprint $table) {
$table->string('queue')->index(); $table->bigIncrements('id');
$table->longText('payload'); $table->string('queue')->index();
$table->unsignedTinyInteger('attempts'); $table->longText('payload');
$table->unsignedInteger('reserved_at')->nullable(); $table->unsignedTinyInteger('attempts');
$table->unsignedInteger('available_at'); $table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('created_at'); $table->unsignedInteger('available_at');
} $table->unsignedInteger('created_at');
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not create table "jobs": %s', $e->getMessage())); } catch (QueryException $e) {
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(sprintf('Could not create table "jobs": %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.');
}
} }
// drop failed jobs table. // drop failed jobs table.
Schema::dropIfExists('failed_jobs'); Schema::dropIfExists('failed_jobs');
// create new failed_jobs table. // create new failed_jobs table.
try { if (!Schema::hasTable('failed_jobs')) {
Schema::create( try {
'failed_jobs', Schema::create(
function (Blueprint $table) { 'failed_jobs',
$table->bigIncrements('id'); function (Blueprint $table) {
$table->string('uuid')->unique(); $table->bigIncrements('id');
$table->text('connection'); $table->string('uuid')->unique();
$table->text('queue'); $table->text('connection');
$table->longText('payload'); $table->text('queue');
$table->longText('exception'); $table->longText('payload');
$table->timestamp('failed_at')->useCurrent(); $table->longText('exception');
} $table->timestamp('failed_at')->useCurrent();
); }
} catch (QueryException $e) { );
Log::error(sprintf('Could not create table "failed_jobs": %s', $e->getMessage())); } catch (QueryException $e) {
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(sprintf('Could not create table "failed_jobs": %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.');
}
} }
// update budget / transaction journal table. // update budget / transaction journal table.
try { if(!Schema::hasColumn('budget_transaction_journal', 'budget_limit_id')) {
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) {
} catch (QueryException $e) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
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.');
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.
try { try {
Schema::table( Schema::table(
'budget_limits', 'budget_limits',

View File

@ -40,19 +40,21 @@ class ChangesForV550b2 extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if(Schema::hasColumn('recurrences_transactions', 'transaction_type_id')) {
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) {
} catch (QueryException|ColumnDoesNotExist $e) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
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.');
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); }
} }
} }
@ -64,19 +66,21 @@ class ChangesForV550b2 extends Migration
public function up(): void public function up(): void
{ {
// expand recurrence transaction table // expand recurrence transaction table
try { if(!Schema::hasColumn('recurrences_transactions', 'transaction_type_id')) {
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) {
} catch (QueryException $e) { Log::error(sprintf('Could not execute query: %s', $e->getMessage()));
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.');
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); }
} }
} }
} }

View File

@ -35,16 +35,18 @@ class AddLdapColumnsToUsersTable extends Migration
*/ */
public function down(): void public function down(): void
{ {
try { if(Schema::hasColumn('users', 'domain')) {
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())); } catch (QueryException|ColumnDoesNotExist $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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.');
}
} }
} }
@ -53,16 +55,18 @@ class AddLdapColumnsToUsersTable extends Migration
*/ */
public function up(): void public function up(): void
{ {
try { if(!Schema::hasColumn('users', 'domain')) {
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())); } catch (QueryException $e) {
Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); 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

@ -60,12 +60,31 @@ 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) {
if (Schema::hasColumn($tableName, 'user_group_id')) {
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.');
}
}
}
if (Schema::hasColumn('users', 'user_group_id')) {
try { 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');
} }
} }
@ -76,21 +95,6 @@ class UserGroups extends Migration
} }
} }
try {
Schema::table(
'users',
function (Blueprint $table) {
$table->dropForeign('type_user_group_id');
if (Schema::hasColumn('users', '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::dropIfExists('group_memberships'); Schema::dropIfExists('group_memberships');
Schema::dropIfExists('user_roles'); Schema::dropIfExists('user_roles');
Schema::dropIfExists('user_groups'); Schema::dropIfExists('user_groups');
@ -107,59 +111,64 @@ class UserGroups extends Migration
* user is a member of a user_group through a user_group_role * user is a member of a user_group through a user_group_role
* may have multiple roles in a group * may have multiple roles in a group
*/ */
try { if (!Schema::hasTable('user_groups')) {
Schema::create( try {
'user_groups', Schema::create(
static function (Blueprint $table) { 'user_groups',
$table->bigIncrements('id'); static function (Blueprint $table) {
$table->timestamps(); $table->bigIncrements('id');
$table->softDeletes(); $table->timestamps();
$table->softDeletes();
$table->string('title', 255); $table->string('title', 255);
$table->unique('title'); $table->unique('title');
} }
); );
} catch (QueryException $e) { } catch (QueryException $e) {
Log::error(sprintf('Could not create table "user_groups": %s', $e->getMessage())); Log::error(sprintf('Could not create table "user_groups": %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 { if (!Schema::hasTable('user_roles')) {
Schema::create( try {
'user_roles', Schema::create(
static function (Blueprint $table) { 'user_roles',
$table->bigIncrements('id'); static function (Blueprint $table) {
$table->timestamps(); $table->bigIncrements('id');
$table->softDeletes(); $table->timestamps();
$table->softDeletes();
$table->string('title', 255); $table->string('title', 255);
$table->unique('title'); $table->unique('title');
} }
); );
} catch (QueryException $e) { } catch (QueryException $e) {
Log::error(sprintf('Could not create table "user_roles": %s', $e->getMessage())); Log::error(sprintf('Could not create table "user_roles": %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.');
}
} }
if (!Schema::hasTable('group_memberships')) {
try {
Schema::create(
'group_memberships',
static function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->softDeletes();
$table->integer('user_id', false, true);
$table->bigInteger('user_group_id', false, true);
$table->bigInteger('user_role_id', false, true);
try { $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade');
Schema::create( $table->foreign('user_group_id')->references('id')->on('user_groups')->onUpdate('cascade')->onDelete('cascade');
'group_memberships', $table->foreign('user_role_id')->references('id')->on('user_roles')->onUpdate('cascade')->onDelete('cascade');
static function (Blueprint $table) { $table->unique(['user_id', 'user_group_id', 'user_role_id']);
$table->bigIncrements('id'); }
$table->timestamps(); );
$table->softDeletes(); } catch (QueryException $e) {
$table->integer('user_id', false, true); Log::error(sprintf('Could not create table "group_memberships": %s', $e->getMessage()));
$table->bigInteger('user_group_id', false, true); Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.');
$table->bigInteger('user_role_id', false, true); }
$table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('user_group_id')->references('id')->on('user_groups')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('user_role_id')->references('id')->on('user_roles')->onUpdate('cascade')->onDelete('cascade');
$table->unique(['user_id', 'user_group_id', 'user_role_id']);
}
);
} catch (QueryException $e) {
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.');
} }
try { try {
Schema::table( Schema::table(
@ -167,7 +176,9 @@ class UserGroups extends Migration
function (Blueprint $table) { function (Blueprint $table) {
if (!Schema::hasColumn('users', 'user_group_id')) { if (!Schema::hasColumn('users', 'user_group_id')) {
$table->bigInteger('user_group_id', false, true)->nullable(); $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'); $table->foreign('user_group_id', 'type_user_group_id')->references('id')->on('user_groups')->onDelete('set null')->onUpdate(
'cascade'
);
} }
} }
); );
@ -175,7 +186,6 @@ class UserGroups extends Migration
Log::error(sprintf('Could not execute query: %s', $e->getMessage())); 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.'); 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) {

View File

@ -36,18 +36,20 @@ return new class () extends Migration {
*/ */
public function up(): void public function up(): void
{ {
try { if (!Schema::hasTable('notifications')) {
Schema::create('notifications', function (Blueprint $table) { try {
$table->uuid('id')->primary(); Schema::create('notifications', function (Blueprint $table) {
$table->string('type'); $table->uuid('id')->primary();
$table->morphs('notifiable'); $table->string('type');
$table->text('data'); $table->morphs('notifiable');
$table->timestamp('read_at')->nullable(); $table->text('data');
$table->timestamps(); $table->timestamp('read_at')->nullable();
}); $table->timestamps();
} catch (QueryException $e) { });
Log::error(sprintf('Could not create table "notifications": %s', $e->getMessage())); } catch (QueryException $e) {
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(sprintf('Could not create table "notifications": %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

@ -36,20 +36,22 @@ return new class () extends Migration {
*/ */
public function up(): void public function up(): void
{ {
try { if (!Schema::hasTable('invited_users')) {
Schema::create('invited_users', function (Blueprint $table) { try {
$table->id(); Schema::create('invited_users', function (Blueprint $table) {
$table->timestamps(); $table->id();
$table->integer('user_id', false, true); $table->timestamps();
$table->string('email', 255); $table->integer('user_id', false, true);
$table->string('invite_code', 64); $table->string('email', 255);
$table->dateTime('expires'); $table->string('invite_code', 64);
$table->boolean('redeemed'); $table->dateTime('expires');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->boolean('redeemed');
}); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
} catch (QueryException $e) { });
Log::error(sprintf('Could not create table "invited_users": %s', $e->getMessage())); } catch (QueryException $e) {
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(sprintf('Could not create table "invited_users": %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

@ -36,25 +36,27 @@ return new class () extends Migration {
*/ */
public function up(): void public function up(): void
{ {
try { if (!Schema::hasTable('audit_log_entries')) {
Schema::create('audit_log_entries', function (Blueprint $table) { try {
$table->id(); Schema::create('audit_log_entries', function (Blueprint $table) {
$table->timestamps(); $table->id();
$table->softDeletes(); $table->timestamps();
$table->softDeletes();
$table->integer('auditable_id', false, true); $table->integer('auditable_id', false, true);
$table->string('auditable_type'); $table->string('auditable_type');
$table->integer('changer_id', false, true); $table->integer('changer_id', false, true);
$table->string('changer_type'); $table->string('changer_type');
$table->string('action', 255); $table->string('action', 255);
$table->text('before')->nullable(); $table->text('before')->nullable();
$table->text('after')->nullable(); $table->text('after')->nullable();
}); });
} catch (QueryException $e) { } catch (QueryException $e) {
Log::error(sprintf('Could not create table "audit_log_entries": %s', $e->getMessage())); Log::error(sprintf('Could not create table "audit_log_entries": %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.');
}
} }
} }