mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
parent
1b22d48a35
commit
fbb1a812dd
2 changed files with 21 additions and 0 deletions
|
@ -526,6 +526,12 @@ class Postgres extends DboSource {
|
|||
$default = isset($col['default']) ? $col['default'] : null;
|
||||
$nullable = isset($col['null']) ? $col['null'] : 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));
|
||||
if (isset($nullable)) {
|
||||
$nullable = ($nullable) ? 'DROP NOT NULL' : 'SET NOT NULL';
|
||||
|
|
|
@ -739,6 +739,21 @@ class PostgresTest extends CakeTestCase {
|
|||
$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->assertRegExp('/RENAME "title" TO "subject";/i', $query);
|
||||
$this->assertRegExp('/ALTER COLUMN "subject" TYPE /i', $query);
|
||||
$this->assertNotRegExp('/;\n\tALTER COLUMN "subject" TYPE /i', $query);
|
||||
$this->assertNotRegExp('/ALTER COLUMN "title" TYPE "subject"/i', $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test it is possible to use virtual field with postgresql
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue