mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-16 15:08:54 +00:00
[ticket/17524] Add index migrator tests
PHPBB-17524
This commit is contained in:
parent
418aa469d7
commit
c47e5d34df
2 changed files with 63 additions and 5 deletions
|
@ -22,12 +22,22 @@ class phpbb_dbal_migration_schema extends \phpbb\db\migration\migration
|
|||
),
|
||||
),
|
||||
'add_tables' => array(
|
||||
$this->table_prefix . 'foobar' => array(
|
||||
'COLUMNS' => array(
|
||||
'module_id' => array('UINT:3', NULL, 'auto_increment'),
|
||||
),
|
||||
$this->table_prefix . 'foobar' => [
|
||||
'COLUMNS' => [
|
||||
'module_id' => ['UINT:3', NULL, 'auto_increment'],
|
||||
'user_id' => ['ULINT', 0],
|
||||
'endpoint' => ['TEXT', ''],
|
||||
'expiration_time' => ['TIMESTAMP', 0],
|
||||
'p256dh' => ['VCHAR', ''],
|
||||
'auth' => ['VCHAR:100', ''],
|
||||
],
|
||||
'PRIMARY_KEY' => 'module_id',
|
||||
),
|
||||
'KEYS' => [
|
||||
'i_simple' => ['INDEX', ['user_id', 'endpoint:191']],
|
||||
'i_uniq' => ['UNIQUE', ['expiration_time', 'p256dh(100)']],
|
||||
'i_auth' => ['INDEX', 'auth'],
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -412,6 +412,54 @@ 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_table_exists('phpbb_foobar'));
|
||||
|
||||
$index_data_row = $this->db_tools->sql_get_table_index_data('phpbb_foobar');
|
||||
$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)
|
||||
{
|
||||
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($is_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($is_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->assertEquals($is_mssql ? ['clustered'] : [], $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'))
|
||||
{
|
||||
$this->migrator->revert('phpbb_dbal_migration_schema');
|
||||
|
|
Loading…
Add table
Reference in a new issue