Skip to content

Commit

Permalink
[10.x] Ensureschema:dump will dump the migrations table only if it …
Browse files Browse the repository at this point in the history
…exists (laravel#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]>
  • Loading branch information
NickSdot and taylorotwell authored Jun 19, 2024
1 parent 16472d1 commit f7ea4e9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Schema/MySqlSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public function dump(Connection $connection, $path)

$this->removeAutoIncrementingState($path);

$this->appendMigrationData($path);
if ($this->hasMigrationTable()) {
$this->appendMigrationData($path);
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Illuminate/Database/Schema/PostgresSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ public function dump(Connection $connection, $path)
{
$commands = collect([
$this->baseDumpCommand().' --schema-only > '.$path,
$this->baseDumpCommand().' -t '.$this->migrationTable.' --data-only >> '.$path,
]);

if ($this->hasMigrationTable()) {
$commands->push($this->baseDumpCommand().' -t '.$this->migrationTable.' --data-only >> '.$path);
}

$commands->map(function ($command, $path) {
$this->makeProcess($command)->mustRun($this->output, array_merge($this->baseVariables($this->connection->getConfig()), [
'LARAVEL_LOAD_PATH' => $path,
Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Database/Schema/SchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ public function makeProcess(...$arguments)
return call_user_func($this->processFactory, ...$arguments);
}

/**
* Determine if the current connection has a migration table.
*
* @return bool
*/
public function hasMigrationTable(): bool
{
return $this->connection->getSchemaBuilder()->hasTable($this->migrationTable);
}

/**
* Specify the name of the application's migration table.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Schema/SqliteSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public function dump(Connection $connection, $path)

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

$this->appendMigrationData($path);
if ($this->hasMigrationTable()) {
$this->appendMigrationData($path);
}
}

/**
Expand Down

0 comments on commit f7ea4e9

Please sign in to comment.