generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from envor/main
Libstream Migrate
- Loading branch information
Showing
5 changed files
with
80 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Envor\Libstream\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Database\DatabaseManager; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class LibstreamMigrateCommand extends Command | ||
{ | ||
public $signature = 'libstream:migrate {--force : Run the command without asking for confirmation} {--fresh : Drop all libstream tables and re-run migrations} {--database= : The database connection to use}'; | ||
|
||
public $description = 'Run the libstream migrations'; | ||
|
||
public function handle(): int | ||
{ | ||
if ($this->option('database')) { | ||
app(DatabaseManager::class)->usingConnection($this->option('database'), fn () => $this->body()); | ||
|
||
return self::SUCCESS; | ||
} | ||
|
||
$this->body(); | ||
|
||
return self::SUCCESS; | ||
} | ||
|
||
private function body() | ||
{ | ||
if ($this->option('fresh')) { | ||
foreach (config('libstream.migration_tables') as $table) { | ||
Schema::dropIfExists($table); | ||
} | ||
|
||
// delete the migrations from the migrations repository | ||
$files = glob(__DIR__.'/../../database/migrations/*'); | ||
|
||
foreach ($files as $file) { | ||
// get the migration file name without extension | ||
$fileName = pathinfo($file, PATHINFO_FILENAME); | ||
//get full realpath to file | ||
$realpath = realpath($file); | ||
// delete the migration from the migrations repository | ||
$options = ['--path' => $realpath, '--realpath' => true]; | ||
if ($this->option('force')) { | ||
$options['--force'] = true; | ||
} | ||
$this->call('migrate:reset', $options, $this->output); | ||
Check failure on line 48 in src/Commands/LibstreamMigrateCommand.php
|
||
} | ||
|
||
return; | ||
} | ||
|
||
// run the migrations | ||
$options = ['--path' => __DIR__.'/../../database/migrations']; | ||
if ($this->option('force')) { | ||
$options['--force'] = true; | ||
} | ||
$this->call('migrate', $options, $this->output); | ||
Check failure on line 59 in src/Commands/LibstreamMigrateCommand.php
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters