SQLiteMigrator.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. */
  24. namespace OC\DB;
  25. use Doctrine\DBAL\Schema\Schema;
  26. use Doctrine\DBAL\Types\BigIntType;
  27. use Doctrine\DBAL\Types\Type;
  28. class SQLiteMigrator extends Migrator {
  29. /**
  30. * @param Schema $targetSchema
  31. * @param \Doctrine\DBAL\Connection $connection
  32. * @return \Doctrine\DBAL\Schema\SchemaDiff
  33. */
  34. protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
  35. $platform = $connection->getDatabasePlatform();
  36. $platform->registerDoctrineTypeMapping('tinyint unsigned', 'integer');
  37. $platform->registerDoctrineTypeMapping('smallint unsigned', 'integer');
  38. $platform->registerDoctrineTypeMapping('varchar ', 'string');
  39. // with sqlite autoincrement columns is of type integer
  40. foreach ($targetSchema->getTables() as $table) {
  41. foreach ($table->getColumns() as $column) {
  42. if ($column->getType() instanceof BigIntType && $column->getAutoincrement()) {
  43. $column->setType(Type::getType('integer'));
  44. }
  45. }
  46. }
  47. return parent::getDiff($targetSchema, $connection);
  48. }
  49. }