diff --git a/src/Illuminate/Database/Console/DumpCommand.php b/src/Illuminate/Database/Console/DumpCommand.php index ef4c0beb593b..24e0fa91de8f 100644 --- a/src/Illuminate/Database/Console/DumpCommand.php +++ b/src/Illuminate/Database/Console/DumpCommand.php @@ -35,9 +35,11 @@ class DumpCommand extends Command */ public function handle(ConnectionResolverInterface $connections, Dispatcher $dispatcher) { - $this->schemaState( - $connection = $connections->connection($database = $this->input->getOption('database')) - )->dump($path = $this->path($connection)); + $connection = $connections->connection($database = $this->input->getOption('database')); + + $this->schemaState($connection)->dump( + $connection, $path = $this->path($connection) + ); $dispatcher->dispatch(new SchemaDumped($connection, $path)); diff --git a/src/Illuminate/Database/Schema/MySqlSchemaState.php b/src/Illuminate/Database/Schema/MySqlSchemaState.php index fa5ce7bc5f67..b8bf3072fc1b 100644 --- a/src/Illuminate/Database/Schema/MySqlSchemaState.php +++ b/src/Illuminate/Database/Schema/MySqlSchemaState.php @@ -3,6 +3,7 @@ namespace Illuminate\Database\Schema; use Exception; +use Illuminate\Database\Connection; use Illuminate\Support\Str; use Symfony\Component\Process\Process; @@ -11,10 +12,11 @@ class MySqlSchemaState extends SchemaState /** * Dump the database's schema into a file. * + * @param \Illuminate\Database\Connection $connection * @param string $path * @return void */ - public function dump($path) + public function dump(Connection $connection, $path) { $this->executeDumpProcess($this->makeProcess( $this->baseDumpCommand().' --routines --result-file="${:LARAVEL_LOAD_PATH}" --no-data' diff --git a/src/Illuminate/Database/Schema/PostgresSchemaState.php b/src/Illuminate/Database/Schema/PostgresSchemaState.php index 05fab012dfc5..8cfa45c21cfd 100644 --- a/src/Illuminate/Database/Schema/PostgresSchemaState.php +++ b/src/Illuminate/Database/Schema/PostgresSchemaState.php @@ -2,6 +2,7 @@ namespace Illuminate\Database\Schema; +use Illuminate\Database\Connection; use Illuminate\Support\Str; class PostgresSchemaState extends SchemaState @@ -9,40 +10,25 @@ class PostgresSchemaState extends SchemaState /** * Dump the database's schema into a file. * + * @param \Illuminate\Database\Connection $connection * @param string $path * @return void */ - public function dump($path) + public function dump(Connection $connection, $path) { + $excludedTables = collect($connection->getSchemaBuilder()->getAllTables()) + ->map->tablename + ->reject(function ($table) { + return $table === 'migrations'; + })->map(function ($table) { + return '--exclude-table-data='.$table; + })->implode(' '); + $this->makeProcess( - $this->baseDumpCommand().' --no-owner --file=$LARAVEL_LOAD_PATH --schema-only' + $this->baseDumpCommand().' --no-owner --file=$LARAVEL_LOAD_PATH '.$excludedTables )->mustRun($this->output, array_merge($this->baseVariables($this->connection->getConfig()), [ 'LARAVEL_LOAD_PATH' => $path, ])); - - $this->appendMigrationData($path); - } - - /** - * Append the migration data to the schema dump. - * - * @param string $path - * @return void - */ - protected function appendMigrationData(string $path) - { - with($process = $this->makeProcess( - $this->baseDumpCommand().' --table=migrations --data-only --inserts' - ))->setTimeout(null)->mustRun(null, array_merge($this->baseVariables($this->connection->getConfig()), [ - // - ])); - - $migrations = collect(preg_split("/\r\n|\n|\r/", $process->getOutput()))->filter(function ($line) { - return preg_match('/^\s*(--|SELECT\s|SET\s)/iu', $line) === 0 && - strlen($line) > 0; - })->all(); - - $this->files->append($path, implode(PHP_EOL, $migrations).PHP_EOL); } /** diff --git a/src/Illuminate/Database/Schema/SchemaState.php b/src/Illuminate/Database/Schema/SchemaState.php index 072ffb8cbe23..781191e6fd43 100644 --- a/src/Illuminate/Database/Schema/SchemaState.php +++ b/src/Illuminate/Database/Schema/SchemaState.php @@ -62,10 +62,11 @@ public function __construct(Connection $connection, Filesystem $files = null, ca /** * Dump the database's schema into a file. * + * @param \Illuminate\Database\Connection $connection * @param string $path * @return void */ - abstract public function dump($path); + abstract public function dump(Connection $connection, $path); /** * Load the given schema file into the database. diff --git a/src/Illuminate/Database/Schema/SqliteSchemaState.php b/src/Illuminate/Database/Schema/SqliteSchemaState.php index 8f6487cad529..57187843e6a7 100644 --- a/src/Illuminate/Database/Schema/SqliteSchemaState.php +++ b/src/Illuminate/Database/Schema/SqliteSchemaState.php @@ -2,16 +2,18 @@ namespace Illuminate\Database\Schema; +use Illuminate\Database\Connection; + class SqliteSchemaState extends SchemaState { /** * Dump the database's schema into a file. * - * @param string $path - * + * @param \Illuminate\Database\Connection + * @param string $path * @return void */ - public function dump($path) + public function dump(Connection $connection, $path) { with($process = $this->makeProcess( $this->baseCommand().' .schema' @@ -53,8 +55,7 @@ protected function appendMigrationData(string $path) /** * Load the given schema file into the database. * - * @param string $path - * + * @param string $path * @return void */ public function load($path)