1 | <?php |
||
13 | class MigrateFresh extends Command |
||
14 | { |
||
15 | use ConfirmableTrait; |
||
16 | |||
17 | /** |
||
18 | * The console command name. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $signature = 'migrate:fresh {--database= : The database connection to use.} |
||
23 | {--force : Force the operation to run when in production.} |
||
24 | {--path= : The path of migrations files to be executed.} |
||
25 | {--seed : Indicates if the seed task should be re-run.}'; |
||
26 | |||
27 | /** |
||
28 | * The console command description. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $description = 'Drop all database tables and re-run all migrations'; |
||
33 | |||
34 | /** |
||
35 | * Execute the console command. |
||
36 | * |
||
37 | * @return mixed |
||
38 | */ |
||
39 | public function handle() |
||
40 | { |
||
41 | $database = $this->input->getOption('database'); |
||
42 | |||
43 | $path = $this->input->getOption('path'); |
||
44 | |||
45 | if (! $this->confirmToProceed()) { |
||
46 | return; |
||
47 | } |
||
48 | |||
49 | $this->info('Dropping all tables...'); |
||
50 | |||
51 | event(new DroppingTables()); |
||
52 | if ($database !== null) { |
||
53 | DB::setDefaultConnection($database); |
||
54 | } |
||
55 | $this->getTableDropper()->dropAllTables(); |
||
56 | event(new DroppedTables()); |
||
57 | |||
58 | $this->info('Running migrations...'); |
||
59 | $this->call('migrate', [ |
||
60 | '--database' => $database, |
||
61 | '--path' => $path, |
||
62 | '--force' => true, |
||
63 | ]); |
||
64 | |||
65 | if ($this->option('seed')) { |
||
66 | $this->info('Running seeders...'); |
||
67 | $this->call('db:seed', ['--force' => true]); |
||
68 | } |
||
69 | |||
70 | $this->comment('All done!'); |
||
71 | } |
||
72 | |||
73 | public function getTableDropper(): TableDropper |
||
77 | } |
||
78 |