-
-
Save doctrinebot/8b6517fdcb3807a7764b to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DBAL-37 - https://github.com/doctrine/dbal/issues/1559
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: PostgreSqlPlatform.php | |
=================================================================== | |
--- PostgreSqlPlatform.php (revision 674) | |
+++ PostgreSqlPlatform.php (revision 696) | |
@@ -340,7 +340,7 @@ | |
public function getAlterTableSQL(TableDiff $diff) | |
{ | |
$sql = array(); | |
- | |
+ //var_dump($diff); | |
foreach ($diff->addedColumns as $column) { | |
$query = 'ADD ' . $this->getColumnDeclarationSQL($column->getName(), $column->toArray()); | |
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; | |
@@ -370,10 +370,30 @@ | |
$query = 'ALTER ' . $oldColumnName . ' ' . ($column->getNotNull() ? 'SET' : 'DROP') . ' NOT NULL'; | |
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; | |
} | |
+ if ($columnDiff->hasChanged('autoincrement')) { | |
+ //var_dump($columnDiff); | |
+ $createSeq = ''; | |
+ $seqName = $diff->name . '_' . $oldColumnName . '_seq'; | |
+ if ($column->getAutoincrement()) { | |
+ // create new seq | |
+ $createSeq = 'CREATE SEQUENCE ' . $seqName . '; '; | |
+ $sql[] = $createSeq; | |
+ $query = 'ALTER ' . $oldColumnName . ' ' . 'SET DEFAULT NEXTVAL (' . "'{$seqName}')"; | |
+ $sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; | |
+ $sql[] = 'SELECT SETVAL(' . "'{$seqName}'" . ', (SELECT MAX(' . $oldColumnName . ') FROM ' . $diff->name . '))'; | |
+ } else { | |
+ // should be dropped? | |
+ //$dropSeq = 'DROP SEQUENCE ' . $seqName . '; '; | |
+ //$sql[] = $dropSeq; | |
+ $query = 'ALTER ' . $oldColumnName . ' ' . 'DROP DEFAULT'; | |
+ $sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; | |
+ $dropSeq = 'DROP SEQUENCE ' . $seqName . '; '; | |
+ $sql[] = $dropSeq; | |
+ } | |
+ | |
+ } | |
} | |
- | |
- foreach ($diff->renamedColumns as $oldColumnName => $column) { | |
- $sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME COLUMN ' . $oldColumnName . ' TO ' . $column->getName(); | |
+foreach ($diff->renamedColumns as $oldColumnName => $column) { $sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME COLUMN ' . $oldColumnName . ' TO ' . $column->getName(); | |
} | |
if ($diff->newName !== false) { | |
@@ -381,7 +401,7 @@ | |
} | |
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff)); | |
- | |
+var_dump($sql); | |
return $sql; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment