1<?php
2/**
3 * @copyright Copyright (c) 2016, ownCloud, Inc.
4 *
5 * @author Robin Appelman <robin@icewind.nl>
6 * @author Thomas Müller <thomas.mueller@tmit.eu>
7 * @author Victor Dubiniuk <dubiniuk@owncloud.com>
8 *
9 * @license AGPL-3.0
10 *
11 * This code is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License, version 3,
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
19 *
20 * You should have received a copy of the GNU Affero General Public License, version 3,
21 * along with this program. If not, see <http://www.gnu.org/licenses/>
22 *
23 */
24namespace OC\DB;
25
26use Doctrine\DBAL\Schema\Schema;
27use Doctrine\DBAL\Types\BigIntType;
28use Doctrine\DBAL\Types\Type;
29
30class SQLiteMigrator extends Migrator {
31
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('tinyint unsigned', 'integer');
40		$platform->registerDoctrineTypeMapping('smallint unsigned', 'integer');
41		$platform->registerDoctrineTypeMapping('varchar ', 'string');
42
43		// with sqlite autoincrement columns is of type integer
44		foreach ($targetSchema->getTables() as $table) {
45			foreach ($table->getColumns() as $column) {
46				if ($column->getType() instanceof BigIntType && $column->getAutoincrement()) {
47					$column->setType(Type::getType('integer'));
48				}
49			}
50		}
51
52		return parent::getDiff($targetSchema, $connection);
53	}
54}
55