|
15 | 15 | 'public/themes/contrib',
|
16 | 16 | ]);
|
17 | 17 |
|
18 |
| -desc('Execute database update & config import'); |
| 18 | +desc('Execute drush update & config import'); |
19 | 19 | 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'); |
22 | 22 | })->once();
|
23 | 23 |
|
24 |
| -desc('Backup production config'); |
| 24 | +desc('Execute drush config:export to backup previous config'); |
25 | 25 | 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); |
36 | 43 | });
|
37 | 44 | before('deploy:drush', 'drush:config:backup');
|
0 commit comments