File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,13 @@ Giving your snapshot a name is optional. If you don't pass a name the current da
133133php artisan snapshot:create
134134```
135135
136+ If you pass a connection but do not declare a name for the snapshot, the connection will be prepended
137+
138+ ``` bash
139+ # Creates a snapshot named something like `logging_2017-03-17 14:31`
140+ php artisan snapshot:create --connection=logging
141+ ```
142+
136143Maybe you only want to snapshot a couple of tables. You can do this by passing the ` --table ` multiple times or as a comma separated list:
137144
138145``` bash
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public function handle()
2121 ?: config ('db-snapshots.default_connection ' )
2222 ?? config ('database.default ' );
2323
24- $ snapshotName = $ this ->argument ( ' name ' ) ?? Carbon:: now ()-> format ( ' Y-m-d_H-i-s ' );
24+ $ snapshotName = $ this ->getSnapshotName ( );
2525
2626 $ compress = $ this ->option ('compress ' ) || config ('db-snapshots.compress ' , false );
2727
@@ -49,4 +49,13 @@ public function handle()
4949
5050 $ this ->info ("Snapshot ` {$ snapshotName }` created (size: {$ size }) " );
5151 }
52+
53+ private function getSnapshotName (): string
54+ {
55+ if (!is_null ($ this ->option ('connection ' )) && is_null ($ this ->argument ('name ' ))) {
56+ return $ this ->option ('connection ' ). "_ " . Carbon::now ()->format ('Y-m-d_H-i-s ' );
57+ }
58+
59+ return $ this ->argument ('name ' ) ?? Carbon::now ()->format ('Y-m-d_H-i-s ' );
60+ }
5261}
Original file line number Diff line number Diff line change 1919 ->expect ('test.sql ' )
2020 ->fileOnDiskToPassRegex ('/CREATE TABLE(?: IF NOT EXISTS){0,1} "models"/ ' );
2121
22+ it ('can will prepend the connection to the default name if no specific name is passed ' , function () {
23+
24+ config ()->set ('database.connections.second_connection ' , [
25+ 'driver ' => 'sqlite ' ,
26+ 'database ' => __DIR__ . '/../temp/second_connection.sqlite ' ,
27+ 'prefix ' => '' ,
28+ ]);
29+
30+ Artisan::call ('snapshot:create ' , ['--connection ' => 'second_connection ' ]);
31+ $ fileName = 'second_connection_ ' . Carbon::now ()->format ('Y-m-d_H-i-s ' ) . '.sql ' ;
32+
33+ $ this ->disk ->assertExists ($ fileName );
34+ });
35+
2236it ('can create a compressed snapshot from CLI param ' , function () {
2337 Artisan::call ('snapshot:create ' , ['--compress ' => true ]);
2438
You can’t perform that action at this time.
0 commit comments