mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[feature/migrations] Store start and end time of migrations
PHPBB3-9737
This commit is contained in:
parent
f817e20f28
commit
d304b6449d
2 changed files with 48 additions and 6 deletions
|
@ -127,6 +127,8 @@ class phpbb_db_migrator
|
||||||
'migration_schema_done' => false,
|
'migration_schema_done' => false,
|
||||||
'migration_data_done' => false,
|
'migration_data_done' => false,
|
||||||
'migration_data_state' => '',
|
'migration_data_state' => '',
|
||||||
|
'migration_start_time' => 0,
|
||||||
|
'migration_end_time' => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
$depends = $migration->depends_on();
|
$depends = $migration->depends_on();
|
||||||
|
@ -141,6 +143,12 @@ class phpbb_db_migrator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($this->migration_state[$name]))
|
||||||
|
{
|
||||||
|
$state['migration_start_time'] = time();
|
||||||
|
$this->insert_migration($name, $state);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$state['migration_schema_done'])
|
if (!$state['migration_schema_done'])
|
||||||
{
|
{
|
||||||
$migration->update_schema();
|
$migration->update_schema();
|
||||||
|
@ -150,6 +158,7 @@ class phpbb_db_migrator
|
||||||
{
|
{
|
||||||
$migration->update_data();
|
$migration->update_data();
|
||||||
$state['migration_data_done'] = true;
|
$state['migration_data_done'] = true;
|
||||||
|
$state['migration_end_time'] = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'UPDATE ' . $this->migrations_table . '
|
$sql = 'UPDATE ' . $this->migrations_table . '
|
||||||
|
@ -162,6 +171,18 @@ class phpbb_db_migrator
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function insert_migration($name, $state)
|
||||||
|
{
|
||||||
|
$migration_row = $state;
|
||||||
|
$migration_row['migration_name'] = $name;
|
||||||
|
|
||||||
|
$sql = 'INSERT INTO ' . $this->migrations_table . '
|
||||||
|
' . $this->db->sql_build_array('INSERT', $migration_row);
|
||||||
|
$this->db->sql_query($sql);
|
||||||
|
|
||||||
|
$this->migration_state[$name] = $state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a migration's dependencies can even theoretically be satisfied.
|
* Checks if a migration's dependencies can even theoretically be satisfied.
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,7 +26,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
|
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setup()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setup();
|
parent::setup();
|
||||||
|
|
||||||
|
@ -35,6 +35,12 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||||
$this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, MIGRATIONS_TABLE);
|
$this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, MIGRATIONS_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
// cleanup
|
||||||
|
$this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
|
||||||
|
}
|
||||||
|
|
||||||
public function test_update()
|
public function test_update()
|
||||||
{
|
{
|
||||||
$this->migrator->set_migrations(array('phpbb_dbal_migration_dummy'));
|
$this->migrator->set_migrations(array('phpbb_dbal_migration_dummy'));
|
||||||
|
@ -43,6 +49,16 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||||
$this->migrator->update();
|
$this->migrator->update();
|
||||||
$this->assertFalse($this->migrator->finished());
|
$this->assertFalse($this->migrator->finished());
|
||||||
|
|
||||||
|
$this->assertSqlResultEquals(
|
||||||
|
array(array('success' => '1')),
|
||||||
|
"SELECT 1 as success
|
||||||
|
FROM phpbb_migrations
|
||||||
|
WHERE migration_name = 'phpbb_dbal_migration_dummy'
|
||||||
|
AND migration_start_time >= " . (time() - 1) . "
|
||||||
|
AND migration_start_time <= " . (time() + 1),
|
||||||
|
'Start time set correctly'
|
||||||
|
);
|
||||||
|
|
||||||
// data
|
// data
|
||||||
$this->migrator->update();
|
$this->migrator->update();
|
||||||
$this->assertTrue($this->migrator->finished());
|
$this->assertTrue($this->migrator->finished());
|
||||||
|
@ -53,8 +69,16 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||||
'Dummy migration created extra_column with value 1 in all rows.'
|
'Dummy migration created extra_column with value 1 in all rows.'
|
||||||
);
|
);
|
||||||
|
|
||||||
// cleanup
|
$this->assertSqlResultEquals(
|
||||||
$this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
|
array(array('success' => '1')),
|
||||||
|
"SELECT 1 as success
|
||||||
|
FROM phpbb_migrations
|
||||||
|
WHERE migration_name = 'phpbb_dbal_migration_dummy'
|
||||||
|
AND migration_start_time <= migration_end_time
|
||||||
|
AND migration_end_time >= " . (time() - 1) . "
|
||||||
|
AND migration_end_time <= " . (time() + 1),
|
||||||
|
'End time set correctly'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_unfulfillable()
|
public function test_unfulfillable()
|
||||||
|
@ -73,8 +97,5 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||||
"SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
|
"SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
|
||||||
'Dummy migration was run, even though an unfulfillable migration was found.'
|
'Dummy migration was run, even though an unfulfillable migration was found.'
|
||||||
);
|
);
|
||||||
|
|
||||||
// cleanup
|
|
||||||
$this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue