mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/12643] Properly handle changing columns on tables with constraints
PHPBB3-12643
This commit is contained in:
parent
e6a8df7f7e
commit
754e36e378
2 changed files with 30 additions and 1 deletions
|
@ -2561,7 +2561,18 @@ class tools
|
||||||
|
|
||||||
foreach ($old_table_cols as $key => $declaration)
|
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];
|
$column_list[] = $entities[0];
|
||||||
if ($entities[0] == $column_name)
|
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'));
|
$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()
|
public function test_column_remove()
|
||||||
{
|
{
|
||||||
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_int_size'));
|
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_int_size'));
|
||||||
|
|
Loading…
Add table
Reference in a new issue