Skip to content

Commit

Permalink
Trucating tables in postgres now correctly resets the associated sequ…
Browse files Browse the repository at this point in the history
…ences
  • Loading branch information
lorenzo committed Oct 26, 2010
1 parent f00f4ea commit 49ed8ed
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cake/libs/model/datasources/dbo/dbo_postgres.php
Expand Up @@ -221,10 +221,12 @@ function &describe(&$model) {
),
'length' => $length
);
if ($c->name == $model->primaryKey) {
$fields[$c->name]['key'] = 'primary';
if ($fields[$c->name]['type'] !== 'string') {
$fields[$c->name]['length'] = 11;
if ($model instanceof Model) {
if ($c->name == $model->primaryKey) {
$fields[$c->name]['key'] = 'primary';
if ($fields[$c->name]['type'] !== 'string') {
$fields[$c->name]['length'] = 11;
}
}
}
if (
Expand Down Expand Up @@ -284,8 +286,14 @@ function getSequence($table, $field = 'id') {
* @return boolean SQL TRUNCATE TABLE statement, false if not applicable.
*/
public function truncate($table, $reset = true) {
$table = $this->fullTableName($table, false);
if (!isset($this->_sequenceMap[$table])) {
$cache = $this->cacheSources;
$this->cacheSources = false;
$this->describe($table);
$this->cacheSources = $cache;
}
if (parent::truncate($table)) {
$table = $this->fullTableName($table, false);
if (isset($this->_sequenceMap[$table]) && $reset) {
foreach ($this->_sequenceMap[$table] as $field => $sequence) {
$this->_execute("ALTER SEQUENCE \"{$sequence}\" RESTART WITH 1");
Expand Down

0 comments on commit 49ed8ed

Please sign in to comment.