Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion config/migration-snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
|
*/
'trim-underscores' => env('MIGRATION_SNAPSHOT_TRIM_UNDERSCORES', true),

/*
|--------------------------------------------------------------------------
| Include Data
Expand All @@ -56,4 +56,15 @@
|
*/
'data' => env('MIGRATION_SNAPSHOT_DATA', false),

/*
|--------------------------------------------------------------------------
| Data Excluded
|--------------------------------------------------------------------------
|
| Comma separated table names to exclude when dumping with data. (The
| "migrations" table will always be excluded regardless.)
|
*/
'data-excluded' => env('MIGRATION_SNAPSHOT_DATA_EXCLUDED', ''),
];
41 changes: 33 additions & 8 deletions src/Commands/MigrateDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,16 @@ private static function mysqlSchemaDump(array $db_config, string $schema_sql_pat
*/
private static function mysqlDataDump(array $db_config, string $data_sql_path) : int
{
passthru(
static::mysqlCommandPrefix($db_config)
$command = static::mysqlCommandPrefix($db_config)
. ' --result-file=' . escapeshellarg($data_sql_path)
. ' --no-create-info --skip-triggers'
. ' --ignore-table=' . escapeshellarg($db_config['database'] . '.migrations'),
. ' --no-create-info --skip-comments --skip-triggers'
. ' --ignore-table=' . escapeshellarg($db_config['database'] . '.migrations');
foreach (static::dataExcluded() as $table) {
$command .= ' --ignore-table=' . escapeshellarg($db_config['database'] . '.' . $table);
}

passthru(
$command,
$exit_code
);

Expand Down Expand Up @@ -343,11 +348,15 @@ function ($line) {
*/
private static function pgsqlDataDump(array $db_config, string $data_sql_path) : int
{
passthru(
static::pgsqlCommandPrefix($db_config)
$command = static::pgsqlCommandPrefix($db_config)
. ' --file=' . escapeshellarg($data_sql_path)
. ' --exclude-table=' . escapeshellarg($db_config['database'] . '.migrations')
. ' --data-only',
. ' --data-only';
foreach (static::dataExcluded() as $table) {
$command .= ' --exclude-table=' . escapeshellarg($db_config['database'] . '.' . $table);
}
passthru(
$command,
$exit_code
);

Expand Down Expand Up @@ -452,7 +461,10 @@ private static function sqliteDataDump(array $db_config, string $data_sql_path)

foreach ($tables as $table) {
// We don't want to dump the migrations table here
if ('migrations' === $table) {
if (
'migrations' === $table
|| in_array($table, static::dataExcluded(), true)
) {
continue;
}

Expand All @@ -479,4 +491,17 @@ private static function sqliteDataDump(array $db_config, string $data_sql_path)

return $exit_code;
}

private static function dataExcluded() : array
{
$data_excluded = config('migration-snapshot.data-excluded');
if (is_iterable($data_excluded)) {
return $data_excluded;
}
return array_filter(
explode(',',
$data_excluded
)
);
}
}