forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[10.x] Improvements for
artisan migrate --pretend
command 🚀 (larave…
…l#48768) * Allow to exclude DB::select*() statements to be excluded from 'pretend' mode * Ensured that we are null safe * Reconsidered naming * Nah, let's keep things simple and people self-responsible * Cleanup * Naming * Changed return type to mixed * Added tests * Cleanup * Added bindings to output and improved tests * Style fixes * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
a02ef13
commit 4e43ca0
Showing
7 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tests/Integration/Migration/pretending/2014_10_12_000000_create_people_is_dynamic_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreatePeopleIsDynamicTable extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::create('people', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('blog_id')->nullable(); | ||
$table->string('name'); | ||
$table->string('email')->unique(); | ||
$table->string('password'); | ||
$table->rememberToken(); | ||
$table->timestamps(); | ||
}); | ||
|
||
DB::table('people')->insert([ | ||
['email' => '[email protected]', 'name' => 'Jane Doe', 'password' => 'secret'], | ||
['email' => '[email protected]', 'name' => 'John Doe', 'password' => 'secret'], | ||
]); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/Integration/Migration/pretending/2014_10_12_000000_create_people_non_dynamic_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreatePeopleNonDynamicTable extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::create('people', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('name'); | ||
$table->string('email')->unique(); | ||
$table->string('password'); | ||
$table->rememberToken(); | ||
$table->timestamps(); | ||
}); | ||
|
||
DB::table('people')->insert([ | ||
['email' => '[email protected]', 'name' => 'Jane Doe', 'password' => 'secret'], | ||
['email' => '[email protected]', 'name' => 'John Doe', 'password' => 'secret'], | ||
]); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/Integration/Migration/pretending/2023_10_17_000000_dynamic_content_is_shown.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class DynamicContentIsShown extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::create('blogs', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('url')->nullable(); | ||
$table->string('name')->nullable(); | ||
}); | ||
|
||
DB::table('blogs')->insert([ | ||
['url' => 'www.janedoe.com'], | ||
['url' => 'www.johndoe.com'], | ||
]); | ||
|
||
DB::statement("ALTER TABLE 'pseudo_table_name' MODIFY 'column_name' VARCHAR(191)"); | ||
|
||
/** @var \Illuminate\Support\Collection $tablesList */ | ||
$tablesList = DB::withoutPretending(function () { | ||
return DB::table('people')->get(); | ||
}); | ||
|
||
$tablesList->each(function ($person, $key) { | ||
DB::table('blogs')->where('blog_id', '=', $person->blog_id)->insert([ | ||
'id' => $key + 1, | ||
'name' => "{$person->name} Blog", | ||
]); | ||
}); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/Integration/Migration/pretending/2023_10_17_000000_dynamic_content_not_shown.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class DynamicContentNotShown extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::create('blogs', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('url')->nullable(); | ||
$table->string('name')->nullable(); | ||
}); | ||
|
||
DB::table('blogs')->insert([ | ||
['url' => 'www.janedoe.com'], | ||
['url' => 'www.johndoe.com'], | ||
]); | ||
|
||
DB::statement("ALTER TABLE 'pseudo_table_name' MODIFY 'column_name' VARCHAR(191)"); | ||
|
||
DB::table('people')->get()->each(function ($person, $key) { | ||
DB::table('blogs')->where('blog_id', '=', $person->blog_id)->insert([ | ||
'id' => $key + 1, | ||
'name' => "{$person->name} Blog", | ||
]); | ||
}); | ||
} | ||
} |