Merge branch 'nojimage-db-postgres-rename-field'

Fixes #3622
This commit is contained in:
mark_story 2013-02-13 22:48:56 -05:00
commit afbc6d84b0
2 changed files with 26 additions and 0 deletions

View file

@ -526,6 +526,12 @@ class Postgres extends DboSource {
$default = isset($col['default']) ? $col['default'] : null; $default = isset($col['default']) ? $col['default'] : null;
$nullable = isset($col['null']) ? $col['null'] : null; $nullable = isset($col['null']) ? $col['null'] : null;
unset($col['default'], $col['null']); unset($col['default'], $col['null']);
if ($field !== $col['name']) {
$newName = $this->name($col['name']);
$out .= "\tRENAME {$fieldName} TO {$newName};\n";
$out .= 'ALTER TABLE ' . $this->fullTableName($curTable) . " \n";
$fieldName = $newName;
}
$colList[] = 'ALTER COLUMN ' . $fieldName . ' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col)); $colList[] = 'ALTER COLUMN ' . $fieldName . ' TYPE ' . str_replace(array($fieldName, 'NOT NULL'), '', $this->buildColumn($col));
if (isset($nullable)) { if (isset($nullable)) {
$nullable = ($nullable) ? 'DROP NOT NULL' : 'SET NOT NULL'; $nullable = ($nullable) ? 'DROP NOT NULL' : 'SET NOT NULL';

View file

@ -739,6 +739,25 @@ class PostgresTest extends CakeTestCase {
$this->Dbo->query($this->Dbo->dropSchema($schema1)); $this->Dbo->query($this->Dbo->dropSchema($schema1));
} }
/**
* Test the alterSchema RENAME statements
*
* @return void
*/
public function testAlterSchemaRenameTo() {
$query = $this->Dbo->alterSchema(array(
'posts' => array(
'change' => array(
'title' => array('name' => 'subject', 'type' => 'string', 'null' => false)
)
)
));
$this->assertContains('RENAME "title" TO "subject";', $query);
$this->assertContains('ALTER COLUMN "subject" TYPE', $query);
$this->assertNotContains(";\n\tALTER COLUMN \"subject\" TYPE", $query);
$this->assertNotContains('ALTER COLUMN "title" TYPE "subject"', $query);
}
/** /**
* Test it is possible to use virtual field with postgresql * Test it is possible to use virtual field with postgresql
* *
@ -922,6 +941,7 @@ class PostgresTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testNestedTransaction() { public function testNestedTransaction() {
$this->Dbo->useNestedTransactions = true;
$this->skipIf($this->Dbo->nestedTransactionSupported() === false, 'The Postgres server do not support nested transaction'); $this->skipIf($this->Dbo->nestedTransactionSupported() === false, 'The Postgres server do not support nested transaction');
$this->loadFixtures('Article'); $this->loadFixtures('Article');