Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add old_id and new_id col in glpi_logs table #19160

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

RomainLvr
Copy link
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

Add two new_id and old_id columns to the glpi_logs table to optimize table searches

@RomainLvr RomainLvr self-assigned this Mar 7, 2025
@RomainLvr RomainLvr requested a review from Copilot March 7, 2025 15:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

@RomainLvr RomainLvr requested a review from Rom1-B March 13, 2025 09:52
@RomainLvr RomainLvr requested a review from Rom1-B March 13, 2025 13:53
@RomainLvr RomainLvr requested a review from Rom1-B March 13, 2025 14:45
@RomainLvr RomainLvr requested review from stonebuzz and removed request for stonebuzz March 14, 2025 10:31
@trasher trasher requested a review from cedric-anne March 17, 2025 08:01
Comment on lines +290 to +292
$DB->tableExists(self::getTable())
&& $DB->fieldExists(self::getTable(), 'old_id')
&& $DB->fieldExists(self::getTable(), 'new_id')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition has been added to fix the following error that appeared during the migration from 0.85.x to 0.90.0:

MySQL query error: Unknown column 'old_id' in 'INSERT INTO' (1054) in SQL query "INSERT INTO `glpi_logs` (`items_id`, `itemtype`, `itemtype_link`, `linked_action`, `user_name`, `date_mod`, `id_search_option`, `old_value`, `new_value`, `old_id`, `new_id`) VALUES ('1', 'Config', '', '0', '', '2025-03-07 15:13:08', '1', 'palette ', 'auror', NULL, NULL)".

IMHO, migrations are not supposed to log anything. The following patch would fix this error, but it is probably not the only one required.

diff --git a/install/migrations/update_0.85.x_to_0.90.0.php b/install/migrations/update_0.85.x_to_0.90.0.php
index 112c8cc6eb..55c619b3f2 100644
--- a/install/migrations/update_0.85.x_to_0.90.0.php
+++ b/install/migrations/update_0.85.x_to_0.90.0.php
@@ -74,16 +74,18 @@ function update085xto0900()
     }
 
    // Add Color selector
-    Config::setConfigurationValues('core', ['palette' => 'auror']);
+    $migration->addConfig(['palette' => 'auror']);
     $migration->addField("glpi_users", "palette", "char(20) DEFAULT NULL");
 
    // add layout config
-    Config::setConfigurationValues('core', ['layout' => 'lefttab']);
+    $migration->addConfig(['layout' => 'lefttab']);
     $migration->addField("glpi_users", "layout", "char(20) DEFAULT NULL");
 
    // add timeline config
-    Config::setConfigurationValues('core', ['ticket_timeline' => 1]);
-    Config::setConfigurationValues('core', ['ticket_timeline_keep_replaced_tabs' => 0]);
+    $migration->addConfig([
+        'ticket_timeline' => 1,
+        'ticket_timeline_keep_replaced_tabs' => 0,
+    ]);
     $migration->addField("glpi_users", "ticket_timeline", "tinyint DEFAULT NULL");
     $migration->addField("glpi_users", "ticket_timeline_keep_replaced_tabs", "tinyint DEFAULT NULL");

I am rarely comfortable with having to patch old migrations, but I do not like having these kinds of conditions either. @trasher What is your opinion about this ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum... I do not like to change old migrations neither, but I do agree it should not log anything.
Since alternative solution seems tricky; and the migration fix is quite light; I'd be OK for this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch does not solve the problem :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are working on a patch that would remove usages of CommonDBTM::add()/CommonDBTM::update() in migrations. I would like to see if we can achieve that in order to remove this condition.

Comment on lines +290 to +292
$DB->tableExists(self::getTable())
&& $DB->fieldExists(self::getTable(), 'old_id')
&& $DB->fieldExists(self::getTable(), 'new_id')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are working on a patch that would remove usages of CommonDBTM::add()/CommonDBTM::update() in migrations. I would like to see if we can achieve that in order to remove this condition.

@cedric-anne cedric-anne added this to the 11.0.0 milestone Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants