mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-31 19:49:20 +02:00
Merge branch 'develop-ascraeus' into develop
* develop-ascraeus: [ticket/12643] Properly handle changing columns on tables with constraints [ticket/12643] Tests dropping similarly named columns [ticket/12643] Ensure that similarly named columns are not removed
This commit is contained in:
commit
cebe7c8028
@ -1996,7 +1996,7 @@ class tools
|
||||
|
||||
$columns = implode(',', $column_list);
|
||||
|
||||
$new_table_cols = trim(preg_replace('/' . $column_name . '[^,]+(?:,|$)/m', '', $new_table_cols));
|
||||
$new_table_cols = trim(preg_replace('/' . $column_name . '\b[^,]+(?:,|$)/m', '', $new_table_cols));
|
||||
if (substr($new_table_cols, -1) === ',')
|
||||
{
|
||||
// Remove the comma from the last entry again
|
||||
@ -2561,7 +2561,18 @@ class tools
|
||||
|
||||
foreach ($old_table_cols as $key => $declaration)
|
||||
{
|
||||
$entities = preg_split('#\s+#', trim($declaration));
|
||||
$declaration = trim($declaration);
|
||||
|
||||
// Check for the beginning of the constraint section and stop
|
||||
if (preg_match('/[^\(]*\s*PRIMARY KEY\s+\(/', $declaration) ||
|
||||
preg_match('/[^\(]*\s*UNIQUE\s+\(/', $declaration) ||
|
||||
preg_match('/[^\(]*\s*FOREIGN KEY\s+\(/', $declaration) ||
|
||||
preg_match('/[^\(]*\s*CHECK\s+\(/', $declaration))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$entities = preg_split('#\s+#', $declaration);
|
||||
$column_list[] = $entities[0];
|
||||
if ($entities[0] == $column_name)
|
||||
{
|
||||
|
@ -239,6 +239,24 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
|
||||
$this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012'));
|
||||
}
|
||||
|
||||
public function test_column_change_with_composite_primary()
|
||||
{
|
||||
// Remove the old primary key
|
||||
$this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_id'));
|
||||
$this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_id', array('UINT', 0)));
|
||||
|
||||
// Create a composite key
|
||||
$this->assertTrue($this->tools->sql_create_primary_key('prefix_table_name', array('c_id', 'c_uint')));
|
||||
|
||||
// Create column
|
||||
$this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12643'));
|
||||
$this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12643', array('DECIMAL', 0)));
|
||||
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12643'));
|
||||
|
||||
// Change type from int to string
|
||||
$this->assertTrue($this->tools->sql_column_change('prefix_table_name', 'c_bug_12643', array('VCHAR:100', '')));
|
||||
}
|
||||
|
||||
public function test_column_remove()
|
||||
{
|
||||
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_int_size'));
|
||||
@ -248,6 +266,17 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
|
||||
$this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_int_size'));
|
||||
}
|
||||
|
||||
public function test_column_remove_similar_name()
|
||||
{
|
||||
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_vchar'));
|
||||
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_vchar_size'));
|
||||
|
||||
$this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_vchar'));
|
||||
|
||||
$this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_vchar'));
|
||||
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_vchar_size'));
|
||||
}
|
||||
|
||||
public function test_column_remove_with_index()
|
||||
{
|
||||
// Create column
|
||||
|
Loading…
x
Reference in New Issue
Block a user