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

[11.x] Fix dumping migrations table with schema or prefixed name #52098

Merged
merged 2 commits into from
Jul 15, 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
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Console/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function schemaState(Connection $connection)
$migrationTable = is_array($migrations) ? ($migrations['table'] ?? 'migrations') : $migrations;

return $connection->getSchemaState()
->withMigrationTable($connection->getTablePrefix().$migrationTable)
->withMigrationTable($migrationTable)
->handleOutputUsing(function ($type, $buffer) {
$this->output->write($buffer);
});
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/MySqlSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function removeAutoIncrementingState(string $path)
protected function appendMigrationData(string $path)
{
$process = $this->executeDumpProcess($this->makeProcess(
$this->baseDumpCommand().' '.$this->migrationTable.' --no-create-info --skip-extended-insert --skip-routines --compact --complete-insert'
$this->baseDumpCommand().' '.$this->getMigrationTable().' --no-create-info --skip-extended-insert --skip-routines --compact --complete-insert'
), null, array_merge($this->baseVariables($this->connection->getConfig()), [
//
]));
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/PostgresBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected function getSchemas()
* @param string $reference
* @return array
*/
protected function parseSchemaAndTable($reference)
public function parseSchemaAndTable($reference)
{
$parts = explode('.', $reference);

Expand Down
14 changes: 13 additions & 1 deletion src/Illuminate/Database/Schema/PostgresSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function dump(Connection $connection, $path)
]);

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

$commands->map(function ($command, $path) {
Expand Down Expand Up @@ -51,6 +51,18 @@ public function load($path)
]));
}

/**
* Get the name of the application's migration table.
*
* @return string
*/
protected function getMigrationTable(): string
{
[$schema, $table] = $this->connection->getSchemaBuilder()->parseSchemaAndTable($this->migrationTable);

return $schema.'.'.$this->connection->getTablePrefix().$table;
}

/**
* Get the base dump command arguments for PostgreSQL as a string.
*
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 @@ -104,6 +104,16 @@ public function hasMigrationTable(): bool
return $this->connection->getSchemaBuilder()->hasTable($this->migrationTable);
}

/**
* Get the name of the application's migration table.
*
* @return string
*/
protected function getMigrationTable(): string
{
return $this->connection->getTablePrefix().$this->migrationTable;
}

/**
* Specify the name of the application's migration table.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/SqliteSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function dump(Connection $connection, $path)
protected function appendMigrationData(string $path)
{
with($process = $this->makeProcess(
$this->baseCommand().' ".dump \''.$this->migrationTable.'\'"'
$this->baseCommand().' ".dump \''.$this->getMigrationTable().'\'"'
))->mustRun(null, array_merge($this->baseVariables($this->connection->getConfig()), [
//
]));
Expand Down
Loading