Passed
Push — master ( 459e0b...37feee )
by Morris
12:59 queued 12s
created

MySQLMigrator::checkTableMigrate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 13
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Christoph Wurst <[email protected]>
6
 * @author Morris Jobke <[email protected]>
7
 * @author Robin Appelman <[email protected]>
8
 * @author Thomas Müller <[email protected]>
9
 * @author Victor Dubiniuk <[email protected]>
10
 *
11
 * @license AGPL-3.0
12
 *
13
 * This code is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License, version 3,
15
 * as published by the Free Software Foundation.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License, version 3,
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>
24
 *
25
 */
26
27
namespace OC\DB;
28
29
use Doctrine\DBAL\Schema\Schema;
30
31
class MySQLMigrator extends Migrator {
32
	/**
33
	 * @param Schema $targetSchema
34
	 * @param \Doctrine\DBAL\Connection $connection
35
	 * @return \Doctrine\DBAL\Schema\SchemaDiff
36
	 */
37
	protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
38
		$platform = $connection->getDatabasePlatform();
39
		$platform->registerDoctrineTypeMapping('enum', 'string');
40
		$platform->registerDoctrineTypeMapping('bit', 'string');
41
42
		$schemaDiff = parent::getDiff($targetSchema, $connection);
43
44
		// identifiers need to be quoted for mysql
45
		foreach ($schemaDiff->changedTables as $tableDiff) {
46
			$tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
47
			foreach ($tableDiff->changedColumns as $column) {
48
				$column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
49
			}
50
		}
51
52
		return $schemaDiff;
53
	}
54
}
55