Skip to content

Commit 53d86d3

Browse files
author
Tom Schlick
committed
update sqlite data dumps to exclude migrations table
1 parent d9bc9a0 commit 53d86d3

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/Commands/MigrateDumpCommand.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,11 @@ private static function sqliteSchemaDump(array $db_config, string $schema_sql_pa
430430

431431
/**
432432
* @param array $db_config
433-
* @param string $schema_sql_path
433+
* @param string $data_sql_path
434434
*
435435
* @return int
436436
*/
437-
private static function sqliteDataDump(array $db_config, string $schema_sql_path) : int
437+
private static function sqliteDataDump(array $db_config, string $data_sql_path) : int
438438
{
439439
// CONSIDER: Accepting command name as option or from config.
440440
$command_prefix = 'sqlite3 ' . escapeshellarg($db_config['database']);
@@ -451,8 +451,13 @@ private static function sqliteDataDump(array $db_config, string $schema_sql_path
451451
$tables = preg_split('/\s+/', implode(' ', $output));
452452

453453
foreach ($tables as $table) {
454+
// We don't want to dump the migrations table here
455+
if ('migrations' === $table) {
456+
continue;
457+
}
458+
454459
// Only migrations should dump data with schema.
455-
$sql_command = 'migrations' !== $table ? '.dump' : '.schema';
460+
$sql_command = '.dump';
456461

457462
$output = [];
458463
exec(
@@ -465,14 +470,8 @@ private static function sqliteDataDump(array $db_config, string $schema_sql_path
465470
return $exit_code;
466471
}
467472

468-
if ('migrations' !== $table) {
469-
$insert_rows = array_slice($output, 4, -1);
470-
$sorted = self::reorderMigrationRows($insert_rows);
471-
array_splice($output, 4, -1, $sorted);
472-
}
473-
474473
file_put_contents(
475-
$schema_sql_path,
474+
$data_sql_path,
476475
implode(PHP_EOL, $output) . PHP_EOL,
477476
FILE_APPEND
478477
);

0 commit comments

Comments
 (0)