Skip to content

Commit 2639764

Browse files
author
Andrey Helldar
authored
Merge pull request #38 from TheDragonCode/2.x
Added support for anonymous migrations on Laravel 8.37+
2 parents 4fc8f1d + 3525fa1 commit 2639764

File tree

50 files changed

+54
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+54
-55
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"require": {
2727
"php": "^7.3 || ^8.0",
2828
"dragon-code/contracts": "^2.15",
29-
"dragon-code/laravel-support": "^3.2",
29+
"dragon-code/laravel-support": "^3.3",
3030
"illuminate/console": "^6.0 || ^7.0 || ^8.0 || ^9.0",
3131
"illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0",
3232
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0",
File renamed without changes.

src/Concerns/Anonymous.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelActions\Concerns;
6+
7+
use DragonCode\LaravelSupport\Facades\AppVersion;
8+
9+
trait Anonymous
10+
{
11+
protected function allowAnonymous(): bool
12+
{
13+
return AppVersion::is('8.37.0');
14+
}
15+
16+
protected function disallowAnonymous(): bool
17+
{
18+
return ! $this->allowAnonymous();
19+
}
20+
}

src/Concerns/Versionable.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Support/MigrationCreator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace DragonCode\LaravelActions\Support;
44

5-
use DragonCode\LaravelSupport\Facades\AppVersion;
5+
use DragonCode\LaravelActions\Concerns\Anonymous;
66
use Illuminate\Database\Migrations\MigrationCreator as BaseMigrationCreator;
77
use Illuminate\Filesystem\Filesystem;
88

99
class MigrationCreator extends BaseMigrationCreator
1010
{
11+
use Anonymous;
12+
1113
protected $customStubPath;
1214

1315
public function __construct(Filesystem $files, ?string $custom_stub_path)
@@ -31,7 +33,7 @@ public function stubPath()
3133

3234
protected function getStub($table, $create): string
3335
{
34-
$stub = AppVersion::is9x() ? '/action-9.x.stub' : '/action-prev.stub';
36+
$stub = $this->allowAnonymous() ? '/action-anonymous.stub' : '/action-named.stub';
3537

3638
return $this->files->get(
3739
$this->stubPath() . $stub

src/Support/Migrator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
use DragonCode\Contracts\LaravelActions\Actionable as ActionableContract;
66
use DragonCode\LaravelActions\Concerns\Infoable;
7-
use DragonCode\LaravelActions\Concerns\Versionable;
7+
use DragonCode\LaravelActions\Concerns\Anonymous;
88
use Illuminate\Database\Migrations\Migrator as BaseMigrator;
99
use Illuminate\Support\Facades\DB;
1010
use Throwable;
1111

1212
class Migrator extends BaseMigrator
1313
{
1414
use Infoable;
15-
use Versionable;
15+
use Anonymous;
1616

1717
public function usingConnection($name, callable $callback)
1818
{
@@ -39,7 +39,7 @@ protected function runUp($file, $batch, $pretend)
3939
// First we will resolve a "real" instance of the migration class from this
4040
// migration file name. Once we have the instances we can run the actual
4141
// command such as "up" or "down", or we can just simulate the action.
42-
if ($this->isLatestApp()) {
42+
if ($this->allowAnonymous()) {
4343
$migration = $this->resolvePath($file);
4444

4545
$name = $this->getMigrationName($file);
@@ -90,7 +90,7 @@ protected function runUp($file, $batch, $pretend)
9090
*/
9191
protected function runDown($file, $migration, $pretend)
9292
{
93-
if ($this->isLatestApp()) {
93+
if ($this->allowAnonymous()) {
9494
$instance = $this->resolvePath($file);
9595

9696
$name = $this->getMigrationName($file);

tests/Commands/CreatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testCreateAction()
2424

2525
public function testDuplicateOnPrev()
2626
{
27-
if ($this->isLatestApp()) {
27+
if ($this->allowAnonymous()) {
2828
$this->assertTrue(true);
2929

3030
return;
@@ -41,7 +41,7 @@ public function testDuplicateOnPrev()
4141

4242
public function testDuplicateOnLatest()
4343
{
44-
if ($this->isPrevApp()) {
44+
if ($this->disallowAnonymous()) {
4545
$this->assertTrue(true);
4646

4747
return;

tests/Commands/MakeTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Tests\Commands;
44

5-
use DragonCode\LaravelSupport\Facades\AppVersion;
65
use Tests\TestCase;
76

87
class MakeTest extends TestCase
@@ -21,9 +20,9 @@ public function testMakingFiles()
2120

2221
$this->assertFileExists($path);
2322

24-
$expected = AppVersion::is9x()
25-
? __DIR__ . '/../fixtures/app/9.x/stubs/make_example.stub'
26-
: __DIR__ . '/../fixtures/app/prev/stubs/make_example.stub';
23+
$expected = $this->allowAnonymous()
24+
? __DIR__ . '/../fixtures/app/anonymous/stubs/make_example.stub'
25+
: __DIR__ . '/../fixtures/app/named/stubs/make_example.stub';
2726

2827
$this->assertEquals(file_get_contents($expected), file_get_contents($path));
2928
}

tests/Concerns/Actionable.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
namespace Tests\Concerns;
44

5-
use DragonCode\LaravelSupport\Facades\AppVersion;
6-
75
trait Actionable
86
{
97
protected function getMigrationPath(): string
108
{
11-
return AppVersion::is9x()
12-
? __DIR__ . '/../fixtures/app/9.x/actions'
13-
: __DIR__ . '/../fixtures/app/prev/actions';
9+
return $this->allowAnonymous()
10+
? __DIR__ . '/../fixtures/app/anonymous/actions'
11+
: __DIR__ . '/../fixtures/app/named/actions';
1412
}
1513
}

0 commit comments

Comments
 (0)