mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
Merge remote-tracking branch 'github-nickvergessen/ticket/11459' into develop-ascraeus
* github-nickvergessen/ticket/11459: (21 commits) [ticket/11459] Make 3.1.0-dev migration depend on migrations_table [ticket/11459] Move $supported_dbms to beginning of create schema file [ticket/11459] Fix missing constant CONFIG_TABLE for sql_create_index() [ticket/11459] Fix auth provider test [ticket/11459] Correctly set up the database from schema in unit tests [ticket/11459] Install DB schema from json file [ticket/11459] Clean up a little more [ticket/11459] Do not add table schema to database schema files [ticket/11459] Create schema.json from migration files [ticket/11459] Do not take files of extensions into account [ticket/11459] Pass array with migration class names to schema generator [ticket/11459] Refresh schema files [ticket/11459] Remove spaces from the end of lines in MSSQL [ticket/11459] Correctly handle index column length [ticket/11459] Add migration for migrations table [ticket/11459] Update doc blocks [ticket/11459] Remove old schema file [ticket/11459] Update schema files with new script [ticket/11459] Use new migration/schema_generator to create schema files [ticket/11459] Add Schema from 3.0.0 ...
This commit is contained in:
1177
phpBB/phpbb/db/migration/data/v30x/release_3_0_0.php
Normal file
1177
phpBB/phpbb/db/migration/data/v30x/release_3_0_0.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -23,6 +23,7 @@ class dev extends \phpbb\db\migration\migration
|
||||
'\phpbb\db\migration\data\v310\style_update_p2',
|
||||
'\phpbb\db\migration\data\v310\timezone_p2',
|
||||
'\phpbb\db\migration\data\v310\reported_posts_display',
|
||||
'\phpbb\db\migration\data\v310\migrations_table',
|
||||
);
|
||||
}
|
||||
|
||||
|
47
phpBB/phpbb/db/migration/data/v310/migrations_table.php
Normal file
47
phpBB/phpbb/db/migration/data/v310/migrations_table.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package migration
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\db\migration\data\v310;
|
||||
|
||||
class migrations_table extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return $this->db_tools->sql_table_exists($this->table_prefix . 'migrations');
|
||||
}
|
||||
|
||||
public function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_tables' => array(
|
||||
$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',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function revert_schema()
|
||||
{
|
||||
return array(
|
||||
'drop_tables' => array(
|
||||
$this->table_prefix . 'migrations',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
179
phpBB/phpbb/db/migration/schema_generator.php
Normal file
179
phpBB/phpbb/db/migration/schema_generator.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package db
|
||||
* @copyright (c) 2014 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\db\migration;
|
||||
|
||||
/**
|
||||
* The schema generator generates the schema based on the existing migrations
|
||||
*
|
||||
* @package db
|
||||
*/
|
||||
class schema_generator
|
||||
{
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\db\driver\driver */
|
||||
protected $db;
|
||||
|
||||
/** @var \phpbb\db\tools */
|
||||
protected $db_tools;
|
||||
|
||||
/** @var array */
|
||||
protected $class_names;
|
||||
|
||||
/** @var string */
|
||||
protected $table_prefix;
|
||||
|
||||
/** @var string */
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/** @var string */
|
||||
protected $php_ext;
|
||||
|
||||
/** @var array */
|
||||
protected $tables;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(array $class_names, \phpbb\config\config $config, \phpbb\db\driver\driver $db, \phpbb\db\tools $db_tools, $phpbb_root_path, $php_ext, $table_prefix)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
$this->db_tools = $db_tools;
|
||||
$this->class_names = $class_names;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
$this->table_prefix = $table_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all migrations and their application state from the database.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_schema()
|
||||
{
|
||||
if (!empty($this->tables))
|
||||
{
|
||||
return $this->tables;
|
||||
}
|
||||
|
||||
$migrations = $this->class_names;
|
||||
|
||||
$tree = array();
|
||||
while (!empty($migrations))
|
||||
{
|
||||
foreach ($migrations as $migration_class)
|
||||
{
|
||||
$open_dependencies = array_diff($migration_class::depends_on(), $tree);
|
||||
if (empty($open_dependencies))
|
||||
{
|
||||
$migration = new $migration_class($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix);
|
||||
$tree[] = $migration_class;
|
||||
$migration_key = array_search($migration_class, $migrations);
|
||||
|
||||
foreach ($migration->update_schema() as $change_type => $data)
|
||||
{
|
||||
if ($change_type === 'add_tables')
|
||||
{
|
||||
foreach ($data as $table => $table_data)
|
||||
{
|
||||
$this->tables[$table] = $table_data;
|
||||
}
|
||||
}
|
||||
else if ($change_type === 'drop_tables')
|
||||
{
|
||||
foreach ($data as $table)
|
||||
{
|
||||
unset($this->tables[$table]);
|
||||
}
|
||||
}
|
||||
else if ($change_type === 'add_columns')
|
||||
{
|
||||
foreach ($data as $table => $add_columns)
|
||||
{
|
||||
foreach ($add_columns as $column => $column_data)
|
||||
{
|
||||
$this->tables[$table]['COLUMNS'][$column] = $column_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($change_type === 'change_columns')
|
||||
{
|
||||
foreach ($data as $table => $change_columns)
|
||||
{
|
||||
foreach ($change_columns as $column => $column_data)
|
||||
{
|
||||
$this->tables[$table]['COLUMNS'][$column] = $column_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($change_type === 'drop_columns')
|
||||
{
|
||||
foreach ($data as $table => $drop_columns)
|
||||
{
|
||||
if (is_array($drop_columns))
|
||||
{
|
||||
foreach ($drop_columns as $column)
|
||||
{
|
||||
unset($this->tables[$table]['COLUMNS'][$column]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($this->tables[$table]['COLUMNS'][$drop_columns]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($change_type === 'add_unique_index')
|
||||
{
|
||||
foreach ($data as $table => $add_index)
|
||||
{
|
||||
foreach ($add_index as $key => $index_data)
|
||||
{
|
||||
$this->tables[$table]['KEYS'][$key] = array('UNIQUE', $index_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($change_type === 'add_index')
|
||||
{
|
||||
foreach ($data as $table => $add_index)
|
||||
{
|
||||
foreach ($add_index as $key => $index_data)
|
||||
{
|
||||
$this->tables[$table]['KEYS'][$key] = array('INDEX', $index_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($change_type === 'drop_keys')
|
||||
{
|
||||
foreach ($data as $table => $drop_keys)
|
||||
{
|
||||
foreach ($drop_keys as $key)
|
||||
{
|
||||
unset($this->tables[$table]['KEYS'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var_dump($change_type);
|
||||
}
|
||||
}
|
||||
unset($migrations[$migration_key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ksort($this->tables);
|
||||
return $this->tables;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user