Fix #8298: Loading fixtures does not update table sequence for Postgresql database

This commit is contained in:
Stefano D. Mtangoo
2025-04-02 12:22:20 +03:00
committed by GitHub
parent 16f50626e1
commit 2e8f686b98
4 changed files with 25 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ Yii Framework 2 Change Log
- Enh #20309: Add custom attributes support to style tags (nzwz)
- Bug #20329: pgsql: Column Schema doesn't recognize PG type cast (arkhamvm)
- Bug #8298: Loading fixtures does not update table sequence for Postgresql database (mtangoo)
2.0.52 February 13, 2025

View File

@@ -51,6 +51,10 @@ if you want to upgrade from version A to version C and there is
version B between A and C, you need to follow the instructions
for both A and B.
Upgrade from Yii 2.0.52
-----------------------
* There was a bug when loading fixtures into PostgreSQL database, the table sequences were not reset. If you used a work-around or if you depended on this behavior, you are advised to review your code.
Upgrade from Yii 2.0.51
-----------------------

View File

@@ -1,4 +1,5 @@
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
@@ -85,6 +86,9 @@ class ActiveFixture extends BaseActiveFixture
$primaryKeys = $this->db->schema->insert($table->fullName, $row);
$this->data[$alias] = array_merge($row, $primaryKeys);
}
if ($table->sequenceName !== null) {
$this->db->createCommand()->executeResetSequence($table->fullName);
}
}
/**

View File

@@ -1,4 +1,5 @@
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
@@ -7,6 +8,8 @@
namespace yiiunit\framework\db\pgsql;
use yiiunit\framework\test\CustomerDbTestCase;
/**
* @group db
* @group pgsql
@@ -15,4 +18,17 @@ namespace yiiunit\framework\db\pgsql;
class ActiveFixtureTest extends \yiiunit\framework\test\ActiveFixtureTest
{
public $driverName = 'pgsql';
public function testFixturesLoadingResetsSeqence()
{
$test = new CustomerDbTestCase();
$test->setUp();
$fixture = $test->getFixture('customers');
$sequenceName = $fixture->getTableSchema()->sequenceName;
$sequenceNextVal = $this->getConnection()->createCommand("SELECT currval('$sequenceName')")->queryScalar();
$this->assertEquals($fixture->getModel('customer2')->id + 1, $sequenceNextVal);
$test->tearDown();
}
}