Skip to content

Commit 2d9bfc2

Browse files
committed
Refactor migration file name date generation
1 parent efc6903 commit 2d9bfc2

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

src/MigrateGenerateCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,19 +398,24 @@ protected function generate(Collection $tables, Collection $views): void
398398
*/
399399
protected function generateMigrations(Collection $tables, Collection $views): void
400400
{
401+
$setting = app(Setting::class);
402+
401403
$this->info('Setting up Tables and Index migrations.');
402404
$this->generateTables($tables);
403405

404406
if (!$this->option('skip-views')) {
407+
$setting->getDate()->addSecond();
405408
$this->info("\nSetting up Views migrations.");
406409
$this->generateViews($views);
407410
}
408411

409412
if (!$this->option('skip-proc')) {
413+
$setting->getDate()->addSecond();
410414
$this->info("\nSetting up Stored Procedures migrations.");
411415
$this->generateProcedures();
412416
}
413417

418+
$setting->getDate()->addSecond();
414419
$this->info("\nSetting up Foreign Key migrations.");
415420
$this->generateForeignKeys($tables);
416421
}

src/Migration/ForeignKeyMigration.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace KitLoong\MigrationsGenerator\Migration;
44

5-
use Carbon\Carbon;
65
use Illuminate\Support\Collection;
76
use KitLoong\MigrationsGenerator\Enum\Migrations\Method\SchemaBuilder;
87
use KitLoong\MigrationsGenerator\Migration\Blueprint\SchemaBlueprint;
@@ -147,7 +146,7 @@ private function makeMigrationPath(string $table): string
147146
$withoutPrefix = $this->stripTablePrefix($table);
148147
return $this->migrationNameHelper->makeFilename(
149148
$this->setting->getFkFilename(),
150-
Carbon::parse($this->setting->getDate())->addSecond()->format('Y_m_d_His'),
149+
$this->setting->getDateForMigrationFilename(),
151150
$withoutPrefix
152151
);
153152
}

src/Migration/ProcedureMigration.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace KitLoong\MigrationsGenerator\Migration;
44

5-
use Carbon\Carbon;
65
use Illuminate\Support\Collection;
76
use KitLoong\MigrationsGenerator\Migration\Blueprint\DBUnpreparedBlueprint;
87
use KitLoong\MigrationsGenerator\Migration\Enum\MigrationFileType;
@@ -112,7 +111,7 @@ private function makeMigrationPath(string $procedure): string
112111
{
113112
return $this->migrationNameHelper->makeFilename(
114113
$this->setting->getProcedureFilename(),
115-
Carbon::parse($this->setting->getDate())->addSecond()->format('Y_m_d_His'),
114+
$this->setting->getDateForMigrationFilename(),
116115
$procedure
117116
);
118117
}

src/Migration/Squash.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function squashMigrations(): string
3838
{
3939
$path = $this->migrationNameHelper->makeFilename(
4040
$this->setting->getTableFilename(),
41-
$this->setting->getDate()->format('Y_m_d_His'),
41+
$this->setting->getDateForMigrationFilename(),
4242
DB::getDatabaseName()
4343
);
4444

src/Migration/TableMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private function makeMigrationPath(string $table): string
205205
$withoutPrefix = $this->stripTablePrefix($table);
206206
return $this->migrationNameHelper->makeFilename(
207207
$this->setting->getTableFilename(),
208-
$this->setting->getDate()->format('Y_m_d_His'),
208+
$this->setting->getDateForMigrationFilename(),
209209
$withoutPrefix
210210
);
211211
}

src/Migration/ViewMigration.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace KitLoong\MigrationsGenerator\Migration;
44

5-
use Carbon\Carbon;
65
use Illuminate\Support\Collection;
76
use KitLoong\MigrationsGenerator\Migration\Blueprint\DBStatementBlueprint;
87
use KitLoong\MigrationsGenerator\Migration\Enum\MigrationFileType;
@@ -118,7 +117,7 @@ private function makeMigrationPath(string $view): string
118117
$withoutPrefix = $this->stripTablePrefix($view);
119118
return $this->migrationNameHelper->makeFilename(
120119
$this->setting->getViewFilename(),
121-
Carbon::parse($this->setting->getDate())->addSecond()->format('Y_m_d_His'),
120+
$this->setting->getDateForMigrationFilename(),
122121
$withoutPrefix
123122
);
124123
}

src/Setting.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ public function getDate(): Carbon
234234
return $this->date;
235235
}
236236

237+
/**
238+
* @return string
239+
*/
240+
public function getDateForMigrationFilename(): string
241+
{
242+
return $this->date->format('Y_m_d_His');
243+
}
244+
237245
/**
238246
* @param \Carbon\Carbon $date
239247
*/

0 commit comments

Comments
 (0)