Skip to content

Commit

Permalink
BcDatabaseService::updateSequence() ユニットテスト調整 (#3900)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
  • Loading branch information
HungDV2022 and dovanhung authored Oct 16, 2024
1 parent 360cd14 commit 96fe6a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions plugins/baser-core/src/Service/BcDatabaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,14 +663,15 @@ public function initSystemData($options = []): bool
* データベースシーケンスをアップデートする
* @checked
* @noTodo
* @unitTest
*/
public function updateSequence()
{
$db = ConnectionManager::get('default');
if($db->config()['driver'] !== Postgres::class) return true;
if ($db->config()['driver'] !== Postgres::class) return true;
$tables = $db->getSchemaCollection()->listTables();
$result = true;
foreach($tables as $table) {
foreach ($tables as $table) {
if (preg_match('/(^|_)phinxlog$/', $table)) continue;
$sql = 'select setval(\'' . $this->getSequence($table) . '\', (select max(id) from ' . $table . '));';
if (!$db->execute($sql)) $result = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Cake\Database\Driver\Mysql;
use Cake\Database\Driver\Postgres;
use Cake\Database\Driver\Sqlite;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\Utility\Inflector;
Expand Down Expand Up @@ -1036,4 +1037,14 @@ public function test_columnExists()
// drop table
$this->BcDatabaseService->dropTable($table);
}

/**
* test updateSequence
* @TODO PostgreSQLのテスト
*/
public function testUpdateSequence()
{
// デフォルトdriver:MYSQL
$this->assertTrue($this->BcDatabaseService->updateSequence());
}
}

0 comments on commit 96fe6a5

Please sign in to comment.