Skip to content

Commit f748796

Browse files
[12.x] Fix migrate:fresh command on SQLite with WAL journal_mode (#56368)
* [12.x] Fix `migrate:fresh` command on SQLite with WAL journal_mode fix #56357 Signed-off-by: Mior Muhammad Zaki <[email protected]> * Prevents running on other database Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Update WipeCommand.php --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent 7c6bed2 commit f748796

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/Illuminate/Database/Console/WipeCommand.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public function handle()
5757
$this->components->info('Dropped all types successfully.');
5858
}
5959

60+
$this->flushDatabaseConnection($database);
61+
6062
return 0;
6163
}
6264

@@ -99,6 +101,17 @@ protected function dropAllTypes($database)
99101
->dropAllTypes();
100102
}
101103

104+
/**
105+
* Flush the given database connection.
106+
*
107+
* @param string $database
108+
* @return void
109+
*/
110+
protected function flushDatabaseConnection($database)
111+
{
112+
$this->laravel['db']->connection($database)->disconnect();
113+
}
114+
102115
/**
103116
* Get the console command options.
104117
*
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Database\Sqlite\Console;
4+
5+
use Illuminate\Filesystem\Filesystem;
6+
use Illuminate\Support\Facades\Schema;
7+
use Illuminate\Tests\Integration\Database\DatabaseTestCase;
8+
use Orchestra\Testbench\Attributes\RequiresDatabase;
9+
use Orchestra\Testbench\Attributes\WithConfig;
10+
11+
use function Illuminate\Filesystem\join_paths;
12+
use function Orchestra\Testbench\default_migration_path;
13+
use function Orchestra\Testbench\default_skeleton_path;
14+
15+
#[RequiresDatabase('sqlite')]
16+
#[WithConfig('database.connections.sqlite.journal_mode', 'wal')]
17+
class MigrateFreshCommandWithJournalModeWalTest extends DatabaseTestCase
18+
{
19+
/** {@inheritDoc} */
20+
#[\Override]
21+
protected function setUp(): void
22+
{
23+
$files = new Filesystem;
24+
25+
$files->copy(
26+
join_paths(__DIR__, 'stubs', 'database-journal-mode-wal.sqlite'),
27+
join_paths(default_skeleton_path(), 'database', 'database.sqlite')
28+
);
29+
30+
$this->beforeApplicationDestroyed(function () use ($files) {
31+
$files->delete(database_path('database.sqlite'));
32+
});
33+
34+
parent::setUp();
35+
}
36+
37+
public function testRunningMigrateFreshCommandWithWalJournalMode()
38+
{
39+
$this->artisan('migrate:fresh', [
40+
'--realpath' => true,
41+
'--path' => default_migration_path(),
42+
])->run();
43+
44+
$this->assertTrue(Schema::hasTable('users'));
45+
}
46+
}
Binary file not shown.

0 commit comments

Comments
 (0)