File tree Expand file tree Collapse file tree 3 files changed +70
-13
lines changed Expand file tree Collapse file tree 3 files changed +70
-13
lines changed Original file line number Diff line number Diff line change 4444 |
4545 */
4646 'trim-underscores ' => env ('MIGRATION_SNAPSHOT_TRIM_UNDERSCORES ' , true ),
47-
47+
4848 /*
4949 |--------------------------------------------------------------------------
5050 | Include Data
5656 |
5757 */
5858 'data ' => env ('MIGRATION_SNAPSHOT_DATA ' , false ),
59+
60+ /*
61+ |--------------------------------------------------------------------------
62+ | After Dump
63+ |--------------------------------------------------------------------------
64+ |
65+ | Run this closure after dumping snapshot. Helps when output may vary by
66+ | environment in unimportant ways which would just pollute the SCM history
67+ | with noisy changes.
68+ |
69+ | Must accept two arguments: `function ($schema_sql_path, $data_sql_path)`.
70+ |
71+ */
72+ 'after-dump ' => null ,
5973];
Original file line number Diff line number Diff line change @@ -62,26 +62,31 @@ public function handle()
6262
6363 $ this ->info ('Dumped schema ' );
6464
65- if (! $ this -> option ( ' include-data ' )) {
66- return ;
67- }
65+ $ data_sql_path = null ;
66+ if ( $ this -> option ( ' include-data ' )) {
67+ $ this -> info ( ' Starting Data Dump ' );
6868
69- $ this -> info ( ' Starting Data Dump ' ) ;
69+ $ data_sql_path = database_path () . self :: DATA_SQL_PATH_SUFFIX ;
7070
71- $ data_sql_path = database_path () . self ::DATA_SQL_PATH_SUFFIX ;
71+ $ method = $ db_config ['driver ' ] . 'DataDump ' ;
72+ $ exit_code = self ::{$ method }($ db_config , $ data_sql_path );
7273
73- $ method = $ db_config ['driver ' ] . 'DataDump ' ;
74- $ exit_code = self ::{$ method }($ db_config , $ data_sql_path );
74+ if (0 !== $ exit_code ) {
75+ if (file_exists ($ data_sql_path )) {
76+ unlink ($ data_sql_path );
77+ }
7578
76- if (0 !== $ exit_code ) {
77- if (file_exists ($ data_sql_path )) {
78- unlink ($ data_sql_path );
79+ exit ($ exit_code );
7980 }
80-
81- exit ($ exit_code );
8281 }
8382
8483 $ this ->info ('Dumped Data ' );
84+
85+ $ after_dump = config ('migration-snapshot.after-dump ' );
86+ if ($ after_dump ) {
87+ $ after_dump ($ schema_sql_path , $ data_sql_path );
88+ $ this ->info ('Ran After-dump ' );
89+ }
8590 }
8691
8792 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use OrisIntel \MigrationSnapshot \Commands \MigrateDumpCommand ;
4+ use OrisIntel \MigrationSnapshot \Tests \TestCase ;
5+
6+ class MigrateDumpTest extends TestCase
7+ {
8+ protected function getEnvironmentSetUp ($ app )
9+ {
10+ parent ::getEnvironmentSetUp ($ app );
11+ $ app ['config ' ]->set (
12+ 'migration-snapshot.after-dump ' ,
13+ function ($ schema_sql_path , $ data_sql_path ) {
14+ file_put_contents (
15+ $ schema_sql_path ,
16+ preg_replace (
17+ '~^/\*.*\*/;?[\r\n]+~mu ' , // Remove /**/ comments.
18+ '' ,
19+ file_get_contents ($ schema_sql_path )
20+ )
21+ );
22+ }
23+ );
24+ }
25+
26+ public function test_dump_callsAfterDumpClosure ()
27+ {
28+ $ this ->createTestTablesWithoutMigrate ();
29+ // TODO: Fix inclusion of `, ['--quiet' => true]` here breaking test.
30+ $ result = \Artisan::call ('migrate:dump ' );
31+ $ this ->assertEquals (0 , $ result );
32+
33+ $ schema_sql = file_get_contents (
34+ database_path () . MigrateDumpCommand::SCHEMA_SQL_PATH_SUFFIX
35+ );
36+ $ this ->assertNotContains ('/* ' , $ schema_sql );
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments