8
8
9
9
final class MigrateDumpCommand extends Command
10
10
{
11
- public const SCHEMA_SQL_PATH_SUFFIX = '/migrations/sql/schema.sql ' ;
12
- public const DATA_SQL_PATH_SUFFIX = '/migrations/sql/data.sql ' ;
13
-
14
11
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. ' ;
15
14
16
15
protected $ signature = 'migrate:dump
17
16
{--database= : The database connection to use}
@@ -22,23 +21,19 @@ final class MigrateDumpCommand extends Command
22
21
23
22
public function handle ()
24
23
{
25
- $ exit_code = null ;
26
-
27
24
$ database = $ this ->option ('database ' ) ?: DB ::getDefaultConnection ();
28
25
DB ::setDefaultConnection ($ database );
29
26
$ db_config = DB ::getConfig ();
30
27
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 ' ]);
34
29
$ schema_sql_directory = dirname ($ schema_sql_path );
35
30
if (! file_exists ($ schema_sql_directory )) {
36
31
mkdir ($ schema_sql_directory , 0755 );
37
32
}
38
33
39
34
if (! in_array ($ db_config ['driver ' ], self ::SUPPORTED_DB_DRIVERS , true )) {
40
35
throw new \InvalidArgumentException (
41
- 'Unsupported DB driver ' . var_export ($ db_config ['driver ' ], 1 )
36
+ 'Unsupported database driver ' . var_export ($ db_config ['driver ' ], 1 )
42
37
);
43
38
}
44
39
@@ -61,13 +56,13 @@ public function handle()
61
56
exit ($ exit_code ); // CONSIDER: Returning instead.
62
57
}
63
58
64
- $ this ->info ('Dumped schema ' );
59
+ $ this ->info ('Dumped ' . $ db_config [ ' driver ' ] . ' schema ' );
65
60
66
61
$ data_path = null ;
67
62
if ($ this ->option ('include-data ' )) {
68
63
$ this ->info ('Starting Data Dump ' );
69
64
70
- $ data_path = database_path () . self ::DATA_SQL_PATH_SUFFIX ;
65
+ $ data_path = self ::getDataSqlPath ( $ db_config [ ' driver ' ]) ;
71
66
if ('pgsql ' === $ db_config ['driver ' ]) {
72
67
$ data_path = preg_replace ('/\.sql$/ ' , '.pgdump ' , $ data_path );
73
68
}
@@ -134,6 +129,16 @@ public static function reorderMigrationRows(array $output) : array
134
129
return $ output ;
135
130
}
136
131
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
+
137
142
/**
138
143
* @param array $db_config like ['host' => , 'port' => ].
139
144
* @param string $schema_sql_path like '.../schema.sql'
0 commit comments