Compare commits

..

2 commits

Author SHA1 Message Date
rxu
2c3e0683a8
Merge 51c997aa22 into 2fce8aeb3e 2025-06-11 07:48:34 +00:00
rxu
51c997aa22
[ticket/17524] Add index migrator tests
PHPBB-17524
2025-06-11 14:48:12 +07:00
3 changed files with 12 additions and 11 deletions

View file

@ -514,7 +514,7 @@ class doctrine implements tools_interface
catch (Exception $e) catch (Exception $e)
{ {
// @todo: check if it makes sense to properly handle the exception // @todo: check if it makes sense to properly handle the exception
return [$e->getMessage()]; return false;
} }
} }

View file

@ -26,15 +26,15 @@ class phpbb_dbal_migration_schema extends \phpbb\db\migration\migration
'COLUMNS' => [ 'COLUMNS' => [
'module_id' => ['UINT:3', NULL, 'auto_increment'], 'module_id' => ['UINT:3', NULL, 'auto_increment'],
'user_id' => ['ULINT', 0], 'user_id' => ['ULINT', 0],
'endpoint' => ['VCHAR:220', ''], 'endpoint' => ['TEXT', ''],
'expiration_time' => ['TIMESTAMP', 0], 'expiration_time' => ['TIMESTAMP', 0],
'p256dh' => ['VCHAR:200', ''], 'p256dh' => ['VCHAR', ''],
'auth' => ['VCHAR:100', ''], 'auth' => ['VCHAR:100', ''],
], ],
'PRIMARY_KEY' => 'module_id', 'PRIMARY_KEY' => 'module_id',
'KEYS' => [ 'KEYS' => [
// 'i_simple' => ['INDEX', ['user_id', 'endpoint:191']], 'i_simple' => ['INDEX', ['user_id', 'endpoint:191']],
// 'i_uniq' => ['UNIQUE', ['expiration_time', 'p256dh(100)']], 'i_uniq' => ['UNIQUE', ['expiration_time', 'p256dh(100)']],
'i_auth' => ['INDEX', 'auth'], 'i_auth' => ['INDEX', 'auth'],
], ],
], ],

View file

@ -409,7 +409,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->assertTrue($this->db_tools->sql_table_exists('phpbb_foobar')); $this->assertTrue($this->db_tools->sql_table_exists('phpbb_foobar'));
$index_data_row = $this->db_tools->sql_get_table_index_data('phpbb_foobar'); $index_data_row = $this->db_tools->sql_get_table_index_data('phpbb_foobar');
$mysql = $this->db->get_sql_layer() === 'mysqli'; // Index length only applies to MySQL indexes $is_mysql = $this->db->get_sql_layer() === 'mysqli'; // Index length only applies to MySQL indexes
$is_mssql = in_array($this->db->get_sql_layer(), ['mssqlnative', 'mssql_odbc']); // MSSQL primary index key has 'clustered' flag
foreach ($index_data_row as $index_name => $index_data) foreach ($index_data_row as $index_name => $index_data)
{ {
switch ($index_name) switch ($index_name)
@ -422,9 +423,9 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->assertTrue($index_data['is_simple']); $this->assertTrue($index_data['is_simple']);
$this->assertEquals(2, count($index_data['options']['lengths'])); $this->assertEquals(2, count($index_data['options']['lengths']));
$this->assertEmpty($index_data['options']['lengths'][0]); $this->assertEmpty($index_data['options']['lengths'][0]);
$this->assertEquals($mysql ? 191 : null, $index_data['options']['lengths'][1]); $this->assertEquals($is_mysql ? 191 : null, $index_data['options']['lengths'][1]);
break; break;
/* case 'i_uniq': case 'i_uniq':
$this->assertEquals(['expiration_time', 'p256dh'], $index_data['columns']); $this->assertEquals(['expiration_time', 'p256dh'], $index_data['columns']);
$this->assertEmpty($index_data['flags']); $this->assertEmpty($index_data['flags']);
$this->assertFalse($index_data['is_primary']); $this->assertFalse($index_data['is_primary']);
@ -432,8 +433,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->assertFalse($index_data['is_simple']); $this->assertFalse($index_data['is_simple']);
$this->assertEquals(2, count($index_data['options']['lengths'])); $this->assertEquals(2, count($index_data['options']['lengths']));
$this->assertEmpty($index_data['options']['lengths'][0]); $this->assertEmpty($index_data['options']['lengths'][0]);
$this->assertEquals($mysql ? 100 : null, $index_data['options']['lengths'][1]); $this->assertEquals($is_mysql ? 100 : null, $index_data['options']['lengths'][1]);
break;*/ break;
case 'i_auth': case 'i_auth':
$this->assertEquals(['auth'], $index_data['columns']); $this->assertEquals(['auth'], $index_data['columns']);
$this->assertEmpty($index_data['flags']); $this->assertEmpty($index_data['flags']);
@ -445,7 +446,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
break; break;
default: // Primary key default: // Primary key
$this->assertEquals(['module_id'], $index_data['columns']); $this->assertEquals(['module_id'], $index_data['columns']);
$this->assertEmpty($index_data['flags']); $this->assertEquals($is_mssql ? ['clustered'] : [], $index_data['flags']);
$this->assertTrue($index_data['is_primary']); $this->assertTrue($index_data['is_primary']);
$this->assertTrue($index_data['is_unique']); $this->assertTrue($index_data['is_unique']);
$this->assertFalse($index_data['is_simple']); $this->assertFalse($index_data['is_simple']);