Skip to content

Commit f7ea4e9

Browse files
[10.x] Ensureschema:dump will dump the migrations table only if it exists (#51827)
* fix: migrations table must only be dumped on default connection * fix: migrations table must only be dumped on default connection * Style * Use `$this->connection->getSchemaBuilder()->hasTable()` instead of `Config::get()`` * Update SchemaState.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 16472d1 commit f7ea4e9

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/Illuminate/Database/Schema/MySqlSchemaState.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public function dump(Connection $connection, $path)
2626

2727
$this->removeAutoIncrementingState($path);
2828

29-
$this->appendMigrationData($path);
29+
if ($this->hasMigrationTable()) {
30+
$this->appendMigrationData($path);
31+
}
3032
}
3133

3234
/**

src/Illuminate/Database/Schema/PostgresSchemaState.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ public function dump(Connection $connection, $path)
1717
{
1818
$commands = collect([
1919
$this->baseDumpCommand().' --schema-only > '.$path,
20-
$this->baseDumpCommand().' -t '.$this->migrationTable.' --data-only >> '.$path,
2120
]);
2221

22+
if ($this->hasMigrationTable()) {
23+
$commands->push($this->baseDumpCommand().' -t '.$this->migrationTable.' --data-only >> '.$path);
24+
}
25+
2326
$commands->map(function ($command, $path) {
2427
$this->makeProcess($command)->mustRun($this->output, array_merge($this->baseVariables($this->connection->getConfig()), [
2528
'LARAVEL_LOAD_PATH' => $path,

src/Illuminate/Database/Schema/SchemaState.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ public function makeProcess(...$arguments)
9494
return call_user_func($this->processFactory, ...$arguments);
9595
}
9696

97+
/**
98+
* Determine if the current connection has a migration table.
99+
*
100+
* @return bool
101+
*/
102+
public function hasMigrationTable(): bool
103+
{
104+
return $this->connection->getSchemaBuilder()->hasTable($this->migrationTable);
105+
}
106+
97107
/**
98108
* Specify the name of the application's migration table.
99109
*

src/Illuminate/Database/Schema/SqliteSchemaState.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public function dump(Connection $connection, $path)
2828

2929
$this->files->put($path, implode(PHP_EOL, $migrations).PHP_EOL);
3030

31-
$this->appendMigrationData($path);
31+
if ($this->hasMigrationTable()) {
32+
$this->appendMigrationData($path);
33+
}
3234
}
3335

3436
/**

0 commit comments

Comments
 (0)