moodle-mod_customcert icon indicating copy to clipboard operation
moodle-mod_customcert copied to clipboard

Unique key breaks when backup/restore with existing codes

Open aspark21 opened this issue 8 months ago • 5 comments

Moodle 4.5 customcert @ MOODLE_404_STABLE - https://github.com/mdjnelson/moodle-mod_customcert/commit/5b45c877e37a404be1e19d19c9645820ff45b67d MySQL

Upgrade error

Debug info: Duplicate entry '7NWLE2cLyH' for key 'mdl_customcert_issues.mdl_custissu_cod_uix'
CREATE UNIQUE INDEX mdl_custissu_cod_uix ON mdl_customcert_issues (code)
Error code: ddlexecuteerror

new key was added in #666 yesterday

aspark21 avatar Mar 31 '25 12:03 aspark21

Hi @aspark21 I added that key.

Could you please explain your setup? Have you backed up or restored certificates? Have you manually edited your database?

Do you have any advice on how your system got to generate that same random number twice in a row?

fulldecent avatar Apr 03 '25 17:04 fulldecent

We have a very large instance of Moodle. Backup & restore probably Manually edited the db - not the table structure but we did have to cleanup this mess in August https://github.com/mdjnelson/moodle-mod_customcert/issues/639 by deleting issues certificates during the timeframe they were generated erroneously

aspark21 avatar Apr 03 '25 19:04 aspark21

Got it OK. It sounds like your issue is result of the backup and restores. Because it is exceedingly unlikely that the software generated the same random number twice for the certificate code.

If you haven't done this already, the sequel query would be: select code from CERT group by code having count(*) > 1.


I don't think this issue results in any changes to the software here, but it might still be helpful as documentation to help you through this and leave the notes here.

While you are going through this, do you see that the certificates that have duplicate codes also relate to the same person in the same course?

fulldecent avatar Apr 03 '25 19:04 fulldecent

Hm. I think we another issue for backup/restore now we have this index but I can't think of a solution without removing the index.

mdjnelson avatar Apr 07 '25 15:04 mdjnelson

We could create the index but make it so its not unique. I am thinking that is the best way forward.

mdjnelson avatar Apr 07 '25 15:04 mdjnelson

How is the backup and restore happening?

Are you restoring it onto the same system or a different system?

Is the issue the primary increment counter in the database?

fulldecent avatar Apr 11 '25 21:04 fulldecent

The issue will happen if they do a backup and restore on the same site so I am making the index not unique.

mdjnelson avatar Apr 12 '25 14:04 mdjnelson

Fixed, thanks for the report.

mdjnelson avatar Apr 12 '25 14:04 mdjnelson

Got it, thank you

fulldecent avatar Apr 13 '25 01:04 fulldecent