88
99final class MigrateDumpCommand extends Command
1010{
11- public const SCHEMA_SQL_PATH_SUFFIX = '/migrations/sql/schema.sql ' ;
12- public const DATA_SQL_PATH_SUFFIX = '/migrations/sql/data.sql ' ;
13-
1411 public const SUPPORTED_DB_DRIVERS = ['mysql ' , 'pgsql ' , 'sqlite ' ];
12+ protected const SCHEMA_SQL_PATH_SUFFIX = 'migrations/sql/schema. ' ;
13+ protected const DATA_SQL_PATH_SUFFIX = 'migrations/sql/data. ' ;
1514
1615 protected $ signature = 'migrate:dump
1716 {--database= : The database connection to use}
@@ -22,23 +21,19 @@ final class MigrateDumpCommand extends Command
2221
2322 public function handle ()
2423 {
25- $ exit_code = null ;
26-
2724 $ database = $ this ->option ('database ' ) ?: DB ::getDefaultConnection ();
2825 DB ::setDefaultConnection ($ database );
2926 $ db_config = DB ::getConfig ();
3027
31- // CONSIDER: Ending with ".mysql" or "-mysql.sql" unless in
32- // compatibility mode.
33- $ schema_sql_path = database_path () . self ::SCHEMA_SQL_PATH_SUFFIX ;
28+ $ schema_sql_path = self ::getSchemaSqlPath ($ db_config ['driver ' ]);
3429 $ schema_sql_directory = dirname ($ schema_sql_path );
3530 if (! file_exists ($ schema_sql_directory )) {
3631 mkdir ($ schema_sql_directory , 0755 );
3732 }
3833
3934 if (! in_array ($ db_config ['driver ' ], self ::SUPPORTED_DB_DRIVERS , true )) {
4035 throw new \InvalidArgumentException (
41- 'Unsupported DB driver ' . var_export ($ db_config ['driver ' ], 1 )
36+ 'Unsupported database driver ' . var_export ($ db_config ['driver ' ], 1 )
4237 );
4338 }
4439
@@ -61,13 +56,13 @@ public function handle()
6156 exit ($ exit_code ); // CONSIDER: Returning instead.
6257 }
6358
64- $ this ->info ('Dumped schema ' );
59+ $ this ->info ('Dumped ' . $ db_config [ ' driver ' ] . ' schema ' );
6560
6661 $ data_path = null ;
6762 if ($ this ->option ('include-data ' )) {
6863 $ this ->info ('Starting Data Dump ' );
6964
70- $ data_path = database_path () . self ::DATA_SQL_PATH_SUFFIX ;
65+ $ data_path = self ::getDataSqlPath ( $ db_config [ ' driver ' ]) ;
7166 if ('pgsql ' === $ db_config ['driver ' ]) {
7267 $ data_path = preg_replace ('/\.sql$/ ' , '.pgdump ' , $ data_path );
7368 }
@@ -134,6 +129,16 @@ public static function reorderMigrationRows(array $output) : array
134129 return $ output ;
135130 }
136131
132+ public static function getSchemaSqlPath (string $ driver ) : string
133+ {
134+ return database_path (self ::SCHEMA_SQL_PATH_SUFFIX . $ driver . '.sql ' );
135+ }
136+
137+ public static function getDataSqlPath (string $ driver ) : string
138+ {
139+ return database_path (self ::DATA_SQL_PATH_SUFFIX . $ driver . '.sql ' );
140+ }
141+
137142 /**
138143 * @param array $db_config like ['host' => , 'port' => ].
139144 * @param string $schema_sql_path like '.../schema.sql'
0 commit comments