-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathDBDiff.php
More file actions
56 lines (44 loc) · 1.47 KB
/
DBDiff.php
File metadata and controls
56 lines (44 loc) · 1.47 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php namespace DBDiff;
use DBDiff\Params\ParamsFactory;
use DBDiff\DB\DiffCalculator;
use DBDiff\SQLGen\SQLGenerator;
use DBDiff\Exceptions\BaseException;
use DBDiff\Logger;
use DBDiff\Templater;
class DBDiff {
public function run() {
// Increase memory limit
ini_set('memory_limit', '512M');
try {
$params = ParamsFactory::get();
// Diff
$diffCalculator = new DiffCalculator;
$diff = $diffCalculator->getDiff($params);
// Empty diff
if (empty($diff['schema']) && empty($diff['data'])) {
Logger::info("Identical resources");
} else {
// SQL
$sqlGenerator = new SQLGenerator($diff);
$up =''; $down = '';
if ($params->include !== 'down') {
$up = $sqlGenerator->getUp();
}
if ($params->include !== 'up') {
$down = $sqlGenerator->getDown();
}
// Generate
$templater = new Templater($params, $up, $down);
$templater->output();
}
Logger::success("Completed");
} catch (\Exception $e) {
if ($e instanceof BaseException) {
Logger::error($e->getMessage(), true);
} else {
Logger::error("Unexpected error: " . $e->getMessage());
throw $e;
}
}
}
}