diff --git a/.ci/php-cs-fixer/composer.lock b/.ci/php-cs-fixer/composer.lock index 97ff2a4e90..aa241e687b 100644 --- a/.ci/php-cs-fixer/composer.lock +++ b/.ci/php-cs-fixer/composer.lock @@ -379,16 +379,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.15.1", + "version": "v3.16.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "d48755372a113bddb99f749e34805d83f3acfe04" + "reference": "d40f9436e1c448d309fa995ab9c14c5c7a96f2dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/d48755372a113bddb99f749e34805d83f3acfe04", - "reference": "d48755372a113bddb99f749e34805d83f3acfe04", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/d40f9436e1c448d309fa995ab9c14c5c7a96f2dc", + "reference": "d40f9436e1c448d309fa995ab9c14c5c7a96f2dc", "shasum": "" }, "require": { @@ -463,7 +463,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.15.1" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.16.0" }, "funding": [ { @@ -471,7 +471,7 @@ "type": "github" } ], - "time": "2023-03-13T23:26:30+00:00" + "time": "2023-04-02T19:30:06+00:00" }, { "name": "psr/cache", diff --git a/app/Console/Commands/ForceMigration.php b/app/Console/Commands/ForceMigration.php new file mode 100644 index 0000000000..bab96cee5e --- /dev/null +++ b/app/Console/Commands/ForceMigration.php @@ -0,0 +1,72 @@ +verifyAccessToken()) { + $this->error('Invalid access token.'); + + return 1; + } + + $this->error('Running this command is dangerous and can cause data loss.'); + $this->error('Please do not continue.'); + $question = $this->confirm('Do you want to continue?'); + if (true === $question) { + $user = $this->getUser(); + Log::channel('audit')->info(sprintf('User #%d ("%s") forced migrations.', $user->id, $user->email)); + $this->forceMigration(); + return 0; + } + return 0; + } + + private function forceMigration(): void + { + $this->line('Dropping "migrations" table...'); + sleep(2); + Schema::dropIfExists('migrations'); + $this->line('Done!'); + $this->line('Re-run all migrations...'); + Artisan::call('migrate', ['--seed' => true]); + sleep(2); + $this->line(''); + $this->info('Done!'); + $this->line('There is a good chance you just saw a lot of error messages.'); + $this->line('No need to panic yet. First try to access Firefly III (again).'); + $this->line('The issue, whatever it was, may have been solved now.'); + $this->line(''); + } +} diff --git a/app/Helpers/Report/NetWorth.php b/app/Helpers/Report/NetWorth.php index c3a051f081..4379213c56 100644 --- a/app/Helpers/Report/NetWorth.php +++ b/app/Helpers/Report/NetWorth.php @@ -78,7 +78,7 @@ class NetWorth implements NetWorthInterface $netWorth = []; $result = []; -// Log::debug(sprintf('Now in getNetWorthByCurrency(%s)', $date->format('Y-m-d'))); + // Log::debug(sprintf('Now in getNetWorthByCurrency(%s)', $date->format('Y-m-d'))); // get default currency $default = app('amount')->getDefaultCurrencyByUser($this->user); @@ -89,11 +89,11 @@ class NetWorth implements NetWorthInterface // get the preferred currency for this account /** @var Account $account */ foreach ($accounts as $account) { -// Log::debug(sprintf('Now at account #%d: "%s"', $account->id, $account->name)); + // Log::debug(sprintf('Now at account #%d: "%s"', $account->id, $account->name)); $currencyId = (int)$this->accountRepository->getMetaValue($account, 'currency_id'); $currencyId = 0 === $currencyId ? $default->id : $currencyId; -// Log::debug(sprintf('Currency ID is #%d', $currencyId)); + // Log::debug(sprintf('Currency ID is #%d', $currencyId)); // balance in array: $balance = $balances[$account->id] ?? '0'; @@ -106,13 +106,13 @@ class NetWorth implements NetWorthInterface $balance = bcsub($balance, $virtualBalance); } -// Log::debug(sprintf('Balance corrected to %s because of virtual balance (%s)', $balance, $virtualBalance)); + // Log::debug(sprintf('Balance corrected to %s because of virtual balance (%s)', $balance, $virtualBalance)); if (!array_key_exists($currencyId, $netWorth)) { $netWorth[$currencyId] = '0'; } $netWorth[$currencyId] = bcadd($balance, $netWorth[$currencyId]); -// Log::debug(sprintf('Total net worth for currency #%d is %s', $currencyId, $netWorth[$currencyId])); + // Log::debug(sprintf('Total net worth for currency #%d is %s', $currencyId, $netWorth[$currencyId])); } ksort($netWorth); diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php index 7c83ceb91d..929057593e 100644 --- a/app/Support/Search/OperatorQuerySearch.php +++ b/app/Support/Search/OperatorQuerySearch.php @@ -263,9 +263,9 @@ class OperatorQuerySearch implements SearchInterface Log::info(sprintf('Ignore search operator "%s"', $operator)); return false; - // + // // all account related searches: - // + // case 'account_is': $this->searchAccount($value, 3, 4); break; @@ -496,9 +496,9 @@ class OperatorQuerySearch implements SearchInterface $this->collector->findNothing(); } break; - // + // // cash account - // + // case 'source_is_cash': $account = $this->getCashAccount(); $this->collector->setSourceAccounts(new Collection([$account])); @@ -523,9 +523,9 @@ class OperatorQuerySearch implements SearchInterface $account = $this->getCashAccount(); $this->collector->excludeAccounts(new Collection([$account])); break; - // + // // description - // + // case 'description_starts': $this->collector->descriptionStarts([$value]); break; @@ -552,9 +552,9 @@ class OperatorQuerySearch implements SearchInterface case '-description_is': $this->collector->descriptionIsNot($value); break; - // + // // currency - // + // case 'currency_is': $currency = $this->findCurrency($value); if (null !== $currency) { @@ -591,9 +591,9 @@ class OperatorQuerySearch implements SearchInterface $this->collector->findNothing(); } break; - // + // // attachments - // + // case 'has_attachments': case '-has_no_attachments': Log::debug('Set collector to filter on attachments.'); @@ -604,7 +604,7 @@ class OperatorQuerySearch implements SearchInterface Log::debug('Set collector to filter on NO attachments.'); $this->collector->hasNoAttachments(); break; - // + // // categories case '-has_any_category': case 'has_no_category': @@ -683,9 +683,9 @@ class OperatorQuerySearch implements SearchInterface $this->collector->findNothing(); } break; - // + // // budgets - // + // case '-has_any_budget': case 'has_no_budget': $this->collector->withoutBudget(); @@ -764,9 +764,9 @@ class OperatorQuerySearch implements SearchInterface $this->collector->findNothing(); } break; - // + // // bill - // + // case '-has_any_bill': case 'has_no_bill': $this->collector->withoutBill(); @@ -843,9 +843,9 @@ class OperatorQuerySearch implements SearchInterface $this->collector->findNothing(); } break; - // + // // tags - // + // case '-has_any_tag': case 'has_no_tag': $this->collector->withoutTags(); @@ -873,9 +873,9 @@ class OperatorQuerySearch implements SearchInterface $this->collector->setWithoutSpecificTags($result); } break; - // + // // notes - // + // case 'notes_contains': $this->collector->notesContain($value); break; @@ -914,9 +914,9 @@ class OperatorQuerySearch implements SearchInterface case '-reconciled': $this->collector->isNotReconciled(); break; - // + // // amount - // + // case 'amount_is': // strip comma's, make dots. Log::debug(sprintf('Original value "%s"', $value)); @@ -987,9 +987,9 @@ class OperatorQuerySearch implements SearchInterface Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); $this->collector->foreignAmountMore($amount); break; - // + // // transaction type - // + // case 'transaction_type': $this->collector->setTypes([ucfirst($value)]); Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value)); @@ -998,9 +998,9 @@ class OperatorQuerySearch implements SearchInterface $this->collector->excludeTypes([ucfirst($value)]); Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value)); break; - // + // // dates - // + // case '-date_on': case 'date_on': $range = $this->parseDateRange($value); @@ -1150,9 +1150,9 @@ class OperatorQuerySearch implements SearchInterface $range = $this->parseDateRange($value); $this->setObjectDateAfterParams('updated_at', $range); return false; - // + // // external URL - // + // case '-any_external_url': case 'no_external_url': $this->collector->withoutExternalUrl(); @@ -1195,9 +1195,9 @@ class OperatorQuerySearch implements SearchInterface $this->collector->externalUrlDoesNotEnd($value); break; - // + // // other fields - // + // case 'external_id_is': $this->collector->setExternalId($value); break; diff --git a/app/Transformers/V2/BudgetLimitTransformer.php b/app/Transformers/V2/BudgetLimitTransformer.php index 470410cab7..127aafe1e4 100644 --- a/app/Transformers/V2/BudgetLimitTransformer.php +++ b/app/Transformers/V2/BudgetLimitTransformer.php @@ -67,11 +67,11 @@ class BudgetLimitTransformer extends AbstractTransformer */ public function transform(BudgetLimit $budgetLimit): array { -// $repository = app(OperationsRepository::class); -// $repository->setUser($budgetLimit->budget->user); -// $expenses = $repository->sumExpenses( -// $budgetLimit->start_date, $budgetLimit->end_date, null, new Collection([$budgetLimit->budget]), $budgetLimit->transactionCurrency -// ); + // $repository = app(OperationsRepository::class); + // $repository->setUser($budgetLimit->budget->user); + // $expenses = $repository->sumExpenses( + // $budgetLimit->start_date, $budgetLimit->end_date, null, new Collection([$budgetLimit->budget]), $budgetLimit->transactionCurrency + // ); $currency = $budgetLimit->transactionCurrency; $amount = $budgetLimit->amount; $currencyDecimalPlaces = 2; diff --git a/app/Transformers/V2/BudgetTransformer.php b/app/Transformers/V2/BudgetTransformer.php index e7f0331e93..9d532faf3e 100644 --- a/app/Transformers/V2/BudgetTransformer.php +++ b/app/Transformers/V2/BudgetTransformer.php @@ -68,30 +68,30 @@ class BudgetTransformer extends AbstractTransformer $start = $this->parameters->get('start'); $end = $this->parameters->get('end'); //$autoBudget = $this->repository->getAutoBudget($budget); -// $spent = []; -// if (null !== $start && null !== $end) { -// $spent = $this->beautify($this->opsRepository->sumExpenses($start, $end, null, new Collection([$budget]))); -// } + // $spent = []; + // if (null !== $start && null !== $end) { + // $spent = $this->beautify($this->opsRepository->sumExpenses($start, $end, null, new Collection([$budget]))); + // } -// $abCurrencyId = null; -// $abCurrencyCode = null; -// $abType = null; -// $abAmount = null; -// $abPeriod = null; -// $notes = $this->repository->getNoteText($budget); -// -// $types = [ -// AutoBudget::AUTO_BUDGET_RESET => 'reset', -// AutoBudget::AUTO_BUDGET_ROLLOVER => 'rollover', -// ]; -// -// if (null !== $autoBudget) { -// $abCurrencyId = (string) $autoBudget->transactionCurrency->id; -// $abCurrencyCode = $autoBudget->transactionCurrency->code; -// $abType = $types[$autoBudget->auto_budget_type]; -// $abAmount = number_format((float) $autoBudget->amount, $autoBudget->transactionCurrency->decimal_places, '.', ''); -// $abPeriod = $autoBudget->period; -// } + // $abCurrencyId = null; + // $abCurrencyCode = null; + // $abType = null; + // $abAmount = null; + // $abPeriod = null; + // $notes = $this->repository->getNoteText($budget); + // + // $types = [ + // AutoBudget::AUTO_BUDGET_RESET => 'reset', + // AutoBudget::AUTO_BUDGET_ROLLOVER => 'rollover', + // ]; + // + // if (null !== $autoBudget) { + // $abCurrencyId = (string) $autoBudget->transactionCurrency->id; + // $abCurrencyCode = $autoBudget->transactionCurrency->code; + // $abType = $types[$autoBudget->auto_budget_type]; + // $abAmount = number_format((float) $autoBudget->amount, $autoBudget->transactionCurrency->decimal_places, '.', ''); + // $abPeriod = $autoBudget->period; + // } return [ 'id' => (string)$budget->id, diff --git a/config/mail.php b/config/mail.php index 5a83a2ae08..22a0401edc 100644 --- a/config/mail.php +++ b/config/mail.php @@ -41,8 +41,8 @@ return [ 'host' => envNonEmpty('MAIL_HOST', 'smtp.mailtrap.io'), 'port' => (int)env('MAIL_PORT', 2525), 'encryption' => envNonEmpty('MAIL_ENCRYPTION', 'tls'), - 'username' => envNonEmpty('MAIL_USERNAME','user@example.com'), - 'password' => envNonEmpty('MAIL_PASSWORD','password'), + 'username' => envNonEmpty('MAIL_USERNAME', 'user@example.com'), + 'password' => envNonEmpty('MAIL_PASSWORD', 'password'), 'timeout' => null, 'verify_peer' => null !== env('MAIL_ENCRYPTION'), ], diff --git a/database/migrations/2016_06_16_000000_create_support_tables.php b/database/migrations/2016_06_16_000000_create_support_tables.php index 18c6be1856..4258a92238 100644 --- a/database/migrations/2016_06_16_000000_create_support_tables.php +++ b/database/migrations/2016_06_16_000000_create_support_tables.php @@ -22,6 +22,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -67,177 +68,257 @@ class CreateSupportTables extends Migration $this->createConfigurationTable(); } + /** + * @return void + */ private function createAccountTypeTable(): void { if (!Schema::hasTable('account_types')) { - Schema::create( - 'account_types', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->string('type', 50); + try { + Schema::create( + 'account_types', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->string('type', 50); - // type must be unique. - $table->unique(['type']); - } - ); + // type must be unique. + $table->unique(['type']); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "account_types": %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.'); + } } } + /** + * @return void + */ private function createConfigurationTable(): void { if (!Schema::hasTable('configuration')) { - Schema::create( - 'configuration', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->string('name', 50); - $table->text('data'); - } - ); + try { + Schema::create( + 'configuration', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->string('name', 50); + $table->text('data'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "configuration": %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.'); + } } } + /** + * @return void + */ private function createCurrencyTable(): void { if (!Schema::hasTable('transaction_currencies')) { - Schema::create( - 'transaction_currencies', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->string('code', 3); - $table->string('name', 255); - $table->string('symbol', 12); + try { + Schema::create( + 'transaction_currencies', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->string('code', 3); + $table->string('name', 255); + $table->string('symbol', 12); - // code must be unique. - $table->unique(['code']); - } - ); + // code must be unique. + $table->unique(['code']); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "transaction_currencies": %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.'); + } } } + /** + * @return void + */ private function createJobsTable(): void { if (!Schema::hasTable('jobs')) { - Schema::create( - 'jobs', - static function (Blueprint $table) { - // straight from Laravel - $table->bigIncrements('id'); - $table->string('queue'); - $table->longText('payload'); - $table->tinyInteger('attempts')->unsigned(); - $table->tinyInteger('reserved')->unsigned(); - $table->unsignedInteger('reserved_at')->nullable(); - $table->unsignedInteger('available_at'); - $table->unsignedInteger('created_at'); - $table->index(['queue', 'reserved', 'reserved_at']); - } - ); + try { + Schema::create( + 'jobs', + static function (Blueprint $table) { + // straight from Laravel + $table->bigIncrements('id'); + $table->string('queue'); + $table->longText('payload'); + $table->tinyInteger('attempts')->unsigned(); + $table->tinyInteger('reserved')->unsigned(); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_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())); + Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.'); + } } } + /** + * @return void + */ private function createPasswordTable(): void { if (!Schema::hasTable('password_resets')) { - Schema::create( - 'password_resets', - static function (Blueprint $table) { - // straight from laravel - $table->string('email')->index(); - $table->string('token')->index(); - $table->timestamp('created_at')->nullable(); - } - ); + try { + Schema::create( + 'password_resets', + static function (Blueprint $table) { + // straight from laravel + $table->string('email')->index(); + $table->string('token')->index(); + $table->timestamp('created_at')->nullable(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "password_resets": %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.'); + } } } + /** + * @return void + */ private function createPermissionRoleTable(): void { if (!Schema::hasTable('permission_role')) { - Schema::create( - 'permission_role', - static function (Blueprint $table) { - $table->integer('permission_id')->unsigned(); - $table->integer('role_id')->unsigned(); + try { + Schema::create( + 'permission_role', + static function (Blueprint $table) { + $table->integer('permission_id')->unsigned(); + $table->integer('role_id')->unsigned(); - $table->foreign('permission_id')->references('id')->on('permissions')->onUpdate('cascade')->onDelete('cascade'); - $table->foreign('role_id')->references('id')->on('roles')->onUpdate('cascade')->onDelete('cascade'); + $table->foreign('permission_id')->references('id')->on('permissions')->onUpdate('cascade')->onDelete('cascade'); + $table->foreign('role_id')->references('id')->on('roles')->onUpdate('cascade')->onDelete('cascade'); - $table->primary(['permission_id', 'role_id']); - } - ); + $table->primary(['permission_id', 'role_id']); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "permission_role": %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.'); + } } } + /** + * @return void + */ private function createPermissionsTable(): void { if (!Schema::hasTable('permissions')) { - Schema::create( - 'permissions', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->string('name')->unique(); - $table->string('display_name')->nullable(); - $table->string('description')->nullable(); - } - ); + try { + Schema::create( + 'permissions', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->string('name')->unique(); + $table->string('display_name')->nullable(); + $table->string('description')->nullable(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "permissions": %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.'); + } } } + /** + * @return void + */ private function createRolesTable(): void { if (!Schema::hasTable('roles')) { - Schema::create( - 'roles', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->string('name')->unique(); - $table->string('display_name')->nullable(); - $table->string('description')->nullable(); - } - ); + try { + Schema::create( + 'roles', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->string('name')->unique(); + $table->string('display_name')->nullable(); + $table->string('description')->nullable(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "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.'); + } } } + /** + * @return void + */ private function createSessionsTable(): void { if (!Schema::hasTable('sessions')) { - Schema::create( - 'sessions', - static function (Blueprint $table) { - $table->string('id')->unique(); - $table->integer('user_id')->nullable(); - $table->string('ip_address', 45)->nullable(); - $table->text('user_agent')->nullable(); - $table->text('payload'); - $table->integer('last_activity'); - } - ); + try { + Schema::create( + 'sessions', + static function (Blueprint $table) { + $table->string('id')->unique(); + $table->integer('user_id')->nullable(); + $table->string('ip_address', 45)->nullable(); + $table->text('user_agent')->nullable(); + $table->text('payload'); + $table->integer('last_activity'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "sessions": %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.'); + } } } + /** + * @return void + */ private function createTransactionTypeTable(): void { if (!Schema::hasTable('transaction_types')) { - Schema::create( - 'transaction_types', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->string('type', 50); + try { + Schema::create( + 'transaction_types', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->string('type', 50); - // type must be unique. - $table->unique(['type']); - } - ); + // type must be unique. + $table->unique(['type']); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "transaction_types": %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.'); + } } } } diff --git a/database/migrations/2016_06_16_000001_create_users_table.php b/database/migrations/2016_06_16_000001_create_users_table.php index b52a52abf7..fe81681ab2 100644 --- a/database/migrations/2016_06_16_000001_create_users_table.php +++ b/database/migrations/2016_06_16_000001_create_users_table.php @@ -22,6 +22,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -47,19 +48,24 @@ class CreateUsersTable extends Migration public function up(): void { if (!Schema::hasTable('users')) { - Schema::create( - 'users', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->string('email', 255); - $table->string('password', 60); - $table->string('remember_token', 100)->nullable(); - $table->string('reset', 32)->nullable(); - $table->tinyInteger('blocked', false, true)->default('0'); - $table->string('blocked_code', 25)->nullable(); - } - ); + try { + Schema::create( + 'users', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->string('email', 255); + $table->string('password', 60); + $table->string('remember_token', 100)->nullable(); + $table->string('reset', 32)->nullable(); + $table->tinyInteger('blocked', false, true)->default('0'); + $table->string('blocked_code', 25)->nullable(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "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.'); + } } } } diff --git a/database/migrations/2016_06_16_000002_create_main_tables.php b/database/migrations/2016_06_16_000002_create_main_tables.php index ba70a57a08..b4d6199014 100644 --- a/database/migrations/2016_06_16_000002_create_main_tables.php +++ b/database/migrations/2016_06_16_000002_create_main_tables.php @@ -22,6 +22,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -41,8 +42,8 @@ class CreateMainTables extends Migration Schema::dropIfExists('attachments'); Schema::dropIfExists('limit_repetitions'); Schema::dropIfExists('budget_limits'); - Schema::dropIfExists('export_jobs'); - Schema::dropIfExists('import_jobs'); + Schema::dropIfExists('export_jobs'); // table is no longer created + Schema::dropIfExists('import_jobs'); // table is no longer created Schema::dropIfExists('preferences'); Schema::dropIfExists('role_user'); Schema::dropIfExists('rule_actions'); @@ -79,7 +80,6 @@ class CreateMainTables extends Migration $this->createBillsTable(); $this->createBudgetTables(); $this->createCategoriesTable(); - $this->createExportJobsTable(); $this->createPreferencesTable(); $this->createRoleTable(); $this->createRuleTables(); @@ -90,94 +90,114 @@ class CreateMainTables extends Migration private function createAccountTables(): void { if (!Schema::hasTable('accounts')) { - Schema::create( - 'accounts', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->integer('account_type_id', false, true); - $table->string('name', 1024); - $table->decimal('virtual_balance', 32, 12)->nullable(); - $table->string('iban', 255)->nullable(); - $table->boolean('active')->default(1); - $table->boolean('encrypted')->default(0); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - $table->foreign('account_type_id')->references('id')->on('account_types')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'accounts', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->integer('account_type_id', false, true); + $table->string('name', 1024); + $table->decimal('virtual_balance', 32, 12)->nullable(); + $table->string('iban', 255)->nullable(); + $table->boolean('active')->default(1); + $table->boolean('encrypted')->default(0); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('account_type_id')->references('id')->on('account_types')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "accounts": %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.'); + } } if (!Schema::hasTable('account_meta')) { - Schema::create( - 'account_meta', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('account_id', false, true); - $table->string('name'); - $table->text('data'); - $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'account_meta', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('account_id', false, true); + $table->string('name'); + $table->text('data'); + $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "account_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.'); + } } } private function createAttachmentsTable(): void { if (!Schema::hasTable('attachments')) { - Schema::create( - 'attachments', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->integer('attachable_id', false, true); - $table->string('attachable_type', 255); - $table->string('md5', 128); - $table->string('filename', 1024); - $table->string('title', 1024)->nullable(); - $table->text('description')->nullable(); - $table->text('notes')->nullable(); - $table->string('mime', 1024); - $table->integer('size', false, true); - $table->boolean('uploaded')->default(1); + try { + Schema::create( + 'attachments', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->integer('attachable_id', false, true); + $table->string('attachable_type', 255); + $table->string('md5', 128); + $table->string('filename', 1024); + $table->string('title', 1024)->nullable(); + $table->text('description')->nullable(); + $table->text('notes')->nullable(); + $table->string('mime', 1024); + $table->integer('size', false, true); + $table->boolean('uploaded')->default(1); - // link user id to users table - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); + // link user id to users table + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "attachments": %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.'); + } } } private function createBillsTable(): void { if (!Schema::hasTable('bills')) { - Schema::create( - 'bills', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->string('name', 1024); - $table->string('match', 1024); - $table->decimal('amount_min', 32, 12); - $table->decimal('amount_max', 32, 12); - $table->date('date'); - $table->string('repeat_freq', 30); - $table->smallInteger('skip', false, true)->default(0); - $table->boolean('automatch')->default(1); - $table->boolean('active')->default(1); - $table->boolean('name_encrypted')->default(0); - $table->boolean('match_encrypted')->default(0); + try { + Schema::create( + 'bills', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->string('name', 1024); + $table->string('match', 1024); + $table->decimal('amount_min', 32, 12); + $table->decimal('amount_max', 32, 12); + $table->date('date'); + $table->string('repeat_freq', 30); + $table->smallInteger('skip', false, true)->default(0); + $table->boolean('automatch')->default(1); + $table->boolean('active')->default(1); + $table->boolean('name_encrypted')->default(0); + $table->boolean('match_encrypted')->default(0); - // link user id to users table - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); + // link user id to users table + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "bills": %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.'); + } } } @@ -187,175 +207,189 @@ class CreateMainTables extends Migration private function createBudgetTables(): void { if (!Schema::hasTable('budgets')) { - Schema::create( - 'budgets', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->string('name', 1024); - $table->boolean('active')->default(1); - $table->boolean('encrypted')->default(0); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'budgets', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->string('name', 1024); + $table->boolean('active')->default(1); + $table->boolean('encrypted')->default(0); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "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.'); + } } if (!Schema::hasTable('budget_limits')) { - Schema::create( - 'budget_limits', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('budget_id', false, true); - $table->date('startdate'); - $table->decimal('amount', 32, 12); - $table->string('repeat_freq', 30); - $table->boolean('repeats')->default(0); - $table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'budget_limits', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('budget_id', false, true); + $table->date('startdate'); + $table->decimal('amount', 32, 12); + $table->string('repeat_freq', 30); + $table->boolean('repeats')->default(0); + $table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "budget_limits": %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.'); + } } if (!Schema::hasTable('limit_repetitions')) { - Schema::create( - 'limit_repetitions', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('budget_limit_id', false, true); - $table->date('startdate'); - $table->date('enddate'); - $table->decimal('amount', 32, 12); - $table->foreign('budget_limit_id')->references('id')->on('budget_limits')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'limit_repetitions', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('budget_limit_id', false, true); + $table->date('startdate'); + $table->date('enddate'); + $table->decimal('amount', 32, 12); + $table->foreign('budget_limit_id')->references('id')->on('budget_limits')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "limit_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.'); + } } } + /** + * @return void + */ private function createCategoriesTable(): void { if (!Schema::hasTable('categories')) { - Schema::create( - 'categories', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->string('name', 1024); - $table->boolean('encrypted')->default(0); + try { + Schema::create( + 'categories', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->string('name', 1024); + $table->boolean('encrypted')->default(0); - // link user id to users table - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); + // link user id to users table + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "categories": %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.'); + } } } - private function createExportJobsTable(): void - { - if (!Schema::hasTable('export_jobs')) { - Schema::create( - 'export_jobs', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('user_id', false, true); - $table->string('key', 12); - $table->string('status', 255); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); - } - - if (!Schema::hasTable('import_jobs')) { - Schema::create( - 'import_jobs', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('user_id')->unsigned(); - $table->string('key', 12)->unique(); - $table->string('file_type', 12); - $table->string('status', 45); - $table->text('configuration')->nullable(); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); - } - } private function createPiggyBanksTable(): void { if (!Schema::hasTable('piggy_banks')) { - Schema::create( - 'piggy_banks', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('account_id', false, true); - $table->string('name', 1024); - $table->decimal('targetamount', 32, 12); - $table->date('startdate')->nullable(); - $table->date('targetdate')->nullable(); - $table->integer('order', false, true)->default(0); - $table->boolean('active')->default(0); - $table->boolean('encrypted')->default(1); - $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'piggy_banks', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('account_id', false, true); + $table->string('name', 1024); + $table->decimal('targetamount', 32, 12); + $table->date('startdate')->nullable(); + $table->date('targetdate')->nullable(); + $table->integer('order', false, true)->default(0); + $table->boolean('active')->default(0); + $table->boolean('encrypted')->default(1); + $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "piggy_banks": %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.'); + } } if (!Schema::hasTable('piggy_bank_repetitions')) { - Schema::create( - 'piggy_bank_repetitions', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('piggy_bank_id', false, true); - $table->date('startdate')->nullable(); - $table->date('targetdate')->nullable(); - $table->decimal('currentamount', 32, 12); - $table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'piggy_bank_repetitions', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('piggy_bank_id', false, true); + $table->date('startdate')->nullable(); + $table->date('targetdate')->nullable(); + $table->decimal('currentamount', 32, 12); + $table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "piggy_bank_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.'); + } } } private function createPreferencesTable(): void { if (!Schema::hasTable('preferences')) { - Schema::create( - 'preferences', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('user_id', false, true); - $table->string('name', 1024); - $table->text('data'); + try { + Schema::create( + 'preferences', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('user_id', false, true); + $table->string('name', 1024); + $table->text('data'); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "preferences": %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.'); + } } } + /** + * @return void + */ private function createRoleTable(): void { if (!Schema::hasTable('role_user')) { - Schema::create( - 'role_user', - static function (Blueprint $table) { - $table->integer('user_id', false, true); - $table->integer('role_id', false, true); + try { + Schema::create( + 'role_user', + static function (Blueprint $table) { + $table->integer('user_id', false, true); + $table->integer('role_id', false, true); - $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade'); - $table->foreign('role_id')->references('id')->on('roles')->onUpdate('cascade')->onDelete('cascade'); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade'); + $table->foreign('role_id')->references('id')->on('roles')->onUpdate('cascade')->onDelete('cascade'); - $table->primary(['user_id', 'role_id']); - } - ); + $table->primary(['user_id', 'role_id']); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "role_user": %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.'); + } } } @@ -366,22 +400,27 @@ class CreateMainTables extends Migration private function createRuleTables(): void { if (!Schema::hasTable('rule_groups')) { - Schema::create( - 'rule_groups', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->string('title', 255); - $table->text('description')->nullable(); - $table->integer('order', false, true)->default(0); - $table->boolean('active')->default(1); + try { + Schema::create( + 'rule_groups', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->string('title', 255); + $table->text('description')->nullable(); + $table->integer('order', false, true)->default(0); + $table->boolean('active')->default(1); - // link user id to users table - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); + // link user id to users table + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "rule_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.'); + } } if (!Schema::hasTable('rules')) { Schema::create( @@ -407,226 +446,287 @@ class CreateMainTables extends Migration ); } if (!Schema::hasTable('rule_actions')) { - Schema::create( - 'rule_actions', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('rule_id', false, true); + try { + Schema::create( + 'rule_actions', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('rule_id', false, true); - $table->string('action_type', 50); - $table->string('action_value', 255); + $table->string('action_type', 50); + $table->string('action_value', 255); - $table->integer('order', false, true)->default(0); - $table->boolean('active')->default(1); - $table->boolean('stop_processing')->default(0); + $table->integer('order', false, true)->default(0); + $table->boolean('active')->default(1); + $table->boolean('stop_processing')->default(0); - // link rule id to rules table - $table->foreign('rule_id')->references('id')->on('rules')->onDelete('cascade'); - } - ); + // link rule id to rules table + $table->foreign('rule_id')->references('id')->on('rules')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "rule_actions": %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.'); + } } if (!Schema::hasTable('rule_triggers')) { - Schema::create( - 'rule_triggers', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('rule_id', false, true); + try { + Schema::create( + 'rule_triggers', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('rule_id', false, true); - $table->string('trigger_type', 50); - $table->string('trigger_value', 255); + $table->string('trigger_type', 50); + $table->string('trigger_value', 255); - $table->integer('order', false, true)->default(0); - $table->boolean('active')->default(1); - $table->boolean('stop_processing')->default(0); + $table->integer('order', false, true)->default(0); + $table->boolean('active')->default(1); + $table->boolean('stop_processing')->default(0); - // link rule id to rules table - $table->foreign('rule_id')->references('id')->on('rules')->onDelete('cascade'); - } - ); - } - } - - private function createTagsTable(): void - { - if (!Schema::hasTable('tags')) { - Schema::create( - 'tags', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - - $table->string('tag', 1024); - $table->string('tagMode', 1024); - $table->date('date')->nullable(); - $table->text('description')->nullable(); - $table->decimal('latitude', 12, 8)->nullable(); - $table->decimal('longitude', 12, 8)->nullable(); - $table->smallInteger('zoomLevel', false, true)->nullable(); - - // link user id to users table - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); + // link rule id to rules table + $table->foreign('rule_id')->references('id')->on('rules')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "rule_triggers": %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.'); + } } } /** - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped. - * @SuppressWarnings(PHPMD.NPathComplexity) // cannot be helped - * @SuppressWarnings(PHPMD.CyclomaticComplexity) // its exactly five + * @return void + */ + private function createTagsTable(): void + { + if (!Schema::hasTable('tags')) { + try { + Schema::create( + 'tags', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + + $table->string('tag', 1024); + $table->string('tagMode', 1024); + $table->date('date')->nullable(); + $table->text('description')->nullable(); + $table->decimal('latitude', 12, 8)->nullable(); + $table->decimal('longitude', 12, 8)->nullable(); + $table->smallInteger('zoomLevel', false, true)->nullable(); + + // link user id to users table + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "tags": %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.'); + } + } + } + + /** + * @return void */ private function createTransactionTables(): void { if (!Schema::hasTable('transaction_journals')) { - Schema::create( - 'transaction_journals', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->integer('transaction_type_id', false, true); - $table->integer('bill_id', false, true)->nullable(); - $table->integer('transaction_currency_id', false, true); - $table->string('description', 1024); - $table->date('date'); - $table->date('interest_date')->nullable(); - $table->date('book_date')->nullable(); - $table->date('process_date')->nullable(); - $table->integer('order', false, true)->default(0); - $table->integer('tag_count', false, true); - $table->boolean('encrypted')->default(1); - $table->boolean('completed')->default(1); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - $table->foreign('transaction_type_id')->references('id')->on('transaction_types')->onDelete('cascade'); - $table->foreign('bill_id')->references('id')->on('bills')->onDelete('set null'); - $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'transaction_journals', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->integer('transaction_type_id', false, true); + $table->integer('bill_id', false, true)->nullable(); + $table->integer('transaction_currency_id', false, true); + $table->string('description', 1024); + $table->date('date'); + $table->date('interest_date')->nullable(); + $table->date('book_date')->nullable(); + $table->date('process_date')->nullable(); + $table->integer('order', false, true)->default(0); + $table->integer('tag_count', false, true); + $table->boolean('encrypted')->default(1); + $table->boolean('completed')->default(1); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('transaction_type_id')->references('id')->on('transaction_types')->onDelete('cascade'); + $table->foreign('bill_id')->references('id')->on('bills')->onDelete('set null'); + $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "transaction_journals": %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.'); + } } if (!Schema::hasTable('journal_meta')) { - Schema::create( - 'journal_meta', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('transaction_journal_id', false, true); - $table->string('name', 255); - $table->text('data'); - $table->string('hash', 64); - $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'journal_meta', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('transaction_journal_id', false, true); + $table->string('name', 255); + $table->text('data'); + $table->string('hash', 64); + $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "journal_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.'); + } } if (!Schema::hasTable('tag_transaction_journal')) { - Schema::create( - 'tag_transaction_journal', - static function (Blueprint $table) { - $table->increments('id'); - $table->integer('tag_id', false, true); - $table->integer('transaction_journal_id', false, true); - $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade'); - $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); + try { + Schema::create( + 'tag_transaction_journal', + static function (Blueprint $table) { + $table->increments('id'); + $table->integer('tag_id', false, true); + $table->integer('transaction_journal_id', false, true); + $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade'); + $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); - // unique combi: - $table->unique(['tag_id', 'transaction_journal_id']); - } - ); + // unique combi: + $table->unique(['tag_id', 'transaction_journal_id']); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "tag_transaction_journal": %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.'); + } } if (!Schema::hasTable('budget_transaction_journal')) { - Schema::create( - 'budget_transaction_journal', - static function (Blueprint $table) { - $table->increments('id'); - $table->integer('budget_id', false, true); - $table->integer('transaction_journal_id', false, true); - $table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade'); - $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'budget_transaction_journal', + static function (Blueprint $table) { + $table->increments('id'); + $table->integer('budget_id', false, true); + $table->integer('transaction_journal_id', false, true); + $table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade'); + $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "budget_transaction_journal": %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.'); + } } if (!Schema::hasTable('category_transaction_journal')) { - Schema::create( - 'category_transaction_journal', - static function (Blueprint $table) { - $table->increments('id'); - $table->integer('category_id', false, true); - $table->integer('transaction_journal_id', false, true); - $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade'); - $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'category_transaction_journal', + static function (Blueprint $table) { + $table->increments('id'); + $table->integer('category_id', false, true); + $table->integer('transaction_journal_id', false, true); + $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade'); + $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "category_transaction_journal": %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.'); + } } if (!Schema::hasTable('piggy_bank_events')) { - Schema::create( - 'piggy_bank_events', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('piggy_bank_id', false, true); - $table->integer('transaction_journal_id', false, true)->nullable(); - $table->date('date'); - $table->decimal('amount', 32, 12); + try { + Schema::create( + 'piggy_bank_events', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('piggy_bank_id', false, true); + $table->integer('transaction_journal_id', false, true)->nullable(); + $table->date('date'); + $table->decimal('amount', 32, 12); - $table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade'); - $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('set null'); - } - ); + $table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade'); + $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('set null'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "piggy_bank_events": %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.'); + } } if (!Schema::hasTable('transactions')) { - Schema::create( - 'transactions', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('account_id', false, true); - $table->integer('transaction_journal_id', false, true); - $table->string('description', 1024)->nullable(); - $table->decimal('amount', 32, 12); + try { + Schema::create( + 'transactions', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('account_id', false, true); + $table->integer('transaction_journal_id', false, true); + $table->string('description', 1024)->nullable(); + $table->decimal('amount', 32, 12); - $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); - $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); - } - ); + $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); + $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "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.'); + } } if (!Schema::hasTable('budget_transaction')) { - Schema::create( - 'budget_transaction', - static function (Blueprint $table) { - $table->increments('id'); - $table->integer('budget_id', false, true); - $table->integer('transaction_id', false, true); + try { + Schema::create( + 'budget_transaction', + static function (Blueprint $table) { + $table->increments('id'); + $table->integer('budget_id', false, true); + $table->integer('transaction_id', false, true); - $table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade'); - $table->foreign('transaction_id')->references('id')->on('transactions')->onDelete('cascade'); - } - ); + $table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade'); + $table->foreign('transaction_id')->references('id')->on('transactions')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "budget_transaction": %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.'); + } } if (!Schema::hasTable('category_transaction')) { - Schema::create( - 'category_transaction', - static function (Blueprint $table) { - $table->increments('id'); - $table->integer('category_id', false, true); - $table->integer('transaction_id', false, true); + try { + Schema::create( + 'category_transaction', + static function (Blueprint $table) { + $table->increments('id'); + $table->integer('category_id', false, true); + $table->integer('transaction_id', false, true); - $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade'); - $table->foreign('transaction_id')->references('id')->on('transactions')->onDelete('cascade'); - } - ); + $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade'); + $table->foreign('transaction_id')->references('id')->on('transactions')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "category_transaction": %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.'); + } } } } diff --git a/database/migrations/2016_08_25_091522_changes_for_3101.php b/database/migrations/2016_08_25_091522_changes_for_3101.php index 611145cb5c..b56dd89926 100644 --- a/database/migrations/2016_08_25_091522_changes_for_3101.php +++ b/database/migrations/2016_08_25_091522_changes_for_3101.php @@ -22,7 +22,6 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; -use Illuminate\Database\Schema\Blueprint; /** * Class ChangesFor3101. @@ -36,14 +35,6 @@ class ChangesFor3101 extends Migration */ public function down(): void { - Schema::table( - 'import_jobs', - static function (Blueprint $table) { - if (Schema::hasColumn('import_jobs', 'extended_status')) { - $table->dropColumn('extended_status'); - } - } - ); } /** @@ -53,13 +44,5 @@ class ChangesFor3101 extends Migration */ public function up(): void { - Schema::table( - 'import_jobs', - static function (Blueprint $table) { - if (!Schema::hasColumn('import_jobs', 'extended_status')) { - $table->text('extended_status')->nullable(); - } - } - ); } } diff --git a/database/migrations/2016_09_12_121359_fix_nullables.php b/database/migrations/2016_09_12_121359_fix_nullables.php index c9bf391dff..0effd41a8b 100644 --- a/database/migrations/2016_09_12_121359_fix_nullables.php +++ b/database/migrations/2016_09_12_121359_fix_nullables.php @@ -22,6 +22,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -45,18 +46,28 @@ class FixNullables extends Migration */ public function up(): void { - Schema::table( - 'rule_groups', - static function (Blueprint $table) { - $table->text('description')->nullable()->change(); - } - ); + try { + Schema::table( + 'rule_groups', + static function (Blueprint $table) { + $table->text('description')->nullable()->change(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not update table: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } - Schema::table( - 'rules', - static function (Blueprint $table) { - $table->text('description')->nullable()->change(); - } - ); + try { + Schema::table( + 'rules', + static function (Blueprint $table) { + $table->text('description')->nullable()->change(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2016_10_09_150037_expand_transactions_table.php b/database/migrations/2016_10_09_150037_expand_transactions_table.php index 85da51be47..e2d6188ebd 100644 --- a/database/migrations/2016_10_09_150037_expand_transactions_table.php +++ b/database/migrations/2016_10_09_150037_expand_transactions_table.php @@ -21,7 +21,9 @@ */ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -36,12 +38,17 @@ class ExpandTransactionsTable extends Migration */ public function down(): void { - Schema::table( - 'transactions', - static function (Blueprint $table) { - $table->dropColumn('identifier'); - } - ); + try { + Schema::table( + 'transactions', + static function (Blueprint $table) { + $table->dropColumn('identifier'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not drop column "extended_status": %s', $e->getMessage())); + Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -51,11 +58,16 @@ class ExpandTransactionsTable extends Migration */ public function up(): void { - Schema::table( - 'transactions', - static function (Blueprint $table) { - $table->smallInteger('identifier', false, true)->default(0); - } - ); + try { + Schema::table( + 'transactions', + static function (Blueprint $table) { + $table->smallInteger('identifier', false, true)->default(0); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2016_10_22_075804_changes_for_v410.php b/database/migrations/2016_10_22_075804_changes_for_v410.php index 1624d1f4b7..823120c72b 100644 --- a/database/migrations/2016_10_22_075804_changes_for_v410.php +++ b/database/migrations/2016_10_22_075804_changes_for_v410.php @@ -22,6 +22,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -46,17 +47,22 @@ class ChangesForV410 extends Migration */ public function up(): void { - Schema::create( - 'notes', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('noteable_id', false, true); - $table->string('noteable_type'); - $table->string('title')->nullable(); - $table->text('text')->nullable(); - } - ); + try { + Schema::create( + 'notes', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('noteable_id', false, true); + $table->string('noteable_type'); + $table->string('title')->nullable(); + $table->text('text')->nullable(); + } + ); + } catch (QueryException $e) { + 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.'); + } } } diff --git a/database/migrations/2016_11_24_210552_changes_for_v420.php b/database/migrations/2016_11_24_210552_changes_for_v420.php index a6884f164d..b6de4904b7 100644 --- a/database/migrations/2016_11_24_210552_changes_for_v420.php +++ b/database/migrations/2016_11_24_210552_changes_for_v420.php @@ -22,6 +22,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -36,12 +37,17 @@ class ChangesForV420 extends Migration */ public function down(): void { - Schema::table( - 'journal_meta', - static function (Blueprint $table) { - $table->dropSoftDeletes(); - } - ); + try { + Schema::table( + 'journal_meta', + static function (Blueprint $table) { + $table->dropSoftDeletes(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -51,11 +57,16 @@ class ChangesForV420 extends Migration */ public function up(): void { - Schema::table( - 'journal_meta', - static function (Blueprint $table) { - $table->softDeletes(); - } - ); + try { + Schema::table( + 'journal_meta', + static function (Blueprint $table) { + $table->softDeletes(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2016_12_22_150431_changes_for_v430.php b/database/migrations/2016_12_22_150431_changes_for_v430.php index f478647289..08d0288cde 100644 --- a/database/migrations/2016_12_22_150431_changes_for_v430.php +++ b/database/migrations/2016_12_22_150431_changes_for_v430.php @@ -22,6 +22,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -46,21 +47,26 @@ class ChangesForV430 extends Migration */ public function up(): void { - Schema::create( - 'available_budgets', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->integer('transaction_currency_id', false, true); - $table->decimal('amount', 32, 12); - $table->date('start_date'); - $table->date('end_date'); + try { + Schema::create( + 'available_budgets', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->integer('transaction_currency_id', false, true); + $table->decimal('amount', 32, 12); + $table->date('start_date'); + $table->date('end_date'); - $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade'); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); + $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade'); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + 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.'); + } } } diff --git a/database/migrations/2016_12_28_203205_changes_for_v431.php b/database/migrations/2016_12_28_203205_changes_for_v431.php index 66b25ffb80..bdfd992bde 100644 --- a/database/migrations/2016_12_28_203205_changes_for_v431.php +++ b/database/migrations/2016_12_28_203205_changes_for_v431.php @@ -21,7 +21,9 @@ */ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -37,41 +39,66 @@ class ChangesForV431 extends Migration public function down(): void { // reinstate "repeats" and "repeat_freq". - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - $table->string('repeat_freq', 30)->nullable(); - } - ); - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - $table->boolean('repeats')->default(0); - } - ); + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + $table->string('repeat_freq', 30)->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.'); + } + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + $table->boolean('repeats')->default(0); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // change field "start_date" to "startdate" - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - $table->renameColumn('start_date', 'startdate'); - } - ); + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + $table->renameColumn('start_date', 'startdate'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // remove date field "end_date" - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - $table->dropColumn('end_date'); - } - ); + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + $table->dropColumn('end_date'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // remove decimal places - Schema::table( - 'transaction_currencies', - static function (Blueprint $table) { - $table->dropColumn('decimal_places'); - } - ); + try { + Schema::table( + 'transaction_currencies', + static function (Blueprint $table) { + $table->dropColumn('decimal_places'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -83,41 +110,66 @@ class ChangesForV431 extends Migration public function up(): void { // add decimal places to "transaction currencies". - Schema::table( - 'transaction_currencies', - static function (Blueprint $table) { - $table->smallInteger('decimal_places', false, true)->default(2); - } - ); + try { + Schema::table( + 'transaction_currencies', + static function (Blueprint $table) { + $table->smallInteger('decimal_places', false, true)->default(2); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // change field "startdate" to "start_date" - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - $table->renameColumn('startdate', 'start_date'); - } - ); + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + $table->renameColumn('startdate', 'start_date'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // add date field "end_date" after "start_date" - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - $table->date('end_date')->nullable()->after('start_date'); - } - ); + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + $table->date('end_date')->nullable()->after('start_date'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // drop "repeats" and "repeat_freq". - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - $table->dropColumn('repeats'); - } - ); - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - $table->dropColumn('repeat_freq'); - } - ); + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + $table->dropColumn('repeats'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + $table->dropColumn('repeat_freq'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2017_04_13_163623_changes_for_v440.php b/database/migrations/2017_04_13_163623_changes_for_v440.php index 79204d198b..330bdf3431 100644 --- a/database/migrations/2017_04_13_163623_changes_for_v440.php +++ b/database/migrations/2017_04_13_163623_changes_for_v440.php @@ -21,7 +21,9 @@ */ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -36,22 +38,24 @@ class ChangesForV440 extends Migration */ public function down(): void { - if (Schema::hasTable('currency_exchange_rates')) { - Schema::dropIfExists('currency_exchange_rates'); - } - - Schema::table( - 'transactions', - static function (Blueprint $table) { - if (Schema::hasColumn('transactions', 'transaction_currency_id')) { - // cannot drop foreign keys in SQLite: - if ('sqlite' !== config('database.default')) { - $table->dropForeign('transactions_transaction_currency_id_foreign'); + Schema::dropIfExists('currency_exchange_rates'); + try { + Schema::table( + 'transactions', + static function (Blueprint $table) { + if (Schema::hasColumn('transactions', 'transaction_currency_id')) { + // cannot drop foreign keys in SQLite: + if ('sqlite' !== config('database.default')) { + $table->dropForeign('transactions_transaction_currency_id_foreign'); + } + $table->dropColumn('transaction_currency_id'); } - $table->dropColumn('transaction_currency_id'); } - } - ); + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -62,34 +66,44 @@ class ChangesForV440 extends Migration public function up(): void { if (!Schema::hasTable('currency_exchange_rates')) { - Schema::create( - 'currency_exchange_rates', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->integer('from_currency_id', false, true); - $table->integer('to_currency_id', false, true); - $table->date('date'); - $table->decimal('rate', 32, 12); - $table->decimal('user_rate', 32, 12)->nullable(); + try { + Schema::create( + 'currency_exchange_rates', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->integer('from_currency_id', false, true); + $table->integer('to_currency_id', false, true); + $table->date('date'); + $table->decimal('rate', 32, 12); + $table->decimal('user_rate', 32, 12)->nullable(); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - $table->foreign('from_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade'); - $table->foreign('to_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade'); - } - ); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('from_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade'); + $table->foreign('to_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + 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.'); + } } - Schema::table( - 'transactions', - static function (Blueprint $table) { - if (!Schema::hasColumn('transactions', 'transaction_currency_id')) { - $table->integer('transaction_currency_id', false, true)->after('description')->nullable(); - $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); + try { + Schema::table( + 'transactions', + static function (Blueprint $table) { + if (!Schema::hasColumn('transactions', 'transaction_currency_id')) { + $table->integer('transaction_currency_id', false, true)->after('description')->nullable(); + $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); + } } - } - ); + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2017_06_02_105232_changes_for_v450.php b/database/migrations/2017_06_02_105232_changes_for_v450.php index 706a75fe39..c632ec6aa3 100644 --- a/database/migrations/2017_06_02_105232_changes_for_v450.php +++ b/database/migrations/2017_06_02_105232_changes_for_v450.php @@ -21,7 +21,9 @@ */ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -37,29 +39,44 @@ class ChangesForV450 extends Migration public function down(): void { // split up for sqlite compatibility - Schema::table( - 'transactions', - static function (Blueprint $table) { - $table->dropColumn('foreign_amount'); - } - ); - - Schema::table( - 'transactions', - static function (Blueprint $table) { - // cannot drop foreign keys in SQLite: - if ('sqlite' !== config('database.default')) { - $table->dropForeign('transactions_foreign_currency_id_foreign'); + try { + Schema::table( + 'transactions', + static function (Blueprint $table) { + $table->dropColumn('foreign_amount'); } - } - ); + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } - Schema::table( - 'transactions', - static function (Blueprint $table) { - $table->dropColumn('foreign_currency_id'); - } - ); + try { + Schema::table( + 'transactions', + static function (Blueprint $table) { + // cannot drop foreign keys in SQLite: + if ('sqlite' !== config('database.default')) { + $table->dropForeign('transactions_foreign_currency_id_foreign'); + } + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } + + try { + Schema::table( + 'transactions', + static function (Blueprint $table) { + $table->dropColumn('foreign_currency_id'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -70,20 +87,30 @@ class ChangesForV450 extends Migration public function up(): void { // add "foreign_amount" to transactions - Schema::table( - 'transactions', - static function (Blueprint $table) { - $table->decimal('foreign_amount', 32, 12)->nullable()->after('amount'); - } - ); + try { + Schema::table( + 'transactions', + static function (Blueprint $table) { + $table->decimal('foreign_amount', 32, 12)->nullable()->after('amount'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // add foreign transaction currency id to transactions (is nullable): - Schema::table( - 'transactions', - static function (Blueprint $table) { - $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'); - } - ); + try { + Schema::table( + 'transactions', + static function (Blueprint $table) { + $table->integer('foreign_currency_id', false, true)->default(null)->after('foreign_amount')->nullable(); + $table->foreign('foreign_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2017_08_20_062014_changes_for_v470.php b/database/migrations/2017_08_20_062014_changes_for_v470.php index 1fe2eff2ac..3d7c6bd8aa 100644 --- a/database/migrations/2017_08_20_062014_changes_for_v470.php +++ b/database/migrations/2017_08_20_062014_changes_for_v470.php @@ -22,6 +22,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -49,40 +50,50 @@ class ChangesForV470 extends Migration public function up(): void { if (!Schema::hasTable('link_types')) { - Schema::create( - 'link_types', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->string('name'); - $table->string('outward'); - $table->string('inward'); - $table->boolean('editable'); + try { + Schema::create( + 'link_types', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->string('name'); + $table->string('outward'); + $table->string('inward'); + $table->boolean('editable'); - $table->unique(['name', 'outward', 'inward']); - } - ); + $table->unique(['name', 'outward', 'inward']); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "link_types": %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.'); + } } if (!Schema::hasTable('journal_links')) { - Schema::create( - 'journal_links', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->integer('link_type_id', false, true); - $table->integer('source_id', false, true); - $table->integer('destination_id', false, true); - $table->text('comment')->nullable(); + try { + Schema::create( + 'journal_links', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->integer('link_type_id', false, true); + $table->integer('source_id', false, true); + $table->integer('destination_id', false, true); + $table->text('comment')->nullable(); - $table->foreign('link_type_id')->references('id')->on('link_types')->onDelete('cascade'); - $table->foreign('source_id')->references('id')->on('transaction_journals')->onDelete('cascade'); - $table->foreign('destination_id')->references('id')->on('transaction_journals')->onDelete('cascade'); + $table->foreign('link_type_id')->references('id')->on('link_types')->onDelete('cascade'); + $table->foreign('source_id')->references('id')->on('transaction_journals')->onDelete('cascade'); + $table->foreign('destination_id')->references('id')->on('transaction_journals')->onDelete('cascade'); - $table->unique(['link_type_id', 'source_id', 'destination_id']); - } - ); + $table->unique(['link_type_id', 'source_id', 'destination_id']); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "journal_links": %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.'); + } } } } diff --git a/database/migrations/2017_11_04_170844_changes_for_v470a.php b/database/migrations/2017_11_04_170844_changes_for_v470a.php index dcc1ada526..7132ef40e2 100644 --- a/database/migrations/2017_11_04_170844_changes_for_v470a.php +++ b/database/migrations/2017_11_04_170844_changes_for_v470a.php @@ -21,7 +21,9 @@ */ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -37,12 +39,17 @@ class ChangesForV470a extends Migration */ public function down(): void { - Schema::table( - 'transactions', - static function (Blueprint $table) { - $table->dropColumn('reconciled'); - } - ); + try { + Schema::table( + 'transactions', + static function (Blueprint $table) { + $table->dropColumn('reconciled'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -52,11 +59,16 @@ class ChangesForV470a extends Migration */ public function up(): void { - Schema::table( - 'transactions', - static function (Blueprint $table) { - $table->boolean('reconciled')->after('deleted_at')->default(0); - } - ); + try { + Schema::table( + 'transactions', + static function (Blueprint $table) { + $table->boolean('reconciled')->after('deleted_at')->default(0); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2018_01_01_000001_create_oauth_auth_codes_table.php b/database/migrations/2018_01_01_000001_create_oauth_auth_codes_table.php index 8a0790e31a..feba2c4ee9 100644 --- a/database/migrations/2018_01_01_000001_create_oauth_auth_codes_table.php +++ b/database/migrations/2018_01_01_000001_create_oauth_auth_codes_table.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -47,16 +48,21 @@ class CreateOauthAuthCodesTable extends Migration */ public function up(): void { - Schema::create( - 'oauth_auth_codes', - static function (Blueprint $table) { - $table->string('id', 100)->primary(); - $table->integer('user_id'); - $table->integer('client_id'); - $table->text('scopes')->nullable(); - $table->boolean('revoked'); - $table->dateTime('expires_at')->nullable(); - } - ); + try { + Schema::create( + 'oauth_auth_codes', + static function (Blueprint $table) { + $table->string('id', 100)->primary(); + $table->integer('user_id'); + $table->integer('client_id'); + $table->text('scopes')->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())); + Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.'); + } } } diff --git a/database/migrations/2018_01_01_000002_create_oauth_access_tokens_table.php b/database/migrations/2018_01_01_000002_create_oauth_access_tokens_table.php index 883955a3e7..aabefd4ad0 100644 --- a/database/migrations/2018_01_01_000002_create_oauth_access_tokens_table.php +++ b/database/migrations/2018_01_01_000002_create_oauth_access_tokens_table.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -47,18 +48,23 @@ class CreateOauthAccessTokensTable extends Migration */ public function up(): void { - Schema::create( - 'oauth_access_tokens', - static function (Blueprint $table) { - $table->string('id', 100)->primary(); - $table->integer('user_id')->index()->nullable(); - $table->integer('client_id'); - $table->string('name')->nullable(); - $table->text('scopes')->nullable(); - $table->boolean('revoked'); - $table->timestamps(); - $table->dateTime('expires_at')->nullable(); - } - ); + try { + Schema::create( + 'oauth_access_tokens', + static function (Blueprint $table) { + $table->string('id', 100)->primary(); + $table->integer('user_id')->index()->nullable(); + $table->integer('client_id'); + $table->string('name')->nullable(); + $table->text('scopes')->nullable(); + $table->boolean('revoked'); + $table->timestamps(); + $table->dateTime('expires_at')->nullable(); + } + ); + } catch (QueryException $e) { + 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.'); + } } } diff --git a/database/migrations/2018_01_01_000003_create_oauth_refresh_tokens_table.php b/database/migrations/2018_01_01_000003_create_oauth_refresh_tokens_table.php index 44a7aecdcb..3b4fafbc2f 100644 --- a/database/migrations/2018_01_01_000003_create_oauth_refresh_tokens_table.php +++ b/database/migrations/2018_01_01_000003_create_oauth_refresh_tokens_table.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -47,14 +48,19 @@ class CreateOauthRefreshTokensTable extends Migration */ public function up(): void { - Schema::create( - 'oauth_refresh_tokens', - static function (Blueprint $table) { - $table->string('id', 100)->primary(); - $table->string('access_token_id', 100)->index(); - $table->boolean('revoked'); - $table->dateTime('expires_at')->nullable(); - } - ); + try { + Schema::create( + 'oauth_refresh_tokens', + static function (Blueprint $table) { + $table->string('id', 100)->primary(); + $table->string('access_token_id', 100)->index(); + $table->boolean('revoked'); + $table->dateTime('expires_at')->nullable(); + } + ); + } catch (QueryException $e) { + 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.'); + } } } diff --git a/database/migrations/2018_01_01_000004_create_oauth_clients_table.php b/database/migrations/2018_01_01_000004_create_oauth_clients_table.php index 2fc046a840..5ec5131cd3 100644 --- a/database/migrations/2018_01_01_000004_create_oauth_clients_table.php +++ b/database/migrations/2018_01_01_000004_create_oauth_clients_table.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -47,19 +48,24 @@ class CreateOauthClientsTable extends Migration */ public function up(): void { - Schema::create( - 'oauth_clients', - static function (Blueprint $table) { - $table->increments('id'); - $table->integer('user_id')->index()->nullable(); - $table->string('name'); - $table->string('secret', 100); - $table->text('redirect'); - $table->boolean('personal_access_client'); - $table->boolean('password_client'); - $table->boolean('revoked'); - $table->timestamps(); - } - ); + try { + Schema::create( + 'oauth_clients', + static function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->index()->nullable(); + $table->string('name'); + $table->string('secret', 100); + $table->text('redirect'); + $table->boolean('personal_access_client'); + $table->boolean('password_client'); + $table->boolean('revoked'); + $table->timestamps(); + } + ); + } catch (QueryException $e) { + 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.'); + } } } diff --git a/database/migrations/2018_01_01_000005_create_oauth_personal_access_clients_table.php b/database/migrations/2018_01_01_000005_create_oauth_personal_access_clients_table.php index 35236cff40..0df1b8520d 100644 --- a/database/migrations/2018_01_01_000005_create_oauth_personal_access_clients_table.php +++ b/database/migrations/2018_01_01_000005_create_oauth_personal_access_clients_table.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -47,13 +48,18 @@ class CreateOauthPersonalAccessClientsTable extends Migration */ public function up(): void { - Schema::create( - 'oauth_personal_access_clients', - static function (Blueprint $table) { - $table->increments('id'); - $table->integer('client_id')->index(); - $table->timestamps(); - } - ); + try { + Schema::create( + 'oauth_personal_access_clients', + static function (Blueprint $table) { + $table->increments('id'); + $table->integer('client_id')->index(); + $table->timestamps(); + } + ); + } catch (QueryException $e) { + 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.'); + } } } diff --git a/database/migrations/2018_03_19_141348_changes_for_v472.php b/database/migrations/2018_03_19_141348_changes_for_v472.php index 060d83cf4b..0c046f9914 100644 --- a/database/migrations/2018_03_19_141348_changes_for_v472.php +++ b/database/migrations/2018_03_19_141348_changes_for_v472.php @@ -22,7 +22,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -39,18 +41,29 @@ class ChangesForV472 extends Migration */ public function down(): void { - Schema::table( - 'attachments', - static function (Blueprint $table) { - $table->text('notes')->nullable(); - } - ); - Schema::table( - 'budgets', - static function (Blueprint $table) { - $table->dropColumn('order'); - } - ); + try { + Schema::table( + 'attachments', + static function (Blueprint $table) { + $table->text('notes')->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.'); + } + + try { + Schema::table( + 'budgets', + static function (Blueprint $table) { + $table->dropColumn('order'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -61,18 +74,28 @@ class ChangesForV472 extends Migration */ public function up(): void { - Schema::table( - 'attachments', - static function (Blueprint $table) { - $table->dropColumn('notes'); - } - ); + try { + Schema::table( + 'attachments', + static function (Blueprint $table) { + $table->dropColumn('notes'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } - Schema::table( - 'budgets', - static function (Blueprint $table) { - $table->mediumInteger('order', false, true)->default(0); - } - ); + try { + Schema::table( + 'budgets', + static function (Blueprint $table) { + $table->mediumInteger('order', false, true)->default(0); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2018_04_07_210913_changes_for_v473.php b/database/migrations/2018_04_07_210913_changes_for_v473.php index 33e93911f8..53a4960338 100644 --- a/database/migrations/2018_04_07_210913_changes_for_v473.php +++ b/database/migrations/2018_04_07_210913_changes_for_v473.php @@ -22,7 +22,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -40,23 +42,34 @@ class ChangesForV473 extends Migration */ public function down(): void { - Schema::table( - 'bills', - static function (Blueprint $table) { - // cannot drop foreign keys in SQLite: - if ('sqlite' !== config('database.default')) { - $table->dropForeign('bills_transaction_currency_id_foreign'); + try { + Schema::table( + 'bills', + static function (Blueprint $table) { + // cannot drop foreign keys in SQLite: + if ('sqlite' !== config('database.default')) { + $table->dropForeign('bills_transaction_currency_id_foreign'); + } + $table->dropColumn('transaction_currency_id'); } - $table->dropColumn('transaction_currency_id'); - } - ); + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } - Schema::table( - 'rules', - static function (Blueprint $table) { - $table->dropColumn('strict'); - } - ); + + try { + Schema::table( + 'rules', + static function (Blueprint $table) { + $table->dropColumn('strict'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -67,18 +80,28 @@ class ChangesForV473 extends Migration */ public function up(): void { - Schema::table( - 'bills', - static function (Blueprint $table) { - $table->integer('transaction_currency_id', false, true)->nullable()->after('user_id'); - $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); - } - ); - Schema::table( - 'rules', - static function (Blueprint $table) { - $table->boolean('strict')->default(true); - } - ); + try { + Schema::table( + 'bills', + static function (Blueprint $table) { + $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())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } + try { + Schema::table( + 'rules', + static function (Blueprint $table) { + $table->boolean('strict')->default(true); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2018_04_29_174524_changes_for_v474.php b/database/migrations/2018_04_29_174524_changes_for_v474.php index 132b86dc47..7e570e57a6 100644 --- a/database/migrations/2018_04_29_174524_changes_for_v474.php +++ b/database/migrations/2018_04_29_174524_changes_for_v474.php @@ -23,7 +23,6 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; -use Illuminate\Database\Schema\Blueprint; /** * Class ChangesForV474. @@ -34,57 +33,11 @@ class ChangesForV474 extends Migration { /** * Reverse the migrations. - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * * @return void */ public function down(): void { - // split up for sqlite compatibility. - Schema::table( - 'import_jobs', - static function (Blueprint $table) { - // cannot drop foreign keys in SQLite: - if ('sqlite' !== config('database.default')) { - $table->dropForeign('import_jobs_tag_id_foreign'); - } - } - ); - - Schema::table( - 'import_jobs', - static function (Blueprint $table) { - $table->dropColumn('provider'); - } - ); - - Schema::table( - 'import_jobs', - static function (Blueprint $table) { - $table->dropColumn('stage'); - } - ); - - Schema::table( - 'import_jobs', - static function (Blueprint $table) { - $table->dropColumn('transactions'); - } - ); - - Schema::table( - 'import_jobs', - static function (Blueprint $table) { - $table->dropColumn('errors'); - } - ); - - Schema::table( - 'import_jobs', - static function (Blueprint $table) { - $table->dropColumn('tag_id'); - } - ); } /** @@ -95,17 +48,5 @@ class ChangesForV474 extends Migration */ public function up(): void { - Schema::table( - 'import_jobs', - static function (Blueprint $table) { - $table->string('provider', 50)->after('file_type')->default(''); - $table->string('stage', 50)->after('status')->default(''); - $table->longText('transactions')->after('extended_status')->nullable(); - $table->longText('errors')->after('transactions')->nullable(); - - $table->integer('tag_id', false, true)->nullable()->after('user_id'); - $table->foreign('tag_id')->references('id')->on('tags')->onDelete('set null'); - } - ); } } diff --git a/database/migrations/2018_06_08_200526_changes_for_v475.php b/database/migrations/2018_06_08_200526_changes_for_v475.php index 17c6f86898..0ecdd6bb0a 100644 --- a/database/migrations/2018_06_08_200526_changes_for_v475.php +++ b/database/migrations/2018_06_08_200526_changes_for_v475.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -55,99 +56,122 @@ class ChangesForV475 extends Migration */ public function up(): void { - Schema::create( - 'recurrences', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->integer('transaction_type_id', false, true); + try { + Schema::create( + 'recurrences', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->integer('transaction_type_id', false, true); - $table->string('title', 1024); - $table->text('description'); + $table->string('title', 1024); + $table->text('description'); - $table->date('first_date'); - $table->date('repeat_until')->nullable(); - $table->date('latest_date')->nullable(); - $table->smallInteger('repetitions', false, true); + $table->date('first_date'); + $table->date('repeat_until')->nullable(); + $table->date('latest_date')->nullable(); + $table->smallInteger('repetitions', false, true); - $table->boolean('apply_rules')->default(true); - $table->boolean('active')->default(true); + $table->boolean('apply_rules')->default(true); + $table->boolean('active')->default(true); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - $table->foreign('transaction_type_id')->references('id')->on('transaction_types')->onDelete('cascade'); - } - ); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('transaction_type_id')->references('id')->on('transaction_types')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + 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.'); + } + try { + Schema::create( + 'recurrences_transactions', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('recurrence_id', false, true); + $table->integer('transaction_currency_id', false, true); + $table->integer('foreign_currency_id', false, true)->nullable(); + $table->integer('source_id', false, true); + $table->integer('destination_id', false, true); - Schema::create( - 'recurrences_transactions', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('recurrence_id', false, true); - $table->integer('transaction_currency_id', false, true); - $table->integer('foreign_currency_id', false, true)->nullable(); - $table->integer('source_id', false, true); - $table->integer('destination_id', false, true); + $table->decimal('amount', 32, 12); + $table->decimal('foreign_amount', 32, 12)->nullable(); + $table->string('description', 1024); - $table->decimal('amount', 32, 12); - $table->decimal('foreign_amount', 32, 12)->nullable(); - $table->string('description', 1024); + $table->foreign('recurrence_id')->references('id')->on('recurrences')->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('source_id')->references('id')->on('accounts')->onDelete('cascade'); + $table->foreign('destination_id')->references('id')->on('accounts')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "recurrences_transactions": %s', $e->getMessage())); + Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.'); + } - $table->foreign('recurrence_id')->references('id')->on('recurrences')->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('source_id')->references('id')->on('accounts')->onDelete('cascade'); - $table->foreign('destination_id')->references('id')->on('accounts')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'recurrences_repetitions', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('recurrence_id', false, true); + $table->string('repetition_type', 50); + $table->string('repetition_moment', 50); + $table->smallInteger('repetition_skip', false, true); + $table->smallInteger('weekend', false, true); - Schema::create( - 'recurrences_repetitions', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('recurrence_id', false, true); - $table->string('repetition_type', 50); - $table->string('repetition_moment', 50); - $table->smallInteger('repetition_skip', false, true); - $table->smallInteger('weekend', false, true); + $table->foreign('recurrence_id')->references('id')->on('recurrences')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "recurrences_repetitions": %s', $e->getMessage())); + Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.'); + } - $table->foreign('recurrence_id')->references('id')->on('recurrences')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'recurrences_meta', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('recurrence_id', false, true); - Schema::create( - 'recurrences_meta', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('recurrence_id', false, true); + $table->string('name', 50); + $table->text('value'); - $table->string('name', 50); - $table->text('value'); + $table->foreign('recurrence_id')->references('id')->on('recurrences')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "recurrences_meta": %s', $e->getMessage())); + Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.'); + } + try { + Schema::create( + 'rt_meta', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('rt_id', false, true); - $table->foreign('recurrence_id')->references('id')->on('recurrences')->onDelete('cascade'); - } - ); + $table->string('name', 50); + $table->text('value'); - 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); - $table->text('value'); - - $table->foreign('rt_id')->references('id')->on('recurrences_transactions')->onDelete('cascade'); - } - ); + $table->foreign('rt_id')->references('id')->on('recurrences_transactions')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "rt_meta": %s', $e->getMessage())); + Log::error('If this table exists already (see the error message), this is not a problem. Other errors? Please open a discussion on GitHub.'); + } } } diff --git a/database/migrations/2018_09_05_195147_changes_for_v477.php b/database/migrations/2018_09_05_195147_changes_for_v477.php index 3db1986b8f..be9f4e233b 100644 --- a/database/migrations/2018_09_05_195147_changes_for_v477.php +++ b/database/migrations/2018_09_05_195147_changes_for_v477.php @@ -22,7 +22,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -39,17 +41,22 @@ class ChangesForV477 extends Migration */ public function down(): void { - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - // cannot drop foreign keys in SQLite: - if ('sqlite' !== config('database.default')) { - $table->dropForeign('budget_limits_transaction_currency_id_foreign'); - } + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + // cannot drop foreign keys in SQLite: + if ('sqlite' !== config('database.default')) { + $table->dropForeign('budget_limits_transaction_currency_id_foreign'); + } - $table->dropColumn(['transaction_currency_id']); - } - ); + $table->dropColumn(['transaction_currency_id']); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -60,12 +67,17 @@ class ChangesForV477 extends Migration */ public function up(): void { - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - $table->integer('transaction_currency_id', false, true)->nullable()->after('budget_id'); - $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); - } - ); + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + $table->integer('transaction_currency_id', false, true)->nullable()->after('budget_id'); + $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2018_11_06_172532_changes_for_v479.php b/database/migrations/2018_11_06_172532_changes_for_v479.php index 9cc0093cbf..6445235f96 100644 --- a/database/migrations/2018_11_06_172532_changes_for_v479.php +++ b/database/migrations/2018_11_06_172532_changes_for_v479.php @@ -22,7 +22,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -37,14 +39,19 @@ class ChangesForV479 extends Migration * * @return void */ - public function down() + public function down(): void { - Schema::table( - 'transaction_currencies', - static function (Blueprint $table) { - $table->dropColumn(['enabled']); - } - ); + try { + Schema::table( + 'transaction_currencies', + static function (Blueprint $table) { + $table->dropColumn(['enabled']); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -53,13 +60,18 @@ class ChangesForV479 extends Migration * * @return void */ - public function up() + public function up(): void { - Schema::table( - 'transaction_currencies', - static function (Blueprint $table) { - $table->boolean('enabled')->default(0)->after('deleted_at'); - } - ); + try { + Schema::table( + 'transaction_currencies', + static function (Blueprint $table) { + $table->boolean('enabled')->default(0)->after('deleted_at'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2019_01_28_193833_changes_for_v4710.php b/database/migrations/2019_01_28_193833_changes_for_v4710.php index 0e07b4286f..d52d5cf8b4 100644 --- a/database/migrations/2019_01_28_193833_changes_for_v4710.php +++ b/database/migrations/2019_01_28_193833_changes_for_v4710.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -53,35 +54,45 @@ class ChangesForV4710 extends Migration public function up(): void { if (!Schema::hasTable('transaction_groups')) { - Schema::create( - 'transaction_groups', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->string('title', 1024)->nullable(); + try { + Schema::create( + 'transaction_groups', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->string('title', 1024)->nullable(); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "transaction_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.'); + } } if (!Schema::hasTable('group_journals')) { - Schema::create( - 'group_journals', - static function (Blueprint $table) { - $table->increments('id'); - $table->integer('transaction_group_id', false, true); - $table->integer('transaction_journal_id', false, true); + try { + Schema::create( + 'group_journals', + static function (Blueprint $table) { + $table->increments('id'); + $table->integer('transaction_group_id', false, true); + $table->integer('transaction_journal_id', false, true); - $table->foreign('transaction_group_id')->references('id')->on('transaction_groups')->onDelete('cascade'); - $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); + $table->foreign('transaction_group_id')->references('id')->on('transaction_groups')->onDelete('cascade'); + $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); - // unique combi: - $table->unique(['transaction_group_id', 'transaction_journal_id'], 'unique_in_group'); - } - ); + // unique combi: + $table->unique(['transaction_group_id', 'transaction_journal_id'], 'unique_in_group'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "group_journals": %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.'); + } } } } diff --git a/database/migrations/2019_02_05_055516_changes_for_v4711.php b/database/migrations/2019_02_05_055516_changes_for_v4711.php index 430f23f0e9..5715ecd269 100644 --- a/database/migrations/2019_02_05_055516_changes_for_v4711.php +++ b/database/migrations/2019_02_05_055516_changes_for_v4711.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -59,18 +60,28 @@ class ChangesForV4711 extends Migration * datetime (without a time zone) for all database engines because MySQL refuses to play * nice. */ - Schema::table( - 'transaction_journals', - static function (Blueprint $table) { - $table->dateTime('date')->change(); - } - ); + try { + Schema::table( + 'transaction_journals', + static function (Blueprint $table) { + $table->dateTime('date')->change(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } - Schema::table( - 'preferences', - static function (Blueprint $table) { - $table->text('data')->nullable()->change(); - } - ); + try { + Schema::table( + 'preferences', + static function (Blueprint $table) { + $table->text('data')->nullable()->change(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2019_02_11_170529_changes_for_v4712.php b/database/migrations/2019_02_11_170529_changes_for_v4712.php index 09c3bb4910..0ebfe1c77c 100644 --- a/database/migrations/2019_02_11_170529_changes_for_v4712.php +++ b/database/migrations/2019_02_11_170529_changes_for_v4712.php @@ -22,6 +22,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -58,11 +59,16 @@ class ChangesForV4712 extends Migration * datetime (without a time zone) for all database engines because MySQL refuses to play * nice. */ - Schema::table( - 'transaction_journals', - static function (Blueprint $table) { - $table->dateTime('date')->change(); - } - ); + try { + Schema::table( + 'transaction_journals', + static function (Blueprint $table) { + $table->dateTime('date')->change(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2019_03_11_223700_fix_ldap_configuration.php b/database/migrations/2019_03_11_223700_fix_ldap_configuration.php index bbf7a89207..7eea9dd17a 100644 --- a/database/migrations/2019_03_11_223700_fix_ldap_configuration.php +++ b/database/migrations/2019_03_11_223700_fix_ldap_configuration.php @@ -21,7 +21,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -39,12 +41,17 @@ class FixLdapConfiguration extends Migration */ public function down(): void { - Schema::table( - 'users', - static function (Blueprint $table) { - $table->dropColumn(['objectguid']); - } - ); + try { + Schema::table( + 'users', + static function (Blueprint $table) { + $table->dropColumn(['objectguid']); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -59,11 +66,16 @@ class FixLdapConfiguration extends Migration * ADLdap2 appears to require the ability to store an objectguid for LDAP users * now. To support this, we add the column. */ - Schema::table( - 'users', - static function (Blueprint $table) { - $table->uuid('objectguid')->nullable()->after('id'); - } - ); + try { + Schema::table( + 'users', + static function (Blueprint $table) { + $table->uuid('objectguid')->nullable()->after('id'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2019_03_22_183214_changes_for_v480.php b/database/migrations/2019_03_22_183214_changes_for_v480.php index 825cfbecb6..6acb6ebb28 100644 --- a/database/migrations/2019_03_22_183214_changes_for_v480.php +++ b/database/migrations/2019_03_22_183214_changes_for_v480.php @@ -21,7 +21,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -38,30 +40,66 @@ class ChangesForV480 extends Migration */ public function down(): void { - Schema::table( - 'transaction_journals', - static function (Blueprint $table) { - // drop transaction_group_id + foreign key. - // cannot drop foreign keys in SQLite: - if ('sqlite' !== config('database.default')) { - $table->dropForeign('transaction_journals_transaction_group_id_foreign'); + try { + Schema::table( + 'transaction_journals', + static function (Blueprint $table) { + // 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 { + $table->dropColumn('transaction_group_id'); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not drop column: %s', $e->getMessage())); + Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.'); + } } - $table->dropColumn('transaction_group_id'); - } - ); - Schema::table( - 'rule_groups', - static function (Blueprint $table) { - $table->dropColumn('stop_processing'); - } - ); + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } - Schema::table( - 'users', - static function (Blueprint $table) { - $table->dropColumn('mfa_secret'); - } - ); + try { + Schema::table( + 'rule_groups', + static function (Blueprint $table) { + try { + $table->dropColumn('stop_processing'); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not drop column: %s', $e->getMessage())); + Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.'); + } + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } + + try { + Schema::table( + 'users', + static function (Blueprint $table) { + try { + $table->dropColumn('mfa_secret'); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not drop column: %s', $e->getMessage())); + Log::error('If the column does not exist, this is not an problem. Otherwise, please open a GitHub discussion.'); + } + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -72,30 +110,52 @@ class ChangesForV480 extends Migration */ public function up(): void { - Schema::table( - 'transaction_journals', - static function (Blueprint $table) { - $table->integer('transaction_currency_id', false, true)->nullable()->change(); + try { + Schema::table( + 'transaction_journals', + static function (Blueprint $table) { + $table->integer('transaction_currency_id', false, true)->nullable()->change(); - // add column "group_id" after "transaction_type_id" - $table->integer('transaction_group_id', false, true) - ->nullable()->default(null)->after('transaction_type_id'); + // add column "group_id" after "transaction_type_id" + $table->integer('transaction_group_id', false, true) + ->nullable()->default(null)->after('transaction_type_id'); - // add foreign key for "transaction_group_id" - $table->foreign('transaction_group_id')->references('id')->on('transaction_groups')->onDelete('cascade'); - } - ); - Schema::table( - 'rule_groups', - static function (Blueprint $table) { - $table->boolean('stop_processing')->default(false); - } - ); - Schema::table( - 'users', - static function (Blueprint $table) { - $table->string('mfa_secret', 50)->nullable(); - } - ); + // add foreign key for "transaction_group_id" + try { + $table->foreign('transaction_group_id')->references('id')->on('transaction_groups')->onDelete('cascade'); + } catch (QueryException $e) { + Log::error(sprintf('Could not create foreign index: %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 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( + 'rule_groups', + static function (Blueprint $table) { + $table->boolean('stop_processing')->default(false); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } + try { + Schema::table( + 'users', + static function (Blueprint $table) { + $table->string('mfa_secret', 50)->nullable(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2019_12_28_191351_make_locations_table.php b/database/migrations/2019_12_28_191351_make_locations_table.php index ff945896e7..10727d28ea 100644 --- a/database/migrations/2019_12_28_191351_make_locations_table.php +++ b/database/migrations/2019_12_28_191351_make_locations_table.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -38,7 +39,7 @@ class MakeLocationsTable extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('locations'); } @@ -48,22 +49,27 @@ class MakeLocationsTable extends Migration * * @return void */ - public function up() + public function up(): void { - Schema::create( - 'locations', - static function (Blueprint $table) { - $table->bigIncrements('id'); - $table->timestamps(); - $table->softDeletes(); + try { + Schema::create( + 'locations', + static function (Blueprint $table) { + $table->bigIncrements('id'); + $table->timestamps(); + $table->softDeletes(); - $table->integer('locatable_id', false, true); - $table->string('locatable_type', 255); + $table->integer('locatable_id', false, true); + $table->string('locatable_type', 255); - $table->decimal('latitude', 12, 8)->nullable(); - $table->decimal('longitude', 12, 8)->nullable(); - $table->smallInteger('zoom_level', false, true)->nullable(); - } - ); + $table->decimal('latitude', 12, 8)->nullable(); + $table->decimal('longitude', 12, 8)->nullable(); + $table->smallInteger('zoom_level', false, true)->nullable(); + } + ); + } catch (QueryException $e) { + 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.'); + } } } diff --git a/database/migrations/2020_03_13_201950_changes_for_v520.php b/database/migrations/2020_03_13_201950_changes_for_v520.php index cf864c4c12..90be1d4789 100644 --- a/database/migrations/2020_03_13_201950_changes_for_v520.php +++ b/database/migrations/2020_03_13_201950_changes_for_v520.php @@ -22,6 +22,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -50,40 +51,27 @@ class ChangesForV520 extends Migration public function up(): void { if (!Schema::hasTable('auto_budgets')) { - Schema::create( - 'auto_budgets', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('budget_id', false, true); - $table->integer('transaction_currency_id', false, true); - $table->tinyInteger('auto_budget_type', false, true)->default(1); - $table->decimal('amount', 32, 12); - $table->string('period', 50); + try { + Schema::create( + 'auto_budgets', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('budget_id', false, true); + $table->integer('transaction_currency_id', false, true); + $table->tinyInteger('auto_budget_type', false, true)->default(1); + $table->decimal('amount', 32, 12); + $table->string('period', 50); - $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade'); - $table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade'); - } - ); - } - - if (!Schema::hasTable('telemetry')) { - Schema::create( - 'telemetry', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->dateTime('submitted')->nullable(); - $table->integer('user_id', false, true)->nullable(); - $table->string('installation_id', 50); - $table->string('type', 25); - $table->string('key', 50); - $table->text('value'); - - $table->foreign('user_id')->references('id')->on('users')->onDelete('set null'); - } - ); + $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('cascade'); + $table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "auto_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.'); + } } } } diff --git a/database/migrations/2020_06_07_063612_changes_for_v530.php b/database/migrations/2020_06_07_063612_changes_for_v530.php index 0441731aa6..aaa97f39ef 100644 --- a/database/migrations/2020_06_07_063612_changes_for_v530.php +++ b/database/migrations/2020_06_07_063612_changes_for_v530.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; /** @@ -51,28 +52,39 @@ class ChangesForV530 extends Migration public function up(): void { if (!Schema::hasTable('object_groups')) { - Schema::create( - 'object_groups', - static function (Blueprint $table) { - $table->increments('id'); - $table->integer('user_id', false, true); - $table->timestamps(); - $table->softDeletes(); - $table->string('title', 255); - $table->mediumInteger('order', false, true)->default(0); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - } - ); + try { + Schema::create( + 'object_groups', + static function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id', false, true); + $table->timestamps(); + $table->softDeletes(); + $table->string('title', 255); + $table->mediumInteger('order', false, true)->default(0); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "object_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.'); + } } + if (!Schema::hasTable('object_groupables')) { - Schema::create( - 'object_groupables', - static function (Blueprint $table) { - $table->integer('object_group_id'); - $table->integer('object_groupable_id', false, true); - $table->string('object_groupable_type', 255); - } - ); + try { + Schema::create( + 'object_groupables', + static function (Blueprint $table) { + $table->integer('object_group_id'); + $table->integer('object_groupable_id', false, true); + $table->string('object_groupable_type', 255); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "object_groupables": %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.'); + } } } } diff --git a/database/migrations/2020_06_30_202620_changes_for_v530a.php b/database/migrations/2020_06_30_202620_changes_for_v530a.php index b54a7144cc..eee512a65c 100644 --- a/database/migrations/2020_06_30_202620_changes_for_v530a.php +++ b/database/migrations/2020_06_30_202620_changes_for_v530a.php @@ -22,7 +22,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -40,12 +42,17 @@ class ChangesForV530a extends Migration */ public function down(): void { - Schema::table( - 'bills', - static function (Blueprint $table) { - $table->dropColumn('order'); - } - ); + try { + Schema::table( + 'bills', + static function (Blueprint $table) { + $table->dropColumn('order'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -55,11 +62,16 @@ class ChangesForV530a extends Migration */ public function up(): void { - Schema::table( - 'bills', - static function (Blueprint $table) { - $table->integer('order', false, true)->default(0); - } - ); + try { + Schema::table( + 'bills', + static function (Blueprint $table) { + $table->integer('order', false, true)->default(0); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2020_07_24_162820_changes_for_v540.php b/database/migrations/2020_07_24_162820_changes_for_v540.php index 38401fba0a..8d3d78eb92 100644 --- a/database/migrations/2020_07_24_162820_changes_for_v540.php +++ b/database/migrations/2020_07_24_162820_changes_for_v540.php @@ -22,7 +22,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -40,27 +42,43 @@ class ChangesForV540 extends Migration */ public function down(): void { - Schema::table( - 'oauth_clients', - static function (Blueprint $table) { - $table->dropColumn('provider'); - } - ); + try { + Schema::table( + 'oauth_clients', + static function (Blueprint $table) { + $table->dropColumn('provider'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } - Schema::table( - 'accounts', - static function (Blueprint $table) { - $table->dropColumn('order'); - } - ); + try { + Schema::table( + 'accounts', + static function (Blueprint $table) { + $table->dropColumn('order'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } - Schema::table( - 'bills', - static function (Blueprint $table) { - $table->dropColumn('end_date'); - $table->dropColumn('extension_date'); - } - ); + try { + Schema::table( + 'bills', + static function (Blueprint $table) { + $table->dropColumn('end_date'); + + $table->dropColumn('extension_date'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -70,31 +88,51 @@ class ChangesForV540 extends Migration */ public function up(): void { - Schema::table( - 'accounts', - static function (Blueprint $table) { - $table->integer('order', false, true)->default(0); - } - ); - Schema::table( - 'oauth_clients', - static function (Blueprint $table) { - $table->string('provider')->nullable(); - } - ); - Schema::table( - 'bills', - static function (Blueprint $table) { - $table->date('end_date')->nullable()->after('date'); - $table->date('extension_date')->nullable()->after('end_date'); - } - ); + try { + Schema::table( + 'accounts', + static function (Blueprint $table) { + $table->integer('order', false, true)->default(0); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } + try { + Schema::table( + '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.'); + } + try { + Schema::table( + 'bills', + static function (Blueprint $table) { + $table->date('end_date')->nullable()->after('date'); + $table->date('extension_date')->nullable()->after('end_date'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // make column nullable: - Schema::table( - 'oauth_clients', - function (Blueprint $table) { - $table->string('secret', 100)->nullable()->change(); - } - ); + try { + Schema::table( + 'oauth_clients', + function (Blueprint $table) { + $table->string('secret', 100)->nullable()->change(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2020_11_12_070604_changes_for_v550.php b/database/migrations/2020_11_12_070604_changes_for_v550.php index 9c73f036a5..02e894715c 100644 --- a/database/migrations/2020_11_12_070604_changes_for_v550.php +++ b/database/migrations/2020_11_12_070604_changes_for_v550.php @@ -22,7 +22,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -36,46 +38,62 @@ class ChangesForV550 extends Migration * * @return void */ - public function down() + public function down(): void { // recreate jobs table. Schema::dropIfExists('jobs'); - Schema::create( - 'jobs', - static function (Blueprint $table) { - // straight from Laravel (this is the OLD table) - $table->bigIncrements('id'); - $table->string('queue'); - $table->longText('payload'); - $table->tinyInteger('attempts')->unsigned(); - $table->tinyInteger('reserved')->unsigned(); - $table->unsignedInteger('reserved_at')->nullable(); - $table->unsignedInteger('available_at'); - $table->unsignedInteger('created_at'); - $table->index(['queue', 'reserved', 'reserved_at']); - } - ); + + try { + Schema::create( + 'jobs', + static function (Blueprint $table) { + // straight from Laravel (this is the OLD table) + $table->bigIncrements('id'); + $table->string('queue'); + $table->longText('payload'); + $table->tinyInteger('attempts')->unsigned(); + $table->tinyInteger('reserved')->unsigned(); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_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())); + 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. - Schema::table( - 'budget_transaction_journal', - function (Blueprint $table) { - $table->dropForeign('budget_id_foreign'); - $table->dropColumn('budget_limit_id'); - } - ); + try { + Schema::table( + 'budget_transaction_journal', + function (Blueprint $table) { + $table->dropForeign('budget_id_foreign'); + $table->dropColumn('budget_limit_id'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // drop failed jobs table. Schema::dropIfExists('failed_jobs'); // drop fields from budget limits - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - $table->dropColumn('period'); - $table->dropColumn('generated'); - } - ); + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + $table->dropColumn('period'); + $table->dropColumn('generated'); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } Schema::dropIfExists('webhook_attempts'); Schema::dropIfExists('webhook_messages'); Schema::dropIfExists('webhooks'); @@ -86,123 +104,158 @@ class ChangesForV550 extends Migration * * @return void */ - public function up() + public function up(): void { // drop and recreate jobs table. Schema::dropIfExists('jobs'); // this is the NEW table - Schema::create( - 'jobs', - function (Blueprint $table) { - $table->bigIncrements('id'); - $table->string('queue')->index(); - $table->longText('payload'); - $table->unsignedTinyInteger('attempts'); - $table->unsignedInteger('reserved_at')->nullable(); - $table->unsignedInteger('available_at'); - $table->unsignedInteger('created_at'); - } - ); + try { + Schema::create( + 'jobs', + function (Blueprint $table) { + $table->bigIncrements('id'); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + } + ); + } catch (QueryException $e) { + 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. Schema::dropIfExists('failed_jobs'); // create new failed_jobs table. - Schema::create( - 'failed_jobs', - function (Blueprint $table) { - $table->bigIncrements('id'); - $table->string('uuid')->unique(); - $table->text('connection'); - $table->text('queue'); - $table->longText('payload'); - $table->longText('exception'); - $table->timestamp('failed_at')->useCurrent(); - } - ); + try { + Schema::create( + 'failed_jobs', + function (Blueprint $table) { + $table->bigIncrements('id'); + $table->string('uuid')->unique(); + $table->text('connection'); + $table->text('queue'); + $table->longText('payload'); + $table->longText('exception'); + $table->timestamp('failed_at')->useCurrent(); + } + ); + } catch (QueryException $e) { + 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. - Schema::table( - 'budget_transaction_journal', - function (Blueprint $table) { - if (!Schema::hasColumn('budget_transaction_journal', 'budget_limit_id')) { - $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'); + try { + Schema::table( + 'budget_transaction_journal', + function (Blueprint $table) { + if (!Schema::hasColumn('budget_transaction_journal', 'budget_limit_id')) { + $table->integer('budget_limit_id', false, true)->nullable()->default(null)->after('budget_id'); + $table->foreign('budget_limit_id', 'budget_id_foreign')->references('id')->on('budget_limits')->onDelete('set null'); + } } - } - ); + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // append budget limits table. // i swear I dropped & recreated this field 15 times already. - Schema::table( - 'budget_limits', - static function (Blueprint $table) { - if (!Schema::hasColumn('budget_limits', 'period')) { - $table->string('period', 12)->nullable(); + try { + Schema::table( + 'budget_limits', + static function (Blueprint $table) { + if (!Schema::hasColumn('budget_limits', 'period')) { + $table->string('period', 12)->nullable(); + } + if (!Schema::hasColumn('budget_limits', 'generated')) { + $table->boolean('generated')->default(false); + } } - if (!Schema::hasColumn('budget_limits', 'generated')) { - $table->boolean('generated')->default(false); - } - } - ); + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // new webhooks table if (!Schema::hasTable('webhooks')) { - Schema::create( - 'webhooks', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('user_id', false, true); - $table->string('title', 255)->index(); - $table->string('secret', 32)->index(); - $table->boolean('active')->default(true); - $table->unsignedSmallInteger('trigger', false); - $table->unsignedSmallInteger('response', false); - $table->unsignedSmallInteger('delivery', false); - $table->string('url', 1024); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - $table->unique(['user_id', 'title']); - } - ); + try { + Schema::create( + 'webhooks', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('user_id', false, true); + $table->string('title', 255)->index(); + $table->string('secret', 32)->index(); + $table->boolean('active')->default(true); + $table->unsignedSmallInteger('trigger', false); + $table->unsignedSmallInteger('response', false); + $table->unsignedSmallInteger('delivery', false); + $table->string('url', 1024); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->unique(['user_id', 'title']); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "webhooks": %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.'); + } } // new webhook_messages table if (!Schema::hasTable('webhook_messages')) { - Schema::create( - 'webhook_messages', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->boolean('sent')->default(false); - $table->boolean('errored')->default(false); + try { + Schema::create( + 'webhook_messages', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->boolean('sent')->default(false); + $table->boolean('errored')->default(false); - $table->integer('webhook_id', false, true); - $table->string('uuid', 64); - $table->longText('message'); + $table->integer('webhook_id', false, true); + $table->string('uuid', 64); + $table->longText('message'); - $table->foreign('webhook_id')->references('id')->on('webhooks')->onDelete('cascade'); - } - ); + $table->foreign('webhook_id')->references('id')->on('webhooks')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "webhook_messages": %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.'); + } } if (!Schema::hasTable('webhook_attempts')) { - Schema::create( - 'webhook_attempts', - static function (Blueprint $table) { - $table->increments('id'); - $table->timestamps(); - $table->softDeletes(); - $table->integer('webhook_message_id', false, true); - $table->unsignedSmallInteger('status_code')->default(0); + try { + Schema::create( + 'webhook_attempts', + static function (Blueprint $table) { + $table->increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('webhook_message_id', false, true); + $table->unsignedSmallInteger('status_code')->default(0); - $table->longText('logs')->nullable(); - $table->longText('response')->nullable(); + $table->longText('logs')->nullable(); + $table->longText('response')->nullable(); - $table->foreign('webhook_message_id')->references('id')->on('webhook_messages')->onDelete('cascade'); - } - ); + $table->foreign('webhook_message_id')->references('id')->on('webhook_messages')->onDelete('cascade'); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "webhook_attempts": %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.'); + } } } } diff --git a/database/migrations/2021_03_12_061213_changes_for_v550b2.php b/database/migrations/2021_03_12_061213_changes_for_v550b2.php index 4b3a97a1b2..94a08bc4fb 100644 --- a/database/migrations/2021_03_12_061213_changes_for_v550b2.php +++ b/database/migrations/2021_03_12_061213_changes_for_v550b2.php @@ -22,7 +22,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -38,15 +40,20 @@ class ChangesForV550b2 extends Migration */ public function down(): void { - Schema::table( - 'recurrences_transactions', - function (Blueprint $table) { - $table->dropForeign('type_foreign'); - if (Schema::hasColumn('recurrences_transactions', 'transaction_type_id')) { - $table->dropColumn('transaction_type_id'); + try { + Schema::table( + 'recurrences_transactions', + function (Blueprint $table) { + $table->dropForeign('type_foreign'); + if (Schema::hasColumn('recurrences_transactions', 'transaction_type_id')) { + $table->dropColumn('transaction_type_id'); + } } - } - ); + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** @@ -57,14 +64,19 @@ class ChangesForV550b2 extends Migration public function up(): void { // expand recurrence transaction table - Schema::table( - 'recurrences_transactions', - function (Blueprint $table) { - if (!Schema::hasColumn('recurrences_transactions', 'transaction_type_id')) { - $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'); + try { + Schema::table( + 'recurrences_transactions', + function (Blueprint $table) { + if (!Schema::hasColumn('recurrences_transactions', 'transaction_type_id')) { + $table->integer('transaction_type_id', false, true)->nullable()->after('transaction_currency_id'); + $table->foreign('transaction_type_id', 'type_foreign')->references('id')->on('transaction_types')->onDelete('set null'); + } } - } - ); + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2021_05_09_064644_add_ldap_columns_to_users_table.php b/database/migrations/2021_05_09_064644_add_ldap_columns_to_users_table.php index 5a0ad59217..763b51ca5b 100644 --- a/database/migrations/2021_05_09_064644_add_ldap_columns_to_users_table.php +++ b/database/migrations/2021_05_09_064644_add_ldap_columns_to_users_table.php @@ -22,7 +22,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -31,26 +33,36 @@ class AddLdapColumnsToUsersTable extends Migration /** * Reverse the migrations. */ - public function down() + public function down(): void { - Schema::table( - 'users', - function (Blueprint $table) { - $table->dropColumn(['domain']); - } - ); + try { + Schema::table( + 'users', + function (Blueprint $table) { + $table->dropColumn(['domain']); + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } /** * Run the migrations. */ - public function up() + public function up(): void { - Schema::table( - 'users', - function (Blueprint $table) { - $table->string('domain')->nullable(); - } - ); + try { + Schema::table( + 'users', + function (Blueprint $table) { + $table->string('domain')->nullable(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2021_05_13_053836_extend_currency_info.php b/database/migrations/2021_05_13_053836_extend_currency_info.php index cc572ac058..b2982f6154 100644 --- a/database/migrations/2021_05_13_053836_extend_currency_info.php +++ b/database/migrations/2021_05_13_053836_extend_currency_info.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -36,7 +37,7 @@ class ExtendCurrencyInfo extends Migration * * @return void */ - public function down() + public function down(): void { // } @@ -46,14 +47,19 @@ class ExtendCurrencyInfo extends Migration * * @return void */ - public function up() + public function up(): void { - Schema::table( - 'transaction_currencies', - function (Blueprint $table) { - $table->string('code', 51)->change(); - $table->string('symbol', 51)->change(); - } - ); + try { + Schema::table( + 'transaction_currencies', + function (Blueprint $table) { + $table->string('code', 51)->change(); + $table->string('symbol', 51)->change(); + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } diff --git a/database/migrations/2021_07_05_193044_drop_tele_table.php b/database/migrations/2021_07_05_193044_drop_tele_table.php index 2d5f7e8823..31016bdff2 100644 --- a/database/migrations/2021_07_05_193044_drop_tele_table.php +++ b/database/migrations/2021_07_05_193044_drop_tele_table.php @@ -35,7 +35,7 @@ class DropTeleTable extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('telemetry'); } @@ -45,7 +45,7 @@ class DropTeleTable extends Migration * * @return void */ - public function up() + public function up(): void { Schema::dropIfExists('telemetry'); } diff --git a/database/migrations/2021_08_28_073733_user_groups.php b/database/migrations/2021_08_28_073733_user_groups.php index fcc2f8242f..ca3b597aa7 100644 --- a/database/migrations/2021_08_28_073733_user_groups.php +++ b/database/migrations/2021_08_28_073733_user_groups.php @@ -22,7 +22,9 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -53,32 +55,42 @@ class UserGroups extends Migration * * @return void */ - public function down() + public function down(): void { // remove columns from tables /** @var string $tableName */ foreach ($this->tables as $tableName) { + try { + Schema::table( + $tableName, + function (Blueprint $table) use ($tableName) { + $table->dropForeign(sprintf('%s_to_ugi', $tableName)); + if (Schema::hasColumn($tableName, 'user_group_id')) { + $table->dropColumn('user_group_id'); + } + } + ); + } catch (QueryException|ColumnDoesNotExist $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } + } + + try { Schema::table( - $tableName, - function (Blueprint $table) use ($tableName) { - $table->dropForeign(sprintf('%s_to_ugi', $tableName)); - if (Schema::hasColumn($tableName, 'user_group_id')) { + '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::table( - 'users', - function (Blueprint $table) { - $table->dropForeign('type_user_group_id'); - if (Schema::hasColumn('users', 'user_group_id')) { - $table->dropColumn('user_group_id'); - } - } - ); - Schema::dropIfExists('group_memberships'); Schema::dropIfExists('user_roles'); Schema::dropIfExists('user_groups'); @@ -89,76 +101,100 @@ class UserGroups extends Migration * * @return void */ - public function up() + public function up(): void { /* * user is a member of a user_group through a user_group_role * may have multiple roles in a group */ - Schema::create( - 'user_groups', - static function (Blueprint $table) { - $table->bigIncrements('id'); - $table->timestamps(); - $table->softDeletes(); + try { + Schema::create( + 'user_groups', + static function (Blueprint $table) { + $table->bigIncrements('id'); + $table->timestamps(); + $table->softDeletes(); - $table->string('title', 255); - $table->unique('title'); - } - ); - - Schema::create( - 'user_roles', - static function (Blueprint $table) { - $table->bigIncrements('id'); - $table->timestamps(); - $table->softDeletes(); - - $table->string('title', 255); - $table->unique('title'); - } - ); - - 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); - - $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']); - } - ); - Schema::table( - 'users', - function (Blueprint $table) { - if (!Schema::hasColumn('users', 'user_group_id')) { - $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->string('title', 255); + $table->unique('title'); } - } - ); + ); + } catch (QueryException $e) { + 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.'); + } + try { + Schema::create( + 'user_roles', + static function (Blueprint $table) { + $table->bigIncrements('id'); + $table->timestamps(); + $table->softDeletes(); + + $table->string('title', 255); + $table->unique('title'); + } + ); + } catch (QueryException $e) { + 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.'); + } + + 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); + + $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 { + Schema::table( + 'users', + function (Blueprint $table) { + if (!Schema::hasColumn('users', 'user_group_id')) { + $table->bigInteger('user_group_id', false, true)->nullable(); + $table->foreign('user_group_id', 'type_user_group_id')->references('id')->on('user_groups')->onDelete('set null')->onUpdate('cascade'); + } + } + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } // ADD columns from tables /** @var string $tableName */ foreach ($this->tables as $tableName) { - Schema::table( - $tableName, - function (Blueprint $table) use ($tableName) { - if (!Schema::hasColumn($tableName, 'user_group_id')) { - $table->bigInteger('user_group_id', false, true)->nullable()->after('user_id'); - $table->foreign('user_group_id', sprintf('%s_to_ugi', $tableName))->references('id')->on('user_groups')->onDelete('set null')->onUpdate( - 'cascade' - ); + try { + Schema::table( + $tableName, + function (Blueprint $table) use ($tableName) { + if (!Schema::hasColumn($tableName, 'user_group_id')) { + $table->bigInteger('user_group_id', false, true)->nullable()->after('user_id'); + $table->foreign('user_group_id', sprintf('%s_to_ugi', $tableName))->references('id')->on('user_groups')->onDelete( + 'set null' + )->onUpdate('cascade'); + } } - } - ); + ); + } catch (QueryException $e) { + Log::error(sprintf('Could not execute query: %s', $e->getMessage())); + Log::error('If the column or index already exists (see error), this is not an problem. Otherwise, please open a GitHub discussion.'); + } } } } diff --git a/database/migrations/2021_12_27_000001_create_local_personal_access_tokens_table.php b/database/migrations/2021_12_27_000001_create_local_personal_access_tokens_table.php index 76c4519124..dcfd29b2e9 100644 --- a/database/migrations/2021_12_27_000001_create_local_personal_access_tokens_table.php +++ b/database/migrations/2021_12_27_000001_create_local_personal_access_tokens_table.php @@ -23,6 +23,7 @@ declare(strict_types=1); use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -36,7 +37,7 @@ class CreateLocalPersonalAccessTokensTable extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('personal_access_tokens'); } @@ -46,18 +47,23 @@ class CreateLocalPersonalAccessTokensTable extends Migration * * @return void */ - public function up() + public function up(): void { if (!Schema::hasTable('personal_access_tokens')) { - Schema::create('personal_access_tokens', function (Blueprint $table) { - $table->bigIncrements('id'); - $table->morphs('tokenable'); - $table->string('name'); - $table->string('token', 64)->unique(); - $table->text('abilities')->nullable(); - $table->timestamp('last_used_at')->nullable(); - $table->timestamps(); - }); + try { + Schema::create('personal_access_tokens', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->morphs('tokenable'); + $table->string('name'); + $table->string('token', 64)->unique(); + $table->text('abilities')->nullable(); + $table->timestamp('last_used_at')->nullable(); + $table->timestamps(); + }); + } catch (QueryException $e) { + Log::error(sprintf('Could not create table "personal_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.'); + } } } } diff --git a/database/migrations/2022_08_21_104626_add_user_groups.php b/database/migrations/2022_08_21_104626_add_user_groups.php index e21fc3b484..30454d1b20 100644 --- a/database/migrations/2022_08_21_104626_add_user_groups.php +++ b/database/migrations/2022_08_21_104626_add_user_groups.php @@ -22,6 +22,7 @@ declare(strict_types=1); +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\QueryException; use Illuminate\Database\Schema\Blueprint; @@ -31,7 +32,7 @@ use Illuminate\Support\Facades\Schema; /** * */ -return new class() extends Migration { +return new class () extends Migration { /** * Run the migrations. * @@ -39,23 +40,20 @@ return new class() extends Migration { */ public function up(): void { - Schema::table( - 'currency_exchange_rates', - function (Blueprint $table) { - if (!Schema::hasColumn('currency_exchange_rates', 'user_group_id')) { - try { + try { + Schema::table( + 'currency_exchange_rates', + function (Blueprint $table) { + if (!Schema::hasColumn('currency_exchange_rates', 'user_group_id')) { $table->bigInteger('user_group_id', false, true)->nullable()->after('user_id'); - } catch (QueryException $e) { - Log::error(sprintf('Could not add column "user_group_id" to table "currency_exchange_rates": %s', $e->getMessage())); - } - try { $table->foreign('user_group_id', 'cer_to_ugi')->references('id')->on('user_groups')->onDelete('set null')->onUpdate('cascade'); - } catch (QueryException $e) { - Log::error(sprintf('Could not add foreign key "cer_to_ugi" to table "currency_exchange_rates": %s', $e->getMessage())); } } - } - ); + ); + } 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.'); + } } /** @@ -65,22 +63,19 @@ return new class() extends Migration { */ public function down(): void { - Schema::table( - 'currency_exchange_rates', - function (Blueprint $table) { - try { + try { + Schema::table( + 'currency_exchange_rates', + function (Blueprint $table) { $table->dropForeign('cer_to_ugi'); - } catch (QueryException $e) { - Log::error(sprintf('Could not drop foreign key "cer_to_ugi" from table "currency_exchange_rates": %s', $e->getMessage())); - } - if (Schema::hasColumn('currency_exchange_rates', 'user_group_id')) { - try { + if (Schema::hasColumn('currency_exchange_rates', 'user_group_id')) { $table->dropColumn('user_group_id'); - } catch (QueryException $e) { - Log::error(sprintf('Could not drop column "user_group_id" from table "currency_exchange_rates": %s', $e->getMessage())); } } - } - ); + ); + } 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.'); + } } }; diff --git a/database/migrations/2022_09_18_123911_create_notifications_table.php b/database/migrations/2022_09_18_123911_create_notifications_table.php index e2781adaca..aca0789a0a 100644 --- a/database/migrations/2022_09_18_123911_create_notifications_table.php +++ b/database/migrations/2022_09_18_123911_create_notifications_table.php @@ -28,13 +28,13 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class () extends Migration { /** * Run the migrations. * * @return void */ - public function up() + public function up(): void { try { Schema::create('notifications', function (Blueprint $table) { @@ -47,6 +47,7 @@ return new class() extends Migration { }); } catch (QueryException $e) { 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.'); } } @@ -55,7 +56,7 @@ return new class() extends Migration { * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('notifications'); } diff --git a/database/migrations/2022_10_01_074908_invited_users.php b/database/migrations/2022_10_01_074908_invited_users.php index 3f1880741a..777a927ec2 100644 --- a/database/migrations/2022_10_01_074908_invited_users.php +++ b/database/migrations/2022_10_01_074908_invited_users.php @@ -28,7 +28,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class () extends Migration { /** * Run the migrations. * @@ -49,6 +49,7 @@ return new class() extends Migration { }); } catch (QueryException $e) { 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.'); } } diff --git a/database/migrations/2022_10_01_210238_audit_log_entries.php b/database/migrations/2022_10_01_210238_audit_log_entries.php index 6cd4ad159f..296e283a20 100644 --- a/database/migrations/2022_10_01_210238_audit_log_entries.php +++ b/database/migrations/2022_10_01_210238_audit_log_entries.php @@ -28,13 +28,13 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class () extends Migration { /** * Run the migrations. * * @return void */ - public function up() + public function up(): void { try { Schema::create('audit_log_entries', function (Blueprint $table) { @@ -54,6 +54,7 @@ return new class() extends Migration { }); } catch (QueryException $e) { 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.'); } } @@ -62,7 +63,7 @@ return new class() extends Migration { * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('audit_log_entries'); }