Skip to content

Commit 95b1899

Browse files
authored
[9.x] Move to anonymous migrations (#37598)
* Move to anonymous migrations * Fix tests
1 parent be221e5 commit 95b1899

File tree

11 files changed

+31
-49
lines changed

11 files changed

+31
-49
lines changed

src/Illuminate/Cache/Console/stubs/cache.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
class CreateCacheTable extends Migration
7+
return new class extends Migration
88
{
99
/**
1010
* Run the migrations.
@@ -29,4 +29,4 @@ class CreateCacheTable extends Migration
2929
{
3030
Schema::dropIfExists('cache');
3131
}
32-
}
32+
};

src/Illuminate/Database/Migrations/MigrationCreator.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function create($name, $path, $table = null, $create = false)
6868
$this->files->ensureDirectoryExists(dirname($path));
6969

7070
$this->files->put(
71-
$path, $this->populateStub($name, $stub, $table)
71+
$path, $this->populateStub($stub, $table)
7272
);
7373

7474
// Next, we will fire any hooks that are supposed to fire after a migration is
@@ -132,18 +132,12 @@ protected function getStub($table, $create)
132132
/**
133133
* Populate the place-holders in the migration stub.
134134
*
135-
* @param string $name
136135
* @param string $stub
137136
* @param string|null $table
138137
* @return string
139138
*/
140-
protected function populateStub($name, $stub, $table)
139+
protected function populateStub($stub, $table)
141140
{
142-
$stub = str_replace(
143-
['DummyClass', '{{ class }}', '{{class}}'],
144-
$this->getClassName($name), $stub
145-
);
146-
147141
// Here we will replace the table place-holders with the table specified by
148142
// the developer, which is useful for quickly creating a tables creation
149143
// or update migration from the console instead of typing it manually.

src/Illuminate/Notifications/Console/stubs/notifications.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
class CreateNotificationsTable extends Migration
7+
return new class extends Migration
88
{
99
/**
1010
* Run the migrations.
@@ -32,4 +32,4 @@ class CreateNotificationsTable extends Migration
3232
{
3333
Schema::dropIfExists('notifications');
3434
}
35-
}
35+
};

src/Illuminate/Queue/Console/BatchesTableCommand.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Console\Command;
66
use Illuminate\Filesystem\Filesystem;
77
use Illuminate\Support\Composer;
8-
use Illuminate\Support\Str;
98

109
class BatchesTableCommand extends Command
1110
{
@@ -69,7 +68,7 @@ public function handle()
6968
$table = $this->laravel['config']['queue.batching.table'] ?? 'job_batches';
7069

7170
$this->replaceMigration(
72-
$this->createBaseMigration($table), $table, Str::studly($table)
71+
$this->createBaseMigration($table), $table
7372
);
7473

7574
$this->info('Migration created successfully!');
@@ -95,15 +94,12 @@ protected function createBaseMigration($table = 'failed_jobs')
9594
*
9695
* @param string $path
9796
* @param string $table
98-
* @param string $tableClassName
9997
* @return void
10098
*/
101-
protected function replaceMigration($path, $table, $tableClassName)
99+
protected function replaceMigration($path, $table)
102100
{
103101
$stub = str_replace(
104-
['{{table}}', '{{tableClassName}}'],
105-
[$table, $tableClassName],
106-
$this->files->get(__DIR__.'/stubs/batches.stub')
102+
'{{table}}', $table, $this->files->get(__DIR__.'/stubs/batches.stub')
107103
);
108104

109105
$this->files->put($path, $stub);

src/Illuminate/Queue/Console/FailedTableCommand.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Console\Command;
66
use Illuminate\Filesystem\Filesystem;
77
use Illuminate\Support\Composer;
8-
use Illuminate\Support\Str;
98

109
class FailedTableCommand extends Command
1110
{
@@ -69,7 +68,7 @@ public function handle()
6968
$table = $this->laravel['config']['queue.failed.table'];
7069

7170
$this->replaceMigration(
72-
$this->createBaseMigration($table), $table, Str::studly($table)
71+
$this->createBaseMigration($table), $table
7372
);
7473

7574
$this->info('Migration created successfully!');
@@ -95,15 +94,12 @@ protected function createBaseMigration($table = 'failed_jobs')
9594
*
9695
* @param string $path
9796
* @param string $table
98-
* @param string $tableClassName
9997
* @return void
10098
*/
101-
protected function replaceMigration($path, $table, $tableClassName)
99+
protected function replaceMigration($path, $table)
102100
{
103101
$stub = str_replace(
104-
['{{table}}', '{{tableClassName}}'],
105-
[$table, $tableClassName],
106-
$this->files->get(__DIR__.'/stubs/failed_jobs.stub')
102+
'{{table}}', $table, $this->files->get(__DIR__.'/stubs/failed_jobs.stub')
107103
);
108104

109105
$this->files->put($path, $stub);

src/Illuminate/Queue/Console/TableCommand.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Console\Command;
66
use Illuminate\Filesystem\Filesystem;
77
use Illuminate\Support\Composer;
8-
use Illuminate\Support\Str;
98

109
class TableCommand extends Command
1110
{
@@ -69,7 +68,7 @@ public function handle()
6968
$table = $this->laravel['config']['queue.connections.database.table'];
7069

7170
$this->replaceMigration(
72-
$this->createBaseMigration($table), $table, Str::studly($table)
71+
$this->createBaseMigration($table), $table
7372
);
7473

7574
$this->info('Migration created successfully!');
@@ -95,15 +94,12 @@ protected function createBaseMigration($table = 'jobs')
9594
*
9695
* @param string $path
9796
* @param string $table
98-
* @param string $tableClassName
9997
* @return void
10098
*/
101-
protected function replaceMigration($path, $table, $tableClassName)
99+
protected function replaceMigration($path, $table)
102100
{
103101
$stub = str_replace(
104-
['{{table}}', '{{tableClassName}}'],
105-
[$table, $tableClassName],
106-
$this->files->get(__DIR__.'/stubs/jobs.stub')
102+
'{{table}}', $table, $this->files->get(__DIR__.'/stubs/jobs.stub')
107103
);
108104

109105
$this->files->put($path, $stub);

src/Illuminate/Queue/Console/stubs/batches.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
class Create{{tableClassName}}Table extends Migration
7+
return new class extends Migration
88
{
99
/**
1010
* Run the migrations.
@@ -36,4 +36,4 @@ class Create{{tableClassName}}Table extends Migration
3636
{
3737
Schema::dropIfExists('{{table}}');
3838
}
39-
}
39+
};

src/Illuminate/Queue/Console/stubs/failed_jobs.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
class Create{{tableClassName}}Table extends Migration
7+
return new class extends Migration
88
{
99
/**
1010
* Run the migrations.
@@ -33,4 +33,4 @@ class Create{{tableClassName}}Table extends Migration
3333
{
3434
Schema::dropIfExists('{{table}}');
3535
}
36-
}
36+
};

src/Illuminate/Queue/Console/stubs/jobs.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
class Create{{tableClassName}}Table extends Migration
7+
return new class extends Migration
88
{
99
/**
1010
* Run the migrations.
@@ -33,4 +33,4 @@ class Create{{tableClassName}}Table extends Migration
3333
{
3434
Schema::dropIfExists('{{table}}');
3535
}
36-
}
36+
};

src/Illuminate/Session/Console/stubs/database.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
class CreateSessionsTable extends Migration
7+
return new class extends Migration
88
{
99
/**
1010
* Run the migrations.
@@ -32,4 +32,4 @@ class CreateSessionsTable extends Migration
3232
{
3333
Schema::dropIfExists('sessions');
3434
}
35-
}
35+
};

0 commit comments

Comments
 (0)