Skip to content

Commit d86a85a

Browse files
authored
Merge pull request #4 from ubc-cpsc/feature/AC-8487-218-backup-config
AC 8487-218: Add checks for empty database and empty .env on drush config
2 parents 81fa922 + 3ac4640 commit d86a85a

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

recipes/drupal8.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,30 @@
1515
'public/themes/contrib',
1616
]);
1717

18-
desc('Execute database update & config import');
18+
desc('Execute drush update & config import');
1919
task('deploy:drush', function () {
20-
// https://www.drush.org/latest/deploycommand/
21-
invoke('drush:deploy');
20+
// https://www.drush.org/latest/deploycommand/
21+
invoke('drush:deploy');
2222
})->once();
2323

24-
desc('Backup production config');
24+
desc('Execute drush config:export to backup previous config');
2525
task('drush:config:backup', function() {
26-
if (has('previous_release')) {
27-
$destination = '{{previous_release}}/config/backup';
28-
}
29-
else {
30-
$destination = '{{release_path}}/config/backup';
31-
}
32-
run("mkdir -p $destination");
33-
cd('{{release_or_current_path}}');
34-
run("./vendor/bin/drush -y config:export --destination=$destination");
35-
writeln('Backup saved to ' . $destination);
26+
// Skip when there aren't database connection variables.
27+
if (! test('[ -s {{release_or_current_path}}/.env ]')) {
28+
writeln("<fg=yellow;options=bold;>Warning: </><fg=yellow;>Your .env file is empty! Skipping...</>");
29+
return;
30+
}
31+
32+
// Skip when there are no tables in the database.
33+
if (test('[[ -z "$(./vendor/bin/drush sql:query \'SHOW TABLES\')" ]]')) {
34+
writeln("<fg=yellow;options=bold;>Warning: </><fg=yellow;>Your database is empty! Skipping...</>");
35+
return;
36+
}
37+
38+
$destination = has('previous_release') ? '{{previous_release}}' : '{{release_path}}';
39+
run("mkdir -p $destination/config/backup");
40+
cd('{{release_or_current_path}}');
41+
run("./vendor/bin/drush -y config:export --destination=$destination");
42+
writeln('Backup saved to ' . $destination);
3643
});
3744
before('deploy:drush', 'drush:config:backup');

0 commit comments

Comments
 (0)