mirror of
https://github.com/ZorgCC/lumen-generators.git
synced 2024-12-27 06:25:28 +03:00
Merge pull request #50 from davidporos92/hotfix/migration-generator
Delete old migration file if exists when creating a new one
This commit is contained in:
commit
8d804e09eb
@ -21,6 +21,7 @@ class MigrationCommand extends BaseCommand {
|
|||||||
{
|
{
|
||||||
$table = $this->argument('table');
|
$table = $this->argument('table');
|
||||||
$name = 'Create' . ucwords(camel_case($table));
|
$name = 'Create' . ucwords(camel_case($table));
|
||||||
|
$snakeName = snake_case($name);
|
||||||
|
|
||||||
$content = $this->getTemplate('migration')
|
$content = $this->getTemplate('migration')
|
||||||
->with([
|
->with([
|
||||||
@ -34,12 +35,26 @@ class MigrationCommand extends BaseCommand {
|
|||||||
|
|
||||||
$file = $this->option('file');
|
$file = $this->option('file');
|
||||||
if(! $file){
|
if(! $file){
|
||||||
$file = date('Y_m_d_His_') . snake_case($name) . '_table';
|
$file = date('Y_m_d_His_') . $snakeName . '_table';
|
||||||
|
$this->deleteOldMigration($snakeName);
|
||||||
|
}else{
|
||||||
|
$this->deleteOldMigration($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->save($content, "./database/migrations/{$file}.php", "{$table} migration");
|
$this->save($content, "./database/migrations/{$file}.php", "{$table} migration");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function deleteOldMigration($fileName)
|
||||||
|
{
|
||||||
|
foreach (new \DirectoryIterator("./database/migrations/") as $fileInfo){
|
||||||
|
if($fileInfo->isDot()) continue;
|
||||||
|
|
||||||
|
if(strpos($fileInfo->getFilename(), $fileName) !== FALSE){
|
||||||
|
unlink($fileInfo->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function getSchema()
|
protected function getSchema()
|
||||||
{
|
{
|
||||||
$schema = $this->option('schema');
|
$schema = $this->option('schema');
|
||||||
|
Loading…
Reference in New Issue
Block a user