File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,9 @@ public function up(): void
2222 {
2323 if ($ this ->hasTable ()) {
2424 Schema::table ($ this ->table (), function (Blueprint $ table ) {
25- $ table ->renameColumn ('migration ' , 'action ' );
25+ if ($ this ->hasColumn ('migration ' ) && $ this ->doesntHaveColumn ('action ' )) {
26+ $ table ->renameColumn ('migration ' , 'action ' );
27+ }
2628
2729 $ table ->unsignedInteger ('batch ' )->change ();
2830 });
@@ -45,6 +47,16 @@ protected function hasTable(): bool
4547 return Schema::hasTable ($ this ->table ());
4648 }
4749
50+ protected function hasColumn (string $ column ): bool
51+ {
52+ return Schema::hasColumn ($ this ->table (), $ column );
53+ }
54+
55+ protected function doesntHaveColumn (string $ column ): bool
56+ {
57+ return ! $ this ->hasColumn ($ column );
58+ }
59+
4860 protected function table (): string
4961 {
5062 return $ this ->config ->table ();
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests \Migrations ;
6+
7+ use DragonCode \LaravelActions \Constants \Names ;
8+ use Illuminate \Support \Facades \DB ;
9+ use Illuminate \Support \Facades \Schema ;
10+ use Tests \TestCase ;
11+
12+ class MigrationTest extends TestCase
13+ {
14+ public function testRunMigrationAfterInstall (): void
15+ {
16+ DB ::table ('migrations ' )->truncate ();
17+
18+ Schema::connection ($ this ->database )->dropIfExists ($ this ->table );
19+
20+ $ this ->assertDatabaseCount ('migrations ' , 0 );
21+ $ this ->assertDatabaseDoesntTable ($ this ->table );
22+
23+ $ this ->artisan (Names::INSTALL )->run ();
24+
25+ $ this ->assertDatabaseCount ('migrations ' , 0 );
26+ $ this ->assertDatabaseHasTable ($ this ->table );
27+
28+ $ this ->artisan ('migrate ' )->run ();
29+
30+ $ this ->assertDatabaseCount ('migrations ' , 1 );
31+ $ this ->assertDatabaseHas ('migrations ' , ['migration ' => '2022_08_18_180137_change_migration_actions_table ' ]);
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments