moodle-mod_customcert
moodle-mod_customcert copied to clipboard
Unique key breaks when backup/restore with existing codes
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
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?
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
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?
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.
We could create the index but make it so its not unique. I am thinking that is the best way forward.
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?
The issue will happen if they do a backup and restore on the same site so I am making the index not unique.
Fixed, thanks for the report.
Got it, thank you