[ticket/12870] Create the migrations table with a method in the migrator

PHPBB3-12870
This commit is contained in:
Tristan Darricau 2014-07-27 11:08:13 +02:00
parent e4a829071e
commit a8e81b6e9f
5 changed files with 29 additions and 47 deletions

View file

@ -84,8 +84,6 @@ services:
- @config - @config
- @cache - @cache
- @log - @log
- @dbal.tools
- %core.table_prefix%
tags: tags:
- { name: console.command } - { name: console.command }

View file

@ -177,25 +177,9 @@ define('IN_DB_UPDATE', true);
// End startup code // End startup code
// Make sure migrations have been installed.
$db_tools = $phpbb_container->get('dbal.tools');
if (!$db_tools->sql_table_exists($table_prefix . 'migrations'))
{
$db_tools->sql_create_table($table_prefix . 'migrations', array(
'COLUMNS' => array(
'migration_name' => array('VCHAR', ''),
'migration_depends_on' => array('TEXT', ''),
'migration_schema_done' => array('BOOL', 0),
'migration_data_done' => array('BOOL', 0),
'migration_data_state' => array('TEXT', ''),
'migration_start_time' => array('TIMESTAMP', 0),
'migration_end_time' => array('TIMESTAMP', 0),
),
'PRIMARY_KEY' => 'migration_name',
));
}
$migrator = $phpbb_container->get('migrator'); $migrator = $phpbb_container->get('migrator');
$migrator->create_migrations_table();
$phpbb_extension_manager = $phpbb_container->get('ext.manager'); $phpbb_extension_manager = $phpbb_container->get('ext.manager');
$finder = $phpbb_extension_manager->get_finder(); $finder = $phpbb_extension_manager->get_finder();

View file

@ -32,21 +32,13 @@ class migrate extends \phpbb\console\command\command
/** @var \phpbb\log\log */ /** @var \phpbb\log\log */
protected $log; protected $log;
/** @var \phpbb\db\tools */ function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log)
protected $db_tools;
/** @var string */
protected $table_prefix;
function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, \phpbb\db\tools $db_tools, $table_prefix)
{ {
$this->migrator = $migrator; $this->migrator = $migrator;
$this->extension_manager = $extension_manager; $this->extension_manager = $extension_manager;
$this->config = $config; $this->config = $config;
$this->cache = $cache; $this->cache = $cache;
$this->log = $log; $this->log = $log;
$this->db_tools = $db_tools;
$this->table_prefix = $table_prefix;
parent::__construct($user); parent::__construct($user);
$this->user->add_lang(array('common', 'install', 'migrator')); $this->user->add_lang(array('common', 'install', 'migrator'));
} }
@ -61,22 +53,7 @@ class migrate extends \phpbb\console\command\command
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
// Make sure migrations have been installed. $this->migrator->create_migrations_table();
if (!$this->db_tools->sql_table_exists($this->table_prefix . 'migrations'))
{
$this->db_tools->sql_create_table($this->table_prefix . 'migrations', array(
'COLUMNS' => array(
'migration_name' => array('VCHAR', ''),
'migration_depends_on' => array('TEXT', ''),
'migration_schema_done' => array('BOOL', 0),
'migration_data_done' => array('BOOL', 0),
'migration_data_state' => array('TEXT', ''),
'migration_start_time' => array('TIMESTAMP', 0),
'migration_end_time' => array('TIMESTAMP', 0),
),
'PRIMARY_KEY' => 'migration_name',
));
}
$this->load_migrations(); $this->load_migrations();
$orig_version = $this->config['version']; $orig_version = $this->config['version'];

View file

@ -767,4 +767,24 @@ class migrator
return $this->migrations; return $this->migrations;
} }
public function create_migrations_table()
{
// Make sure migrations have been installed.
if (!$this->db_tools->sql_table_exists($this->table_prefix . 'migrations'))
{
$this->db_tools->sql_create_table($this->table_prefix . 'migrations', array(
'COLUMNS' => array(
'migration_name' => array('VCHAR', ''),
'migration_depends_on' => array('TEXT', ''),
'migration_schema_done' => array('BOOL', 0),
'migration_data_done' => array('BOOL', 0),
'migration_data_state' => array('TEXT', ''),
'migration_start_time' => array('TIMESTAMP', 0),
'migration_end_time' => array('TIMESTAMP', 0),
),
'PRIMARY_KEY' => 'migration_name',
));
}
}
} }

View file

@ -78,8 +78,11 @@ class manager
$this->extensions = array(); $this->extensions = array();
// Do not try to load any extensions if the extension table // Do not try to load any extensions if the extension table
// does not exist. (The table is crated by the firsts migrations). // does not exist or when installing or updating.
if (version_compare($this->config['version'], '3.1.0-dev', '<')) // Note: database updater invokes this code, and in 3.0
// there is no extension table therefore the rest of this function
// fails
if (defined('IN_INSTALL') || version_compare($this->config['version'], '3.1.0-dev', '<'))
{ {
return; return;
} }