Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Ensureschema:dump will dump the migrations table only if it exists #51827

Merged
merged 6 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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