Trucating tables in postgres now correctly resets the associated sequences

This commit is contained in:
José Lorenzo Rodríguez 2010-10-25 19:45:46 -04:30
parent f00f4eae0f
commit 49ed8ede8e

View file

@ -221,10 +221,12 @@ class DboPostgres extends DboSource {
),
'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 (
@ -284,8 +286,14 @@ class DboPostgres extends DboSource {
* @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");