Pending

User tests: Successful: Unsuccessful:

avatar richard67
richard67
24 Aug 2025

Pull Request for Issue # .

Follow up to PRs #45211 , #45233 and #43974 .

Summary of Changes

This pull request (PR) modifies all INSERT statements in any 6.0 update SQL scripts so that the new records are only inserted if they do not already exist.

This makes sure that we do not get duplicate records when the update SQL script runs multiple time, e.g. a 2nd time after a failed update attempt is resumed instead of starting again with a restored backup from before the update.

In case of the extensions table where we do not have a unique key which could be violated by the inserted data and where we do not use the primary key (id column) in the insert, so that also cannot be violated, we have to use an INSERT INTO ... SELECT ... WHERE NOT EXISTS statement, checking the column combination type, element, folder and client_id, which should be unique for each extension even if we don't have a unique key for that.

In case of the mail templates table we have a primary key on the 2 columns template_id and language. Here we can use INSERT IGNORE for MySQL and MariaDB and ON CONFLICT DO NOTHING for PostgreSQL to avoid duplicates.

All this increases the resilience of the update SQL scripts for multiple executions.

For both ways INSERT INTO ... SELECT ... WHERE NOT EXISTS and INSERT IGNORE/ON CONFLICT DO NOTHING we have already examples in update SQL scripts for 5.x versions.

As we are in beta phase we can modify the existing 6.0.0 scripts without the need for any extra comment about the modification.

Testing Instructions

Use phpMyAdmin on a Joomla 5.4 database where the records which shall be inserted by the update SQL statements which are modified by this PR do not exist yet.

Alternatively, on any Joomla version, copy the CREATE TABLE statement for the #__mail_templates table from the installation/supports.sql file and the CREATE TABLE statement for the #__extensions table from the installation/base.sql file into phpMyadmin and execute them so you have these tables without your database prefix and can play with them without messing your installation.

Now execute multiple times the original SQL statement from each of the scripts touched by this PR. Original means how it is without this PR applied. You have to replace the #__ by the actual prefix when not using separate tables with the original #__ prefix.

Result: See section "Actual result BEFORE applying this Pull Request" below.

Now delete the previously inserted records from the mentioned tables, or if working on separate tables beside your Joomla installation, just clear these tables so you have the initial conditions.

Now execute multiple times the modified SQL statement from each of the scripts touched by this PR. You have to replace the #__ by the actual prefix when not using separate tables with the original #__ prefix.

Result: See section "Expected result AFTER applying this Pull Request" below.

Actual result BEFORE applying this Pull Request

With every execution of the particular INSERT statement a new record is inserted.

Expected result AFTER applying this Pull Request

With the first execution of the particular INSERT statement a new record is inserted, every further execution does not insert a new record.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar richard67 richard67 - open - 24 Aug 2025
avatar richard67 richard67 - change - 24 Aug 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 24 Aug 2025
Category SQL Administration com_admin Postgresql
avatar richard67 richard67 - change - 24 Aug 2025
Title
6.0 dev update sql no duplicate inserts
[6.0] Don't insert duplicate records in update SQL scripts when the script runs multiple times
avatar richard67 richard67 - edited - 24 Aug 2025
avatar richard67 richard67 - change - 24 Aug 2025
Title
[6.0] Don't insert duplicate records in update SQL scripts when the script runs multiple times
[6.0] Don't insert duplicate records in update SQL scripts when they are executed multiple times
avatar richard67 richard67 - edited - 24 Aug 2025
avatar richard67 richard67 - change - 24 Aug 2025
The description was changed
avatar richard67 richard67 - edited - 24 Aug 2025
avatar richard67 richard67 - change - 24 Aug 2025
The description was changed
avatar richard67 richard67 - edited - 24 Aug 2025
avatar richard67 richard67 - change - 24 Aug 2025
The description was changed
avatar richard67 richard67 - edited - 24 Aug 2025
avatar richard67 richard67 - change - 24 Aug 2025
The description was changed
avatar richard67 richard67 - edited - 24 Aug 2025
avatar richard67 richard67 - change - 24 Aug 2025
The description was changed
avatar richard67 richard67 - edited - 24 Aug 2025
avatar brianteeman
brianteeman - comment - 24 Aug 2025

Thanks for the detailed explanation. From reading the code I had some questions but i see you answered all of them already

Add a Comment

Login with GitHub to post a comment