You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OCPostgreSqlPlatformTest.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2017, ownCloud GmbH
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\DB;
  22. use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
  23. use Doctrine\DBAL\Schema\Comparator;
  24. use Doctrine\DBAL\Schema\Schema;
  25. use Doctrine\DBAL\Types\Types;
  26. /**
  27. * Class OCPostgreSqlPlatformTest
  28. *
  29. * custom OCPostgreSqlPlatform behavior has been upstreamed, test is left to
  30. * ensure behavior stays correct.
  31. *
  32. * @group DB
  33. *
  34. * @package Test\DB
  35. */
  36. class OCPostgreSqlPlatformTest extends \Test\TestCase {
  37. public function testAlterBigint() {
  38. $platform = new PostgreSQL100Platform();
  39. $sourceSchema = new Schema();
  40. $targetSchema = new Schema();
  41. $this->createTableAndColumn($sourceSchema, Types::INTEGER);
  42. $this->createTableAndColumn($targetSchema, Types::BIGINT);
  43. $comparator = new Comparator();
  44. $diff = $comparator->compare($sourceSchema, $targetSchema);
  45. $sqlStatements = $diff->toSql($platform);
  46. $this->assertContains(
  47. 'ALTER TABLE poor_yorick ALTER id TYPE BIGINT',
  48. $sqlStatements,
  49. true
  50. );
  51. $this->assertNotContains(
  52. 'ALTER TABLE poor_yorick ALTER id DROP DEFAULT',
  53. $sqlStatements,
  54. true
  55. );
  56. }
  57. protected function createTableAndColumn($schema, $type) {
  58. $table = $schema->createTable("poor_yorick");
  59. $table->addColumn('id', $type, [
  60. 'autoincrement' => true,
  61. 'unsigned' => true,
  62. 'notnull' => true,
  63. 'length' => 11,
  64. ]);
  65. }
  66. }