PR-6.0-dev 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

avatar muhme muhme - test_item - 29 Aug 2025 - Tested successfully
avatar muhme
muhme - comment - 29 Aug 2025

I have tested this item ✅ successfully on 34a605b

Tested with JBT and integrated phpMyAdmin, some used SQL statements:

  • select * from ajbt54_mail_templates where template_id = 'plg_content_joomla.newarticle'
  • select * from ajbt54_extensions where name = 'plg_fields_note';
  • select * from ajbt54_extensions where name = 'plg_fields_number'
  • Before applying this PR in 5.4 and with MariaDB 10.6.23
    • for 6.0.0-2025-03-25.sql script duplicate key error
    • for 6.0.0-2025-08-16.sql before 0 ajbt54_extensions where name = 'plg_fields_note' and with each script execution one more entry
    • for 6.0.0-2025-08-17.sql before 0 ajbt54_extensions where name = 'plg_fields_number' and with each script execution one more entry

Tested this PR with JBT scripts/graft and integrated phpMyAdmin and pgAdmin

  • MariaDB 10.6.23
    • ✅ running 6.0.0-2025-03-25.sql script multiple times, for second and following runs only a warning
    • ✅ running 6.0.0-2025-08-16.sql script multiple times, running mutliple times is possible, only one entry
    • ✅ running 6.0.0-2025-08-17.sql script multiple times, running mutliple times is possible, only one entry
  • MySQL 8.1.0 new Joomla installation with JBT scripts/database
    • ✅ running 6.0.0-2025-03-25.sql script multiple times, for second and following runs only a warning
    • ✅ running 6.0.0-2025-08-16.sql script multiple times, running mutliple times is possible, only one entry
    • ✅ running 6.0.0-2025-08-17.sql script multiple times, running mutliple times is possible, only one entry
  • PostgreSQL 15.8 new Joomla installation with JBT scripts/database
    • ✅ running 6.0.0-2025-03-25.sql script multiple times, no problem with second and following runs, still one entry
    • ✅ running 6.0.0-2025-08-16.sql script multiple times, running mutliple times is possible, only one entry
    • ✅ running 6.0.0-2025-08-17.sql script multiple times, running mutliple times is possible, only one entry
  • Checked all SQL scripts in administrator/components/com_admin/sql/updates/mysql/*
    ✅ All insert statements are save with INSERT IGNORE or INSERT INTO ... WHERE NOT EXISTS
    This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45972.
avatar softforge softforge - change - 29 Aug 2025
Labels Added: PR-6.0-dev
avatar softforge softforge - change - 29 Aug 2025
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2025-08-29 16:22:12
Closed_By softforge
avatar softforge softforge - close - 29 Aug 2025
avatar softforge softforge - merge - 29 Aug 2025

Add a Comment

Login with GitHub to post a comment