mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-25 19:38:53 +00:00
Merge 5b947ee554
into 4f10e6e212
This commit is contained in:
commit
7efe5394a7
3 changed files with 94 additions and 0 deletions
|
@ -78,6 +78,36 @@ class postgresql_platform extends PostgreSQL94Platform
|
|||
return AbstractPlatform::getDefaultValueDeclarationSQL($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getAlterTableSQL(TableDiff $diff)
|
||||
{
|
||||
$sql = parent::getAlterTableSQL($diff);
|
||||
$table_name = $diff->getOldTable()->getName();
|
||||
$columns = array_merge($diff->getAddedColumns(), $diff->getModifiedColumns());
|
||||
$post_sql = $sequence_sql = [];
|
||||
|
||||
foreach ($columns as $column)
|
||||
{
|
||||
$column_name = $column->getName();
|
||||
if (!empty($column->getAutoincrement()))
|
||||
{
|
||||
$sequence = new Sequence($this->getIdentitySequenceName($table_name, $column_name));
|
||||
$sequence_sql[] = $this->getCreateSequenceSQL($sequence);
|
||||
$post_sql[] = 'ALTER SEQUENCE '.$sequence->getName().' OWNED BY ' . $table_name . '.' . $column_name;
|
||||
}
|
||||
}
|
||||
$sql = array_merge($sequence_sql, $sql, $post_sql);
|
||||
|
||||
foreach ($sql as $i => $query)
|
||||
{
|
||||
$sql[$i] = str_replace('{{placeholder_sequence}}', "nextval('{$table_name}_seq')", $query);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
43
tests/dbal/migration/schema_add_autoincrement.php
Normal file
43
tests/dbal/migration/schema_add_autoincrement.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ require_once __DIR__ . '/migration/revert_table_with_dependency.php';
|
|||
require_once __DIR__ . '/migration/fail.php';
|
||||
require_once __DIR__ . '/migration/installed.php';
|
||||
require_once __DIR__ . '/migration/schema.php';
|
||||
require_once __DIR__ . '/migration/schema_add_autoincrement.php';
|
||||
|
||||
class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||
{
|
||||
|
@ -416,4 +417,24 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
|||
$this->assertFalse($this->db_tools->sql_column_exists('phpbb_config', 'test_column1'));
|
||||
$this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar'));
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue