Skip to content

Commit 73282e0

Browse files
authored
Merge pull request #6 from orisintel/feature/dump-ending-in-line-break
feat(MigrateDumpCommand): Append new line after dumps to aid readabil…
2 parents 204da22 + 858e928 commit 73282e0

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

src/Commands/MigrateDumpCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ private static function mysqlDump(array $db_config, string $schema_sql_path) : i
145145

146146
$output = self::reorderMigrationRows($output);
147147

148+
// Append reordered rows, and include a line break to make SCM diffs
149+
// easier to read.
148150
file_put_contents(
149151
$schema_sql_path,
150-
implode(PHP_EOL, $output),
152+
implode(PHP_EOL, $output) . PHP_EOL,
151153
FILE_APPEND
152154
);
153155

@@ -196,7 +198,7 @@ private static function pgsqlDump(array $db_config, string $schema_sql_path) : i
196198

197199
file_put_contents(
198200
$schema_sql_path,
199-
implode(PHP_EOL, $output),
201+
implode(PHP_EOL, $output) . PHP_EOL,
200202
FILE_APPEND
201203
);
202204

tests/Mysql/MigrateDumpTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public function test_handle()
2424
$this->assertContains('CREATE TABLE `test_ms`', $result_sql);
2525
$this->assertContains('INSERT INTO `migrations`', $result_sql);
2626
$this->assertNotContains(' AUTO_INCREMENT=', $result_sql);
27+
$last_character = mb_substr($result_sql, -1);
28+
$this->assertRegExp("/[\r\n]\z/mu", $last_character);
2729
}
2830

2931
public function test_reorderMigrationRows()

tests/Postgresql/MigrateDumpTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ public function test_handle()
1919
$result_sql = file_get_contents($this->schemaSqlPath);
2020
$this->assertRegExp('/CREATE TABLE (public\.)?test_ms /', $result_sql);
2121
$this->assertRegExp('/INSERT INTO (public\.)?migrations /', $result_sql);
22+
$last_character = mb_substr($result_sql, -1);
23+
$this->assertRegExp("/[\r\n]\z/mu", $last_character);
2224
}
23-
}
25+
}

tests/Sqlite/MigrateDumpTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ public function test_handle()
1515
$result_sql = file_get_contents($this->schemaSqlPath);
1616
$this->assertRegExp('/CREATE TABLE( IF NOT EXISTS)? "test_ms" /', $result_sql);
1717
$this->assertRegExp('/INSERT INTO "?migrations"? /', $result_sql);
18+
$last_character = mb_substr($result_sql, -1);
19+
$this->assertRegExp("/[\r\n]\z/mu", $last_character);
1820
}
1921
}

0 commit comments

Comments
 (0)