From e8f8dcf0eaf53c4d7e175a6b90ae181794718184 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 7 Feb 2014 20:49:13 +0100 Subject: [PATCH 1/2] [ticket/12170] Assign schema keys in migration helper with data_depth 1 The migration helper currently drops any keys with schema changes that have the data_depth 1. This change will correctly assign the keys to the steps array without dropping the keys that might contain important info like the actual table that should be created. PHPBB3-12170 --- phpBB/phpbb/db/migration/helper.php | 2 +- tests/dbal/migration/schema.php | 11 +++++++++++ tests/dbal/migrator_test.php | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/db/migration/helper.php b/phpBB/phpbb/db/migration/helper.php index 28a6a56511..009ad1da9f 100644 --- a/phpBB/phpbb/db/migration/helper.php +++ b/phpBB/phpbb/db/migration/helper.php @@ -53,7 +53,7 @@ class helper $steps[] = array( 'dbtools.perform_schema_changes', array(array( $change_type => array( - $value, + (!is_int($key)) ? $key : 0 => $value, ), )), ); diff --git a/tests/dbal/migration/schema.php b/tests/dbal/migration/schema.php index 46cf66eaec..98407eb1bd 100644 --- a/tests/dbal/migration/schema.php +++ b/tests/dbal/migration/schema.php @@ -17,6 +17,14 @@ class phpbb_dbal_migration_schema extends \phpbb\db\migration\migration 'test_column1' => array('BOOL', 1), ), ), + 'add_tables' => array( + $this->table_prefix . 'foobar' => array( + 'COLUMNS' => array( + 'module_id' => array('UINT:3', NULL, 'auto_increment'), + ), + 'PRIMARY_KEY' => 'module_id', + ), + ), ); } @@ -28,6 +36,9 @@ class phpbb_dbal_migration_schema extends \phpbb\db\migration\migration 'test_column1', ), ), + 'drop_tables' => array( + $this->table_prefix . 'foobar', + ), ); } } diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index c075f19825..f22f5f5b30 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -280,6 +280,7 @@ 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')); while ($this->migrator->migration_state('phpbb_dbal_migration_schema')) { @@ -287,5 +288,6 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case } $this->assertFalse($this->db_tools->sql_column_exists('phpbb_config', 'test_column1')); + $this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar')); } } From 344fde7f06bcd74f3b142ef79ada32289cb6cd06 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 7 Feb 2014 14:37:45 -0600 Subject: [PATCH 2/2] [ticket/12170] Test for 12170 PHPBB3-12170 --- tests/migrator/get_schema_steps_test.php | 38 +++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/tests/migrator/get_schema_steps_test.php b/tests/migrator/get_schema_steps_test.php index f354d3617f..226535754e 100644 --- a/tests/migrator/get_schema_steps_test.php +++ b/tests/migrator/get_schema_steps_test.php @@ -21,7 +21,22 @@ class get_schema_steps_test extends phpbb_test_case return array( array( array( - 'add_tables' => array('table1', 'table2', 'table3'), + 'add_tables' => array( + 'foo' => array( + 'COLUMNS' => array( + 'foobar' => array('BOOL', 0), + 'foobar2' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('foobar'), + ), + 'bar' => array( + 'COLUMNS' => array( + 'barfoo' => array('BOOL', 0), + 'barfoor2' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('barfoo'), + ), + ), 'drop_tables' => array('table1', 'table2', 'table3'), 'add_index' => array( 'table1' => array( @@ -73,9 +88,24 @@ class get_schema_steps_test extends phpbb_test_case array('dbtools.perform_schema_changes', array(array('drop_tables' => array('table1')))), array('dbtools.perform_schema_changes', array(array('drop_tables' => array('table2')))), array('dbtools.perform_schema_changes', array(array('drop_tables' => array('table3')))), - array('dbtools.perform_schema_changes', array(array('add_tables' => array('table1')))), - array('dbtools.perform_schema_changes', array(array('add_tables' => array('table2')))), - array('dbtools.perform_schema_changes', array(array('add_tables' => array('table3')))), + array('dbtools.perform_schema_changes', array(array('add_tables' => array( + 'foo' => array( + 'COLUMNS' => array( + 'foobar' => array('BOOL', 0), + 'foobar2' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('foobar'), + ), + )))), + array('dbtools.perform_schema_changes', array(array('add_tables' => array( + 'bar' => array( + 'COLUMNS' => array( + 'barfoo' => array('BOOL', 0), + 'barfoor2' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('barfoo'), + ), + )))), array('dbtools.perform_schema_changes', array(array('change_columns' => array( 'table1' => array( 'column1' => array('foo'),