Skip to content

Commit

Permalink
Merge pull request #2374 from erikn69/patch-6
Browse files Browse the repository at this point in the history
[V6] Use anonymous migrations
  • Loading branch information
drbyte committed Mar 24, 2023
2 parents de846f7 + bfc3e3b commit 4845386
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
8 changes: 4 additions & 4 deletions database/migrations/add_teams_fields.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddTeamsFields extends Migration
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
$teams = config('permission.teams');
$tableNames = config('permission.table_names');
Expand Down Expand Up @@ -88,8 +88,8 @@ class AddTeamsFields extends Migration
*
* @return void
*/
public function down()
public function down(): void
{

}
}
};
8 changes: 4 additions & 4 deletions database/migrations/create_permission_tables.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePermissionTables extends Migration
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
$teams = config('permission.teams');
$tableNames = config('permission.table_names');
Expand Down Expand Up @@ -125,7 +125,7 @@ class CreatePermissionTables extends Migration
*
* @return void
*/
public function down()
public function down(): void
{
$tableNames = config('permission.table_names');

Expand All @@ -139,4 +139,4 @@ class CreatePermissionTables extends Migration
Schema::drop($tableNames['roles']);
Schema::drop($tableNames['permissions']);
}
}
};
6 changes: 3 additions & 3 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ public function it_can_setup_teams_upgrade()
$matchingFiles = glob(database_path('migrations/*_add_teams_fields.php'));
$this->assertTrue(count($matchingFiles) > 0);

include_once $matchingFiles[count($matchingFiles) - 1];
(new \AddTeamsFields())->up();
(new \AddTeamsFields())->up(); //test upgrade teams migration fresh
$AddTeamsFields = require($matchingFiles[count($matchingFiles) - 1]);
$AddTeamsFields->up();
$AddTeamsFields->up(); //test upgrade teams migration fresh

Role::create(['name' => 'new-role', 'team_test_id' => 1]);
$role = Role::where('name', 'new-role')->first();
Expand Down
12 changes: 4 additions & 8 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ private function prepareMigration()
{
$migration = str_replace(
[
'CreatePermissionTables',
'(\'id\'); // permission id',
'(\'id\'); // role id',
'references(\'id\') // permission id',
Expand All @@ -177,7 +176,6 @@ private function prepareMigration()
'unsignedBigInteger($pivotPermission)',
],
[
'CreatePermissionCustomTables',
'(\'permission_test_id\');',
'(\'role_test_id\');',
'references(\'permission_test_id\')',
Expand All @@ -190,12 +188,10 @@ private function prepareMigration()
);

file_put_contents(__DIR__.'/CreatePermissionCustomTables.php', $migration);

include_once __DIR__.'/../database/migrations/create_permission_tables.php.stub';
self::$migration = new \CreatePermissionTables();

include_once __DIR__.'/CreatePermissionCustomTables.php';
self::$customMigration = new \CreatePermissionCustomTables();

self::$migration = require(__DIR__.'/../database/migrations/create_permission_tables.php.stub');

self::$customMigration = require(__DIR__.'/CreatePermissionCustomTables.php');
}

protected function reloadPermissions()
Expand Down

0 comments on commit 4845386

Please sign in to comment.