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

feat(ModuleInstaller): Add method to rename tables in the DB #623

Open
wants to merge 1 commit into
base: support/3.2
Choose a base branch
from

Conversation

Hipska
Copy link
Contributor

@Hipska Hipska commented Feb 28, 2024

Base information

Question Answer
Related to a SourceForge thead / Another PR / Combodo ticket? N/A
Type of change? Enhancement

Objective

To have a helper method that can rename a table in DB during setup.

The helper method can silently ignore the renaming if the origin table doesn't exist or the destination table already exists. This to avoid errors when running the setup again after the migration has ben done before.
EDIT: This part has been rejected by Combodo technical review..

Proposed solution

Creation of ModuleInstallerAPI::RenameTableInDB.

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have tested all changes I made on an iTop instance
  • I have added a unit test, otherwise I have explained why I couldn't
  • Is the PR clear and detailled enough so anyone can understand digging in the code?

@Molkobain Molkobain added enhancement New feature or request core labels Feb 28, 2024
Copy link
Member

@Molkobain Molkobain left a comment

Choose a reason for hiding this comment

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

See comment on test

@Molkobain Molkobain self-assigned this Feb 28, 2024
Copy link
Contributor

@piRGoif piRGoif left a comment

Choose a reason for hiding this comment

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

Great work, thanks !
My remarks are mostly questions, and also we may add more uses cases in the phpunit

setup/moduleinstaller.class.inc.php Outdated Show resolved Hide resolved
setup/moduleinstaller.class.inc.php Show resolved Hide resolved
setup/moduleinstaller.class.inc.php Outdated Show resolved Hide resolved
setup/moduleinstaller.class.inc.php Show resolved Hide resolved
setup/moduleinstaller.class.inc.php Outdated Show resolved Hide resolved
* @throws \CoreException
* @throws \MySQLException
*/
public function testRenameTableInDB()
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also test :

  • orig and dest on the same existing table name
  • orig and dest on the same non existing table name
  • orig on a non existing table name
  • dest on an existing table name

This may be easier to code using a dataprovider returning orig and dest names, and expected result ?

Copy link
Member

@Molkobain Molkobain left a comment

Choose a reason for hiding this comment

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

Technical review:

  • Unit test:
    • Move table revert in tearDown() method for better robustness in case there is an issue within the test method
  • New method:
    • Add SetupLog message in exit conditions (except the !MetaModel::DBExists(false)). See RenameEnumValueInDB() for a real example, MoveColumnInDB() is a bad one.

@Hipska
Copy link
Contributor Author

Hipska commented May 13, 2024

Okay @Molkobain, but earlier you said this:

So it's best to revert the table to its original state in order to keep it clean for other tests. Moving the revert in the teardown method would not pollute other test classes, but it would impact other tests from the current class.

So I understand that it might impact other tests and thus it needed to be added within the test?

About the exit conditions, I thought this was also discussed and agreed before?

Ok right, indeed there are only return in \ModuleInstallerAPI::MoveColumnInDB This method was added in 2018 so not to far away, it is quite a strange choice :/ To be discussed during next review !

Followed by

Closing conversation, we discussed during tech review and this is no longer valid.

Do I understand this wrong?

@Hipska
Copy link
Contributor Author

Hipska commented Jul 10, 2024

@Molkobain?

@Molkobain
Copy link
Member

Hello Thomas, nevermidn about the revert table comment, leave it as it is.
Just missing the SetupLog messages, then alright for me. :)

@Hipska Hipska requested a review from Molkobain July 16, 2024 08:18
@Molkobain
Copy link
Member

Thanks!

@Molkobain Molkobain changed the base branch from develop to support/3.2 July 17, 2024 07:59
@Molkobain Molkobain changed the base branch from support/3.2 to develop July 17, 2024 07:59
@Hipska Hipska force-pushed the feature/moduleinstaller_rename_table branch from c4450d9 to 8662a5b Compare July 19, 2024 14:42
@Hipska Hipska changed the base branch from develop to support/3.2 July 19, 2024 14:43
@Hipska Hipska force-pushed the feature/moduleinstaller_rename_table branch from 8662a5b to c4450d9 Compare July 19, 2024 14:59
@Hipska Hipska changed the base branch from support/3.2 to develop July 19, 2024 15:00
@Hipska Hipska force-pushed the feature/moduleinstaller_rename_table branch from c4450d9 to f91ca34 Compare July 22, 2024 10:36
@Hipska Hipska changed the base branch from develop to support/3.2 July 22, 2024 10:36
@Hipska Hipska requested a review from Molkobain July 22, 2024 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core enhancement New feature or request
Projects
Status: Pending functional review
3 participants