Compare commits

..

17 commits

Author SHA1 Message Date
rxu
d2202b7747
[ticket/17507] Fix column removal issues
PHPBB-17507
2025-07-08 01:02:36 +07:00
rxu
07b63fc6a8
[ticket/17507] Adjust module removal procedure
PHPBB-17507
2025-07-07 23:18:02 +07:00
rxu
0f71afae61
[ticket/17507] Add base class for testing migrations
PHPBB-17507
2025-07-07 23:18:01 +07:00
rxu
59ef2c8fce
[ticket/17507] Add remove_jabber migration test
PHPBB-17507
2025-07-07 23:18:01 +07:00
rxu
4b420e2958
[ticket/17507] Fix notification related tests
PHPBB-17507
2025-07-07 23:18:01 +07:00
rxu
1d34b4f06a
[ticket/17507] Fix 'add_primary_keys' db tools option for schema generator
PHPBB-17507
2025-07-07 23:18:00 +07:00
rxu
38ee655b2a
[ticket/17507] Add id as primary key, fix schema_create_primary_key() method
PHPBB-17507
2025-07-07 23:18:00 +07:00
rxu
e4cd3ac744
[ticket/17507] General SQL error on installing remove_jabber.php migration
The issue affects probably any DBMS excluding MySQL/MariaDB.

PHPBB-17507
2025-07-07 23:17:59 +07:00
Marc Alexander
4f89e2b97d
[ticket/17528] Fix migration issue using postgres
PHPBB-17528
2025-07-07 23:17:59 +07:00
rxu
53360e0c17
[ticket/17528] Fix typo
PHPBB-17528
2025-07-07 23:17:59 +07:00
rxu
83f1ed8de4
[ticket/17528] Fix PostgreSQL platform issues
PHPBB-17528
2025-07-07 23:17:58 +07:00
rxu
98c6a88438
[ticket/17528] Fix MySQL platform
PHPBB-17528
2025-07-07 23:17:58 +07:00
rxu
9cccf26311
[ticket/17528] Fix phpBB PostgreSQL platform [ci skip]
PHPBB-17528
2025-07-07 23:17:57 +07:00
rxu
43833b40bb
[ticket/17528] Add test for adding autoincrement column
PHPBB-17528
2025-07-07 23:17:53 +07:00
Marc Alexander
30ee379576 Merge branch '3.3.x' 2025-07-07 15:35:55 +00:00
Marc Alexander
081f2391cb
Merge pull request #6836 from rxu/ticket/17533
[ticket/17533] Fix reverting migrations logic
2025-07-07 17:35:37 +02:00
rxu
0b242b9608
[ticket/17533] Fix reverting migrations logic
Basically, prefer revert_data() if exists.

PHPBB-17533
2025-07-07 11:02:30 +07:00
4 changed files with 85 additions and 60 deletions

View file

@ -575,7 +575,7 @@ class migrator
$state['migration_data_state']['_total_time'] : 0.0; $state['migration_data_state']['_total_time'] : 0.0;
$elapsed_time = microtime(true); $elapsed_time = microtime(true);
$steps = array_merge($this->helper->reverse_update_data($migration->update_data()), $migration->revert_data()); $steps = $migration->revert_data() ?: $this->helper->reverse_update_data($migration->update_data());
$result = $this->process_data_step($steps, $state['migration_data_state']); $result = $this->process_data_step($steps, $state['migration_data_state']);
$elapsed_time = microtime(true) - $elapsed_time; $elapsed_time = microtime(true) - $elapsed_time;

View file

@ -300,34 +300,10 @@ class doctrine implements tools_interface
*/ */
public function sql_column_remove(string $table_name, string $column_name) public function sql_column_remove(string $table_name, string $column_name)
{ {
// Check if this column is part of a primary key. If yes, remove the primary key. $return = $this->schema_drop_primary_key($table_name, $column_name);
$primary_key_indexes = $this->get_filtered_index_list($table_name, false); if ($return !== true)
$primary_key_indexes = array_filter($primary_key_indexes, function($index) use ($column_name) {
$index_columns = array_map('strtolower', $index->getUnquotedColumns());
return in_array($column_name, $index_columns, true) && $index->isPrimary();
});
if (count($primary_key_indexes))
{ {
// For PostgreSQL, drop primary index first to avoid "Dependent objects still exist" error return $return;
if (stripos($this->get_schema_manager()->getDatabasePlatform()->getname(), 'postgresql') !== false)
{
$this->get_schema_manager()->dropIndex('"primary"', $table_name);
}
$ret = $this->alter_schema(
function (Schema $schema) use ($table_name, $column_name): void
{
$table = $schema->getTable($table_name);
$table->dropPrimaryKey();
}
);
if ($ret !== true)
{
return $ret;
}
} }
return $this->alter_schema( return $this->alter_schema(
@ -835,6 +811,8 @@ class doctrine implements tools_interface
*/ */
protected function schema_column_remove(Schema $schema, string $table_name, string $column_name, bool $safe_check = false): void protected function schema_column_remove(Schema $schema, string $table_name, string $column_name, bool $safe_check = false): void
{ {
$this->schema_drop_primary_key($table_name, $column_name);
$this->alter_table( $this->alter_table(
$schema, $schema,
$table_name, $table_name,
@ -1005,6 +983,47 @@ class doctrine implements tools_interface
$table->setPrimaryKey($columns); $table->setPrimaryKey($columns);
} }
/**
* Removes primary key from a table
*
* @param string $table_name
* @param string $column_name
*
* @return bool|string[]
*
* @throws SchemaException
*/
protected function schema_drop_primary_key(string $table_name, string $column_name): array|bool
{
// Check if this column is part of a primary key. If yes, remove the primary key.
$primary_key_indexes = $this->get_filtered_index_list($table_name, false);
$primary_key_indexes = array_filter($primary_key_indexes, function($index) use ($column_name) {
$index_columns = array_map('strtolower', $index->getUnquotedColumns());
return in_array($column_name, $index_columns, true) && $index->isPrimary();
});
$return = true;
if (count($primary_key_indexes))
{
// For PostgreSQL, drop primary index first to avoid "Dependent objects still exist" error
if (stripos($this->get_schema_manager()->getDatabasePlatform()->getname(), 'postgresql') !== false)
{
$this->get_schema_manager()->dropIndex('"primary"', $table_name);
}
$return = $this->alter_schema(
function (Schema $schema) use ($table_name, $column_name): void
{
$table = $schema->getTable($table_name);
$table->dropPrimaryKey();
}
);
}
return $return;
}
/** /**
* Recreate an index of a table * Recreate an index of a table
* *
@ -1016,40 +1035,43 @@ class doctrine implements tools_interface
*/ */
protected function recreate_index(Table $table, Index $index, array $new_columns): void protected function recreate_index(Table $table, Index $index, array $new_columns): void
{ {
if ($index->isPrimary()) if (!empty($new_columns))
{ {
$table->dropPrimaryKey(); if ($table->hasPrimaryKey() && $index->isPrimary())
} {
else $table->dropPrimaryKey();
{ }
$table->dropIndex($index->getName()); else if ($table->hasIndex($index->getName()))
} {
$table->dropIndex($index->getName());
}
if (count($new_columns) > 0) if (count($new_columns) > 0)
{
if ($index->isPrimary())
{ {
$table->setPrimaryKey( if ($index->isPrimary())
$new_columns, {
$index->getName(), $table->setPrimaryKey(
); $new_columns,
} $index->getName(),
else if ($index->isUnique()) );
{ }
$table->addUniqueIndex( else if ($index->isUnique())
$new_columns, {
$index->getName(), $table->addUniqueIndex(
$index->getOptions(), $new_columns,
); $index->getName(),
} $index->getOptions(),
else );
{ }
$table->addIndex( else
$new_columns, {
$index->getName(), $table->addIndex(
$index->getFlags(), $new_columns,
$index->getOptions(), $index->getName(),
); $index->getFlags(),
$index->getOptions(),
);
}
} }
} }
} }

View file

@ -134,7 +134,7 @@ abstract class phpbb_migration_test_base extends phpbb_database_test_case
protected function revert_migration() protected function revert_migration()
{ {
while ($this->migrator->migration_state($this->migration_class)) while ($this->migrator->migration_state($this->migration_class) !== false)
{ {
try try
{ {

View file

@ -69,5 +69,8 @@ class phpbb_migrations_remove_jabber_migration_test extends phpbb_migration_test
$this->assertTrue($this->tools['permission']->exists('a_jabber')); $this->assertTrue($this->tools['permission']->exists('a_jabber'));
$this->assertTrue($this->tools['permission']->exists('u_sendim')); $this->assertTrue($this->tools['permission']->exists('u_sendim'));
$this->assertTrue($this->tools['module']->exists('acp', 'ACP_CLIENT_COMMUNICATION', 'ACP_JABBER_SETTINGS')); $this->assertTrue($this->tools['module']->exists('acp', 'ACP_CLIENT_COMMUNICATION', 'ACP_JABBER_SETTINGS'));
// Apply migration back
$this->apply_migration();
} }
} }