File tree Expand file tree Collapse file tree 2 files changed +53
-1
lines changed Expand file tree Collapse file tree 2 files changed +53
-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 Doctrine \DBAL \Driver \PDOSqlite \Driver ;
8+ use DragonCode \LaravelActions \Constants \Names ;
9+ use Illuminate \Support \Facades \DB ;
10+ use Illuminate \Support \Facades \Schema ;
11+ use Tests \TestCase ;
12+
13+ class MigrationTest extends TestCase
14+ {
15+ public function testRunMigrationAfterInstall (): void
16+ {
17+ if (! class_exists (Driver::class)) {
18+ $ this ->assertTrue (true );
19+
20+ return ;
21+ }
22+
23+ DB ::table ('migrations ' )->truncate ();
24+
25+ Schema::connection ($ this ->database )->dropIfExists ($ this ->table );
26+
27+ $ this ->assertDatabaseCount ('migrations ' , 0 );
28+ $ this ->assertDatabaseDoesntTable ($ this ->table );
29+
30+ $ this ->artisan (Names::INSTALL )->run ();
31+
32+ $ this ->assertDatabaseCount ('migrations ' , 0 );
33+ $ this ->assertDatabaseHasTable ($ this ->table );
34+
35+ $ this ->artisan ('migrate ' )->run ();
36+
37+ $ this ->assertDatabaseCount ('migrations ' , 1 );
38+ $ this ->assertDatabaseHas ('migrations ' , ['migration ' => '2022_08_18_180137_change_migration_actions_table ' ]);
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments