Skip to content

Commit 1adfeda

Browse files
Database table name changed from migration_actions to actions
1 parent 4c01cd0 commit 1adfeda

7 files changed

+86
-5
lines changed

config/actions.php

Lines changed: 3 additions & 3 deletions
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
|--------------------------------------------------------------------------
@@ -35,7 +35,7 @@
3535
|
3636
*/
3737

38-
'path' => base_path('actions'),
38+
'path' => base_path('actions'),
3939

4040
/*
4141
|--------------------------------------------------------------------------
@@ -56,5 +56,5 @@
5656
|
5757
*/
5858

59-
'exclude' => null,
59+
'exclude' => null,
6060
];
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

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

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

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
}

0 commit comments

Comments
 (0)