Skip to content

Commit

Permalink
Restarting sequences by default qhen calling DboSource::truncate(), r…
Browse files Browse the repository at this point in the history
…emoving option to drop the sequence as it does not match behavior from other dbos
  • Loading branch information
lorenzo committed Oct 21, 2010
1 parent 2262844 commit 88289f0
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions cake/libs/model/datasources/dbo/dbo_postgres.php
Expand Up @@ -308,20 +308,16 @@ function getSequence($table, $field = 'id') {
* Deletes all the records in a table and drops all associated auto-increment sequences
*
* @param mixed $table A string or model class representing the table to be truncated
* @param integer $reset If -1, sequences are dropped, if 0 (default), sequences are reset,
* @param boolean $reset true for resseting the sequence, false to leave it as is.
* and if 1, sequences are not modified
* @return boolean SQL TRUNCATE TABLE statement, false if not applicable.
*/
public function truncate($table, $reset = 0) {
public function truncate($table, $reset = true) {
if (parent::truncate($table)) {
$table = $this->fullTableName($table, false);
if (isset($this->_sequenceMap[$table]) && $reset !== 1) {
if (isset($this->_sequenceMap[$table]) && $reset) {
foreach ($this->_sequenceMap[$table] as $field => $sequence) {
if ($reset === 0) {
$this->_execute("ALTER SEQUENCE \"{$sequence}\" RESTART WITH 1");
} elseif ($reset === -1) {
$this->_execute("DROP SEQUENCE IF EXISTS \"{$sequence}\"");
}
$this->_execute("ALTER SEQUENCE \"{$sequence}\" RESTART WITH 1");
}
}
return true;
Expand Down

0 comments on commit 88289f0

Please sign in to comment.