Compare commits

...

5 commits

Author SHA1 Message Date
rxu
be3438d573
Merge e37312c397 into 2fce8aeb3e 2025-06-11 05:23:47 +00:00
rxu
e37312c397
[ticket/17524] Debug what's wrong
PHPBB-17524
2025-06-11 12:23:23 +07:00
rxu
4bdf5ab6d2
[ticket/17524] Do not hit MSSQL index key size limit of 900 bytes
MSSQL index size limitations are 16 key columns and 900 bytes
(prior to SQL Server 2016 (13.x)) and a maximum of 32 key columns
and a maximum index key size of 1,700 bytes (as of SQL Server 2016 (13.x)).

PHPBB-17524
2025-06-10 21:33:24 +07:00
rxu
993e637af9
[ticket/17524] test index key length only on MySQL where it does apply
PHPBB-17524
2025-06-10 15:22:46 +07:00
rxu
83c6ffce64
[ticket/17524] Add index migrator tests
PHPBB-17524
2025-06-10 13:55:48 +07:00
3 changed files with 64 additions and 11 deletions

View file

@ -390,13 +390,9 @@ class doctrine implements tools_interface
* 'is_simple' => (bool) $isSimple, * 'is_simple' => (bool) $isSimple,
* ] * ]
* *
* @param Schema $schema
* @param string $table_name * @param string $table_name
* @param string $column_name
* @param array $column_data
* @param bool $safe_check
* *
* @throws SchemaException * @return array
*/ */
public function sql_get_table_index_data(string $table_name): array public function sql_get_table_index_data(string $table_name): array
{ {
@ -518,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 false; return [$e->getMessage()];
} }
} }

View file

@ -22,12 +22,22 @@ class phpbb_dbal_migration_schema extends \phpbb\db\migration\migration
), ),
), ),
'add_tables' => array( 'add_tables' => array(
$this->table_prefix . 'foobar' => array( $this->table_prefix . 'foobar' => [
'COLUMNS' => array( 'COLUMNS' => [
'module_id' => array('UINT:3', NULL, 'auto_increment'), 'module_id' => ['UINT:3', NULL, 'auto_increment'],
), 'user_id' => ['ULINT', 0],
'endpoint' => ['VCHAR:220', ''],
'expiration_time' => ['TIMESTAMP', 0],
'p256dh' => ['VCHAR:200', ''],
'auth' => ['VCHAR:100', ''],
],
'PRIMARY_KEY' => 'module_id', 'PRIMARY_KEY' => 'module_id',
), 'KEYS' => [
// 'i_simple' => ['INDEX', ['user_id', 'endpoint:191']],
// 'i_uniq' => ['UNIQUE', ['expiration_time', 'p256dh(100)']],
'i_auth' => ['INDEX', 'auth'],
],
],
), ),
); );
} }

View file

@ -408,6 +408,53 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->assertTrue($this->db_tools->sql_column_exists('phpbb_config', 'test_column1')); $this->assertTrue($this->db_tools->sql_column_exists('phpbb_config', 'test_column1'));
$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');
$mysql = $this->db->get_sql_layer() === 'mysqli'; // Index length only applies to MySQL indexes
foreach ($index_data_row as $index_name => $index_data)
{
switch ($index_name)
{
case 'i_simple':
$this->assertEquals(['user_id', 'endpoint'], $index_data['columns']);
$this->assertEmpty($index_data['flags']);
$this->assertFalse($index_data['is_primary']);
$this->assertFalse($index_data['is_unique']);
$this->assertTrue($index_data['is_simple']);
$this->assertEquals(2, count($index_data['options']['lengths']));
$this->assertEmpty($index_data['options']['lengths'][0]);
$this->assertEquals($mysql ? 191 : null, $index_data['options']['lengths'][1]);
break;
/* case 'i_uniq':
$this->assertEquals(['expiration_time', 'p256dh'], $index_data['columns']);
$this->assertEmpty($index_data['flags']);
$this->assertFalse($index_data['is_primary']);
$this->assertTrue($index_data['is_unique']);
$this->assertFalse($index_data['is_simple']);
$this->assertEquals(2, count($index_data['options']['lengths']));
$this->assertEmpty($index_data['options']['lengths'][0]);
$this->assertEquals($mysql ? 100 : null, $index_data['options']['lengths'][1]);
break;*/
case 'i_auth':
$this->assertEquals(['auth'], $index_data['columns']);
$this->assertEmpty($index_data['flags']);
$this->assertFalse($index_data['is_primary']);
$this->assertFalse($index_data['is_unique']);
$this->assertTrue($index_data['is_simple']);
$this->assertEquals(1, count($index_data['options']['lengths']));
$this->assertEmpty($index_data['options']['lengths'][0]);
break;
default: // Primary key
$this->assertEquals(['module_id'], $index_data['columns']);
$this->assertEmpty($index_data['flags']);
$this->assertTrue($index_data['is_primary']);
$this->assertTrue($index_data['is_unique']);
$this->assertFalse($index_data['is_simple']);
$this->assertEquals(1, count($index_data['options']['lengths']));
$this->assertEmpty($index_data['options']['lengths'][0]);
break;
}
}
while ($this->migrator->migration_state('phpbb_dbal_migration_schema')) while ($this->migrator->migration_state('phpbb_dbal_migration_schema'))
{ {
$this->migrator->revert('phpbb_dbal_migration_schema'); $this->migrator->revert('phpbb_dbal_migration_schema');