-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdb_init.php
More file actions
40 lines (30 loc) · 1.34 KB
/
db_init.php
File metadata and controls
40 lines (30 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace Deployer;
use SourceBroker\DeployerExtendedDatabase\Utility\OptionUtility;
/**
* Check for missing database: Run database updateschema + import database of base branch
*/
task('db:init', function () {
$optionUtility = new OptionUtility(input()->getOption('options'));
$baseBranch = $optionUtility->getOption('txBaseBranch');
// abort if feature branch has already been configured
if (!$baseBranch || !get('argument_host')) {
return;
}
$activePath = get('deploy_path') . '/' . (test('[ -L {{deploy_path}}/release ]') ? 'release' : 'current');
$hasPageTable = (boolean)run('cd ' . $activePath . ' && echo "SHOW TABLES LIKE \'pages\';" | {{bin/php}} {{local/bin/typo3}} database:import');
// no database import if pages table exists
if ($hasPageTable) {
return;
}
$targetHost = get('argument_host');
$baseStage = str_replace(strtolower(get('branch')), strtolower($baseBranch), $targetHost);
// update schema (db:import would fail with empty database)
run('cd ' . $activePath . ' && {{bin/php}} {{local/bin/typo3}} database:updateschema');
// abort in case base is target
if ($baseStage === $targetHost) {
return;
}
// copy database from base branch
runLocally('{{local/bin/deployer}} db:copy ' . $baseStage . ' --options=target:' . $targetHost);
});