ERROR: Upgrade failed: DB: Duplicate entry for key 'versions_pkey'

Hey!

While trying to upgrade OMP from 3.1.0.0 to 3.1.2-4 I get the following error while running the database upgrade:
ERROR: Upgrade failed: DB: Duplicate entry 'plugins.generic-pdfJsViewer-1-0-0-0' for key 'versions_pkey'

Rolling back the upgrade and examining the database, I don’t see how this is caused.
SELECT * FROM omp.versions WHERE product = "pdfJsViewer";
Gives me:
major,minor,revision,build,date_installed,current,product_type,product,product_class_name,lazy_load,sitewide
1,0,0,0,“2017-08-21 15:43:27”,1,plugins.generic,pdfJsViewer,PdfJsViewerPlugin,1,0
1,0,0,0,“2017-08-23 10:41:13”,1,plugins.viewableFiles,pdfJsViewer,PdfJsViewerPlugin,1,0

product_type is different, so the key should be different. Anyone an idea what causes this error?

Hi @dersmon,

You should be able to work around this by deleting the entry with product_type = 'plugins.viewableFiles' before running the upgrade.

Regards,
Alec Smecher
Public Knowledge Project Team

Thanks @asmecher, that worked, but now I have another one:

ERROR: Upgrade failed: DB: Duplicate entry '1--subjectsEnabledSubmission' for key 'press_settings_pkey'

SELECT * FROM omp.press_settings WHERE setting_name LIKE "subject%" ORDER BY setting_name ASC;

results in:

press_id,locale,setting_name,setting_value,setting_type
1,subjectEnabledSubmission,0,bool
1,subjectEnabledWorkflow,0,bool
1,subjectRequired,0,bool
1,subjectsEnabledSubmission,0,bool
1,subjectsEnabledWorkflow,0,bool
1,subjectsRequired,0,bool

I am working on a system I have not initially setup/maintained. Any idea how these inconsistencies came to be?

Thanks

Hi @dersmon,

Is it possible that an upgrade was attempted but failed, then another upgrade was attempted without first restoring from backup? When an upgrade fails, it leaves the database stuck somewhere between the two versions, and should be restored before another upgrade is attempted.

Regards,
Alec Smecher
Public Knowledge Project Team

So probably the last error is the result of an already added row that the migration script tries to add a second time?

I deleted the entry for subjectsEnabledSubmission and had to delete two other rows in press_settings, now the upgrade script succeeds. After the upgrade all rows were added again, so it really seems like a bugged upgrade attempt was the error.

1 Like