mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Restarting sequences by default qhen calling DboSource::truncate(), removing option to drop the sequence as it does not match behavior from other dbos
This commit is contained in:
parent
2262844346
commit
88289f071e
1 changed files with 4 additions and 8 deletions
|
@ -308,20 +308,16 @@ class DboPostgres extends DboSource {
|
|||
* 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;
|
||||
|
|
Loading…
Reference in a new issue