From 561359b14fb03c998d3aee4f259ae12b76b1b7d6 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 7 Apr 2023 20:54:15 +0200 Subject: [PATCH] Add command to force migrations. --- app/Console/Commands/ForceMigration.php | 72 +++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 app/Console/Commands/ForceMigration.php 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(''); + } +}