1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[feature/migrations] Basic migrations with schema and data changes

The migrator takes care of applying migrations as necessary.

RFC: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=41337

PHPBB3-9737
This commit is contained in:
Nils Adermann
2011-07-15 11:57:53 -04:00
committed by Nathan Guse
parent 0e9b7bcae9
commit f817e20f28
15 changed files with 574 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_migrations">
<column>migration_name</column>
<column>migration_schema_done</column>
<column>migration_data_done</column>
<column>migration_data_state</column>
<column>migration_start_time</column>
<column>migration_end_time</column>
<row>
<value>installed_migration</value>
<value>1</value>
<value>1</value>
<value></value>
<value>1234</value>
<value>5678</value>
</row>
</table>
<table name="phpbb_config">
<column>config_name</column>
<column>config_value</column>
<row>
<value>foo</value>
<value>bar</value>
</row>
</table>
</dataset>

View File

@@ -0,0 +1,26 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class phpbb_dbal_migration_dummy extends phpbb_db_migration
{
function depends_on()
{
return array('installed_migration');
}
function update_schema()
{
$this->db_column_add('phpbb_config', 'extra_column', array('UINT', 0));
}
function update_data()
{
$this->db->sql_query('UPDATE phpbb_config SET extra_column = 1');
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class phpbb_dbal_migration_unfulfillable extends phpbb_db_migration
{
function depends_on()
{
return array('installed_migration', 'phpbb_dbal_migration_dummy', 'non_existant_migration');
}
function update_schema()
{
trigger_error('Schema update of migration with unfulfillable dependency was run!');
}
function update_data()
{
trigger_error('Data update of migration with unfulfillable dependency was run!');
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
require_once dirname(__FILE__) . '/migration/dummy.php';
require_once dirname(__FILE__) . '/migration/unfulfillable.php';
class phpbb_dbal_migrator_test extends phpbb_database_test_case
{
protected $db;
protected $db_tools;
protected $migrator;
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
}
public function setup()
{
parent::setup();
$this->db = $this->new_dbal();
$this->db_tools = new phpbb_db_tools($this->db);
$this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, MIGRATIONS_TABLE);
}
public function test_update()
{
$this->migrator->set_migrations(array('phpbb_dbal_migration_dummy'));
// schema
$this->migrator->update();
$this->assertFalse($this->migrator->finished());
// data
$this->migrator->update();
$this->assertTrue($this->migrator->finished());
$this->assertSqlResultEquals(
array(array('extra_column' => '1')),
"SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
'Dummy migration created extra_column with value 1 in all rows.'
);
// cleanup
$this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
}
public function test_unfulfillable()
{
$this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy'));
while (!$this->migrator->finished())
{
$this->migrator->update();
}
$this->assertTrue($this->migrator->finished());
$this->assertSqlResultEquals(
array(array('extra_column' => '1')),
"SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
'Dummy migration was run, even though an unfulfillable migration was found.'
);
// cleanup
$this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
}
}