From 110eb15a77f84da0d83ebc2bb123eec08ecc19ca Mon Sep 17 00:00:00 2001
From: Taylor Otwell <taylorotwell@gmail.com>
Date: Thu, 5 Nov 2020 09:31:08 -0600
Subject: [PATCH] respect migration table name in config when dumping schema

---
 .../Database/Console/DumpCommand.php          |  2 ++
 .../Database/Schema/MySqlSchemaState.php      |  2 +-
 .../Database/Schema/PostgresSchemaState.php   |  2 +-
 .../Database/Schema/SchemaState.php           | 20 +++++++++++++++++++
 .../Database/Schema/SqliteSchemaState.php     |  2 +-
 5 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/Illuminate/Database/Console/DumpCommand.php b/src/Illuminate/Database/Console/DumpCommand.php
index 24e0fa91de8f..4cb26bde3c3b 100644
--- a/src/Illuminate/Database/Console/DumpCommand.php
+++ b/src/Illuminate/Database/Console/DumpCommand.php
@@ -8,6 +8,7 @@
 use Illuminate\Database\ConnectionResolverInterface;
 use Illuminate\Database\Events\SchemaDumped;
 use Illuminate\Filesystem\Filesystem;
+use Illuminate\Support\Facades\Config;
 
 class DumpCommand extends Command
 {
@@ -63,6 +64,7 @@ public function handle(ConnectionResolverInterface $connections, Dispatcher $dis
     protected function schemaState(Connection $connection)
     {
         return $connection->getSchemaState()
+                ->withMigrationTable(Config::get('database.migrations', 'migrations'))
                 ->handleOutputUsing(function ($type, $buffer) {
                     $this->output->write($buffer);
                 });
diff --git a/src/Illuminate/Database/Schema/MySqlSchemaState.php b/src/Illuminate/Database/Schema/MySqlSchemaState.php
index eda6c886009a..472739f787ec 100644
--- a/src/Illuminate/Database/Schema/MySqlSchemaState.php
+++ b/src/Illuminate/Database/Schema/MySqlSchemaState.php
@@ -53,7 +53,7 @@ protected function removeAutoIncrementingState(string $path)
     protected function appendMigrationData(string $path)
     {
         $process = $this->executeDumpProcess($this->makeProcess(
-            $this->baseDumpCommand().' migrations --no-create-info --skip-extended-insert --skip-routines --compact'
+            $this->baseDumpCommand().' '.$this->migrationTable.' --no-create-info --skip-extended-insert --skip-routines --compact'
         ), null, array_merge($this->baseVariables($this->connection->getConfig()), [
             //
         ]));
diff --git a/src/Illuminate/Database/Schema/PostgresSchemaState.php b/src/Illuminate/Database/Schema/PostgresSchemaState.php
index 8cfa45c21cfd..8349a0b53083 100644
--- a/src/Illuminate/Database/Schema/PostgresSchemaState.php
+++ b/src/Illuminate/Database/Schema/PostgresSchemaState.php
@@ -19,7 +19,7 @@ public function dump(Connection $connection, $path)
         $excludedTables = collect($connection->getSchemaBuilder()->getAllTables())
                         ->map->tablename
                         ->reject(function ($table) {
-                            return $table === 'migrations';
+                            return $table === $this->migrationTable;
                         })->map(function ($table) {
                             return '--exclude-table-data='.$table;
                         })->implode(' ');
diff --git a/src/Illuminate/Database/Schema/SchemaState.php b/src/Illuminate/Database/Schema/SchemaState.php
index 781191e6fd43..6c4e56578252 100644
--- a/src/Illuminate/Database/Schema/SchemaState.php
+++ b/src/Illuminate/Database/Schema/SchemaState.php
@@ -22,6 +22,13 @@ abstract class SchemaState
      */
     protected $files;
 
+    /**
+     * The name of the application's migration table.
+     *
+     * @var string
+     */
+    protected $migrationTable = 'migrations';
+
     /**
      * The process factory callback.
      *
@@ -87,6 +94,19 @@ public function makeProcess(...$arguments)
         return call_user_func($this->processFactory, ...$arguments);
     }
 
+    /**
+     * Specify the name of the application's migration table.
+     *
+     * @param  string  $table
+     * @return $this
+     */
+    public function withMigrationTable(string $table)
+    {
+        $this->migrationTable = $table;
+
+        return $this;
+    }
+
     /**
      * Specify the callback that should be used to handle process output.
      *
diff --git a/src/Illuminate/Database/Schema/SqliteSchemaState.php b/src/Illuminate/Database/Schema/SqliteSchemaState.php
index 57187843e6a7..247b52a534fa 100644
--- a/src/Illuminate/Database/Schema/SqliteSchemaState.php
+++ b/src/Illuminate/Database/Schema/SqliteSchemaState.php
@@ -39,7 +39,7 @@ public function dump(Connection $connection, $path)
     protected function appendMigrationData(string $path)
     {
         with($process = $this->makeProcess(
-            $this->baseCommand().' ".dump \'migrations\'"'
+            $this->baseCommand().' ".dump \''.$this->migrationTable.'\'"'
         ))->mustRun(null, array_merge($this->baseVariables($this->connection->getConfig()), [
             //
         ]));