Skip to content

Commit 7fb1a46

Browse files
Merge pull request #114 from TheDragonCode/4.x-1
Database table name changed from `migration_actions` to `actions`
2 parents 1ea8351 + b4fa9e3 commit 7fb1a46

8 files changed

+81
-3
lines changed

config/actions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
|
2525
*/
2626

27-
'table' => 'deploy_actions',
27+
'table' => 'actions',
2828

2929
/*
3030
|--------------------------------------------------------------------------

database/migrations/anonymous/2022_08_18_180137_change_migration_actions_table.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use DragonCode\LaravelActions\Database\BaseChangeColumn;
46

57
return new class () extends BaseChangeColumn
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use DragonCode\LaravelActions\Database\BaseRenameMigrationsActionsTableToActions;
6+
7+
return new class () extends BaseRenameMigrationsActionsTableToActions
8+
{
9+
};

database/migrations/named/2022_08_18_180137_change_migration_actions_table.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use DragonCode\LaravelActions\Database\BaseChangeColumn;
46

57
class ChangeMigrationActionsTable extends BaseChangeColumn
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use DragonCode\LaravelActions\Database\BaseRenameMigrationsActionsTableToActions;
6+
7+
class RenameMigrationsActionsTableToActions extends BaseRenameMigrationsActionsTableToActions
8+
{
9+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelActions\Database;
6+
7+
use DragonCode\LaravelActions\Action;
8+
use DragonCode\LaravelActions\Helpers\Config;
9+
use Illuminate\Support\Facades\Schema;
10+
use RuntimeException;
11+
12+
class BaseRenameMigrationsActionsTableToActions extends Action
13+
{
14+
protected Config $config;
15+
16+
public function __construct()
17+
{
18+
$this->config = app(Config::class);
19+
}
20+
21+
public function up(): void
22+
{
23+
if (Schema::hasTable('migration_actions') && $this->doesntSame('migration_actions', $this->table())) {
24+
$this->validateTable($this->table());
25+
26+
Schema::rename('migration_actions', $this->table());
27+
}
28+
}
29+
30+
public function down(): void
31+
{
32+
if (Schema::hasTable($this->table()) && $this->doesntSame('migration_actions', $this->table())) {
33+
$this->validateTable('migration_actions');
34+
35+
Schema::rename($this->table(), 'migration_actions');
36+
}
37+
}
38+
39+
protected function validateTable(string $name): void
40+
{
41+
if (Schema::hasTable($name)) {
42+
throw new RuntimeException(sprintf('A table named [%s] already exists. Change the table name settings in the [%s] configuration file.', $name, 'config/actions.php'));
43+
}
44+
}
45+
46+
protected function doesntSame(string $first, string $second): bool
47+
{
48+
return $first !== $second;
49+
}
50+
51+
protected function table(): string
52+
{
53+
return $this->config->table();
54+
}
55+
}

src/ServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public function boot(): void
2222
if ($this->app->runningInConsole()) {
2323
$this->publishConfig();
2424

25-
$this->registerCommands();
2625
$this->registerAbout();
26+
$this->registerCommands();
2727
$this->registerMigrations();
2828
$this->registerNotifications();
2929
}

tests/Migrations/MigrationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public function testRunMigrationAfterInstall(): void
3434

3535
$this->artisan('migrate')->run();
3636

37-
$this->assertDatabaseCount('migrations', 1);
37+
$this->assertDatabaseCount('migrations', 2);
3838
$this->assertDatabaseHas('migrations', ['migration' => '2022_08_18_180137_change_migration_actions_table']);
39+
$this->assertDatabaseHas('migrations', ['migration' => '2023_01_21_172923_rename_migrations_actions_table_to_actions']);
3940
}
4041
}

0 commit comments

Comments
 (0)