-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathDiffCalculator.php
More file actions
58 lines (46 loc) · 1.66 KB
/
DiffCalculator.php
File metadata and controls
58 lines (46 loc) · 1.66 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
57
58
<?php namespace DBDiff\DB;
use DBDiff\DB\Schema\DBSchema;
use DBDiff\DB\Schema\TableSchema;
use DBDiff\DB\Data\DBData;
use DBDiff\DB\Data\TableData;
use DBDiff\SQLGen\Dialect\DialectRegistry;
class DiffCalculator {
protected $manager;
function __construct() {
$this->manager = new DBManager;
}
public function getDiff($params) {
// Connect and test accessibility
$this->manager->connect($params);
$this->manager->testResources($params);
// Initialise the SQL dialect for this run so all DiffToSQL classes
// generate correctly-quoted SQL for the target driver.
DialectRegistry::setForDriver($this->manager->getDriver());
// Schema diff
$schemaDiff = [];
if ($params->type !== 'data') {
if ($params->input['kind'] === 'db') {
$dbSchema = new DBSchema($this->manager);
$schemaDiff = $dbSchema->getDiff();
} else {
$tableSchema = new TableSchema($this->manager);
$schemaDiff = $tableSchema->getDiff($params->input['source']['table']);
}
}
// Data diff
$dataDiff = [];
if ($params->type !== 'schema') {
if ($params->input['kind'] === 'db') {
$dbData = new DBData($this->manager);
$dataDiff = $dbData->getDiff();
} else {
$tableData = new TableData($this->manager);
$dataDiff = $tableData->getDiff($params->input['source']['table']);
}
}
return [
'schema' => $schemaDiff,
'data' => $dataDiff,
];
}
}