Skip to content

Commit 642d86d

Browse files
committed
closes #10 and #19
1 parent a113c0d commit 642d86d

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
}
2222
],
2323
"require": {
24-
"php": "^7.3|^8.0",
25-
"illuminate/support": "~5.5.0 || ~5.6.0 || ~5.7.0 || ~5.8.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
24+
"php": "^8.1",
25+
"illuminate/support": "^9.0 || ^10.0 || ^11.0",
2626
"spatie/regex": "^3.1.1",
2727
"doctrine/dbal": "^3.4"
2828
},

src/SyncMigrateCommand.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class SyncMigrateCommand extends BaseCommand
2323
*
2424
* @var string
2525
*/
26-
protected $signature = 'migrate:sync';
26+
protected $signature = 'migrate:sync {file?}';
2727
/**
2828
* The console command description.
2929
*
@@ -53,17 +53,44 @@ public function __construct(Migrator $migrator)
5353
*/
5454
public function handle()
5555
{
56-
$files = $this->migrator->getMigrationFiles($this->getMigrationPaths());
5756

58-
foreach ($files as $file) {
57+
//if file option is given.
58+
$file = $this->argument('file');
59+
if (!empty($file)) {
60+
$file = rtrim($file, '.php') . '.php';
61+
$fileExists = true;
62+
if (!file_exists($file)) {
63+
$fileExists = false;
64+
foreach ($this->getMigrationPaths() as $path) {
65+
if (file_exists($path . '/' . $file)) {
66+
$file = $path . '/' . $file;
67+
$fileExists = true;
68+
break;
69+
}
70+
}
71+
}
72+
73+
if (!$fileExists) {
74+
$this->error("File not found: $file");
75+
return;
76+
}
77+
5978
$this->processMigration(file_get_contents($file));
79+
} else {
80+
$files = $this->migrator->getMigrationFiles($this->getMigrationPaths());
81+
82+
foreach ($files as $file) {
83+
$this->processMigration(file_get_contents($file));
84+
}
6085
}
6186

6287
$this->abondedTables()->each(function ($table) {
6388
$this->error("Schemas doesn't have table <fg=black;bg=white> {$table} </> seems you have delete it");
6489

65-
$this->confirm("Do you want to drop <fg=black;bg=white> {$table} </> ?",
66-
true) && LaravelSchema::dropIfExists($table);
90+
$this->confirm(
91+
"Do you want to drop <fg=black;bg=white> {$table} </> ?",
92+
true
93+
) && LaravelSchema::dropIfExists($table);
6794
})->isEmpty() && $this->syncedOrNot();
6895

6996
}
@@ -76,7 +103,7 @@ protected function syncedOrNot()
76103
protected function tables()
77104
{
78105
return Collection::make(DB::select('SHOW TABLES'))->map(function ($table) {
79-
return array_values((array)$table);
106+
return array_values((array) $table);
80107
})->flatten();
81108
}
82109

0 commit comments

Comments
 (0)