OCPostgreSqlPlatformTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2017 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Test\DB;
  8. use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
  9. use Doctrine\DBAL\Schema\Comparator;
  10. use Doctrine\DBAL\Schema\Schema;
  11. use Doctrine\DBAL\Types\Types;
  12. /**
  13. * Class OCPostgreSqlPlatformTest
  14. *
  15. * custom OCPostgreSqlPlatform behavior has been upstreamed, test is left to
  16. * ensure behavior stays correct.
  17. *
  18. * @group DB
  19. *
  20. * @package Test\DB
  21. */
  22. class OCPostgreSqlPlatformTest extends \Test\TestCase {
  23. public function testAlterBigint() {
  24. $platform = new PostgreSQL100Platform();
  25. $sourceSchema = new Schema();
  26. $targetSchema = new Schema();
  27. $this->createTableAndColumn($sourceSchema, Types::INTEGER);
  28. $this->createTableAndColumn($targetSchema, Types::BIGINT);
  29. $comparator = new Comparator();
  30. $diff = $comparator->compare($sourceSchema, $targetSchema);
  31. $sqlStatements = $diff->toSql($platform);
  32. $this->assertContains(
  33. 'ALTER TABLE poor_yorick ALTER id TYPE BIGINT',
  34. $sqlStatements,
  35. true
  36. );
  37. $this->assertNotContains(
  38. 'ALTER TABLE poor_yorick ALTER id DROP DEFAULT',
  39. $sqlStatements,
  40. true
  41. );
  42. }
  43. protected function createTableAndColumn($schema, $type) {
  44. $table = $schema->createTable("poor_yorick");
  45. $table->addColumn('id', $type, [
  46. 'autoincrement' => true,
  47. 'unsigned' => true,
  48. 'notnull' => true,
  49. 'length' => 11,
  50. ]);
  51. }
  52. }