2017-09-29 09:07:50 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2017, ownCloud GmbH
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2017-11-17 14:48:10 +00:00
|
|
|
|
2017-09-29 09:07:50 +00:00
|
|
|
namespace Test\DB;
|
|
|
|
|
2017-11-17 14:48:10 +00:00
|
|
|
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
|
2017-09-29 09:07:50 +00:00
|
|
|
use Doctrine\DBAL\Schema\Comparator;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
|
|
use Doctrine\DBAL\Types\Type;
|
2017-11-17 14:48:10 +00:00
|
|
|
|
|
|
|
/**
|
2017-09-29 09:07:50 +00:00
|
|
|
* Class OCPostgreSqlPlatformTest
|
|
|
|
*
|
2017-11-17 14:48:10 +00:00
|
|
|
* custom OCPostgreSqlPlatform behavior has been upstreamed, test is left to
|
|
|
|
* ensure behavior stays correct.
|
|
|
|
*
|
2017-09-29 09:07:50 +00:00
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package Test\DB
|
|
|
|
*/
|
|
|
|
class OCPostgreSqlPlatformTest extends \Test\TestCase {
|
|
|
|
|
2017-11-17 14:48:10 +00:00
|
|
|
public function testAlterBigint() {
|
|
|
|
$platform = new PostgreSqlPlatform();
|
2017-09-29 09:07:50 +00:00
|
|
|
$sourceSchema = new Schema();
|
|
|
|
$targetSchema = new Schema();
|
2017-11-17 14:48:10 +00:00
|
|
|
|
2017-09-29 09:07:50 +00:00
|
|
|
$this->createTableAndColumn($sourceSchema, Type::INTEGER);
|
|
|
|
$this->createTableAndColumn($targetSchema, Type::BIGINT);
|
2017-11-17 14:48:10 +00:00
|
|
|
|
2017-09-29 09:07:50 +00:00
|
|
|
$comparator = new Comparator();
|
|
|
|
$diff = $comparator->compare($sourceSchema, $targetSchema);
|
|
|
|
$sqlStatements = $diff->toSql($platform);
|
|
|
|
$this->assertContains(
|
|
|
|
'ALTER TABLE poor_yorick ALTER id TYPE BIGINT',
|
|
|
|
$sqlStatements,
|
|
|
|
true
|
|
|
|
);
|
2017-11-17 14:48:10 +00:00
|
|
|
|
2017-09-29 09:07:50 +00:00
|
|
|
$this->assertNotContains(
|
|
|
|
'ALTER TABLE poor_yorick ALTER id DROP DEFAULT',
|
|
|
|
$sqlStatements,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
2017-11-17 14:48:10 +00:00
|
|
|
|
|
|
|
protected function createTableAndColumn($schema, $type) {
|
2017-09-29 09:07:50 +00:00
|
|
|
$table = $schema->createTable("poor_yorick");
|
|
|
|
$table->addColumn('id', $type, [
|
|
|
|
'autoincrement' => true,
|
2017-11-17 14:48:10 +00:00
|
|
|
'unsigned' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 11,
|
2017-09-29 09:07:50 +00:00
|
|
|
]);
|
|
|
|
}
|
2017-11-17 14:48:10 +00:00
|
|
|
|
2017-09-29 09:07:50 +00:00
|
|
|
}
|