-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDatabaseResetCommand.php
More file actions
51 lines (38 loc) · 1.66 KB
/
DatabaseResetCommand.php
File metadata and controls
51 lines (38 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Leaf\Commands;
use Leaf\Sprout\Command;
class DatabaseResetCommand extends Command
{
protected $signature = 'db:reset
{file? : The name of the schema file to reset}
{--seed|s? : Seed the database after migration}';
public $description = 'Reset migration history + db tables';
public $help = 'Clear all database tables, and migrate afresh. Add --seed to seed db';
protected function handle()
{
$fileToMigrate = $this->argument('file');
$migrations = function_exists('AppPaths') ?
glob(getcwd() . DIRECTORY_SEPARATOR . AppPaths('database') . DIRECTORY_SEPARATOR . '*.yml') :
glob(getcwd() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . '*.yml');
foreach ($migrations as $migration) {
$currentFileName = path($migration)->basename();
if ($fileToMigrate && preg_replace('/\.yml$/', '', $currentFileName) !== preg_replace('/\.yml$/', '', $fileToMigrate)) {
continue;
}
$this->writeln("> db reset on <comment>$currentFileName</comment>");
if (!\Leaf\Schema::reset($migration)) {
$this->error("Could not reset $currentFileName");
return 1;
}
if ($this->option('seed')) {
if (!\Leaf\Schema::seed($migration)) {
$this->error("Could not seed $currentFileName");
return 1;
}
$this->writeln("> $currentFileName seeded successfully!");
}
}
$this->info("Database reset completed!\n");
return 0;
}
}