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 44
44
|
45
45
*/
46
46
'trim-underscores ' => env ('MIGRATION_SNAPSHOT_TRIM_UNDERSCORES ' , true ),
47
-
47
+
48
48
/*
49
49
|--------------------------------------------------------------------------
50
50
| Include Data
56
56
|
57
57
*/
58
58
'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 ,
59
73
];
Original file line number Diff line number Diff line change @@ -62,26 +62,31 @@ public function handle()
62
62
63
63
$ this ->info ('Dumped schema ' );
64
64
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 ' );
68
68
69
- $ this -> info ( ' Starting Data Dump ' ) ;
69
+ $ data_sql_path = database_path () . self :: DATA_SQL_PATH_SUFFIX ;
70
70
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 );
72
73
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
+ }
75
78
76
- if (0 !== $ exit_code ) {
77
- if (file_exists ($ data_sql_path )) {
78
- unlink ($ data_sql_path );
79
+ exit ($ exit_code );
79
80
}
80
-
81
- exit ($ exit_code );
82
81
}
83
82
84
83
$ 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
+ }
85
90
}
86
91
87
92
/**
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