Skip to content

Commit da81c00

Browse files
author
Paul Rogers
committed
fix(MigrateDumpCommand::mysqlDump): Remove AUTO_INCREMENT= values from dumps.
1 parent ffcc5d6 commit da81c00

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Commands/MigrateDumpCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ private static function mysqlDump(array $db_config, string $schema_sql_path) : i
7171

7272
// Not including connection name in file since typically only one DB.
7373
// Excluding any hash or date suffix since only current is relevant.
74-
$command_prefix = 'mysqldump --routines --skip-add-drop-table'
74+
$command_prefix = 'set -o pipefail &&'
75+
. ' mysqldump --routines --skip-add-drop-table --fake'
7576
. ' --skip-add-locks --skip-comments --skip-set-charset --tz-utc'
7677
. ' --host=' . escapeshellarg($db_config['host'])
7778
. ' --port=' . escapeshellarg($db_config['port'])
@@ -80,8 +81,9 @@ private static function mysqlDump(array $db_config, string $schema_sql_path) : i
8081
. ' ' . escapeshellarg($db_config['database']);
8182
passthru(
8283
$command_prefix
83-
. ' --result-file=' . escapeshellarg($schema_sql_path)
84-
. ' --no-data',
84+
. ' --no-data'
85+
// CONSIDER: Avoiding Bash/shell and Sed by doing replacement in PHP.
86+
. ' | sed -E "s/ AUTO_INCREMENT=[0-9]+ ?//g" > ' . escapeshellarg($schema_sql_path),
8587
$exit_code
8688
);
8789

tests/Mysql/MigrateDumpTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ public function test_handle()
1717
$result_sql = file_get_contents($this->schemaSqlPath);
1818
$this->assertContains('CREATE TABLE `test_ms`', $result_sql);
1919
$this->assertContains('INSERT INTO `migrations`', $result_sql);
20+
$this->assertNotContains(' AUTO_INCREMENT=', $result_sql);
2021
}
2122
}

0 commit comments

Comments
 (0)