No Code Attached Yet
avatar sousa9g
sousa9g
9 Dec 2021

Problem identified

I have a Joomla component and Joomla 4 reports that it has database problems, however I am pretty sure that it does not.

Scenario: component A has 02 SQL update files named 1.0.0.sql and 1.1.0.sql

File 1.0.0.sql contains this SQL statement:

ALTER TABLE X CHANGE column_a column_a VARCHAR(10) NOT NULL;

File 1.1.0.sql contains this SQL statement:

ALTER TABLE X CHANGE column_a column_a VARCHAR(100) NOT NULL;

When checking for dabase problems, Joomla run through all SQL update files, and then immediately reports a problem in file 1.0.0.sql, as it does not match the actual column in the database. But there should be no problems at all in this scenario, as 1.1.0.sql is the latest one, and it should be checked agains the database, not all past update SQL files, am I wrong?

Proposed solution

Open questions

avatar sousa9g sousa9g - open - 9 Dec 2021
avatar richard67
richard67 - comment - 9 Dec 2021

@sousa9g That's how the database check works. It goes through all present update SQL scripts from old to new without any knowledge that a later statement again modifies the same thing. E.g. the database checker can't handle if an index is removed and later added back, or a column is removed and later added back, or vice versa.

Therefore when such a thing happened, we had to comment out the statement in the old SQL skript (and ship it in the update package as we ship them all).

In your case it would be to comment out the statement in the 1.0.0.sql:

-- The following statement had to be disabled due to a later change in 1.0.1.sql
-- ALTER TABLE X CHANGE `column_a` `column_a` VARCHAR(10) NOT NULL;

If you check update SQL scripts of the CMS core for version 3.10 you will find some examples of that.

Let me know if this helps you, and close this issue if you are ok with it.

Thanks in advance.

avatar sousa9g sousa9g - change - 11 Dec 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-12-11 15:41:09
Closed_By sousa9g
Labels Added: No Code Attached Yet
avatar sousa9g sousa9g - close - 11 Dec 2021
avatar sousa9g
sousa9g - comment - 11 Dec 2021

Thank you for your answer!

avatar richard67
richard67 - comment - 11 Dec 2021

@sousa9g Thanks for feedback.

Add a Comment

Login with GitHub to post a comment