diff --git a/tests/dbal/migration/schema_add_autoincrement.php b/tests/dbal/migration/schema_add_autoincrement.php new file mode 100644 index 0000000000..4e3ecff183 --- /dev/null +++ b/tests/dbal/migration/schema_add_autoincrement.php @@ -0,0 +1,43 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +class schema_add_autoincrement extends \phpbb\db\migration\migration +{ + function update_schema() + { + return [ + 'add_tables' => [ + $this->table_prefix . 'noid' => [ + 'COLUMNS' => [ + 'text' => ['VCHAR:50', ''], + ], + ], + ], + + 'add_columns' => [ + $this->table_prefix . 'noid' => [ + 'id' => ['UINT:3', null, 'auto_increment'], + ], + ], + ]; + } + + function revert_schema() + { + return [ + 'drop_tables' => [ + $this->table_prefix . 'noid', + ], + ]; + } +} diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index f4b80fc5e9..284c52a07c 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -25,6 +25,7 @@ require_once __DIR__ . '/migration/fail.php'; require_once __DIR__ . '/migration/installed.php'; require_once __DIR__ . '/migration/schema.php'; require_once __DIR__ . '/migration/schema_index.php'; +require_once __DIR__ . '/migration/schema_add_autoincrement.php'; class phpbb_dbal_migrator_test extends phpbb_database_test_case { @@ -502,4 +503,24 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case } } } + + public function test_add_autoincrement_column() + { + $this->migrator->set_migrations(['schema_add_autoincrement']); + + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->db_tools->sql_table_exists('phpbb_noid')); + $this->assertTrue($this->db_tools->sql_column_exists('phpbb_noid', 'id')); + + while ($this->migrator->migration_state('schema_add_autoincrement')) + { + $this->migrator->revert('schema_add_autoincrement'); + } + + $this->assertFalse($this->db_tools->sql_table_exists('phpbb_noid')); + } }