Changeset ::20110825-1000-creating-providers-for-persons-from-encounter::raff fails

I have made upgrades in the past from 1.6.x to 1.11.x which were successful, however for one of the most recent upgrades i am now working on, i have fallen into

Caused by: liquibase.exception.MigrationFailedException: Migration failed for change set liquibase-update-to-latest.xml::20110825-1000-migrating-providers-to-encounter-provider::raff:

which is as a result of the above failing Changeset;

At first i thought it was my MySQL version (5.6, provided by MariaDB 10.0) but found out it is not. I am manually editing this SQL through MySQL client to use insert ignore to avoid checking for duplicates, since it fails in this manner even when there was no entries in encounter_provider after which i manually delete provider_id column from encounter table to skip these two consecutive change-sets.

Is this a personal problem or within the changeset @raff?

You need to provide more of the stack trace.

As a way of troubleshooting, execute the select statement alone without the insert and locate the duplicate records. This will help refine the next steps.

Wondering why distinct keyword can’t handle this!!! i couldn’t see such duplicates easily when i was troubleshooting this so i skipped them with insert ignore

It needs an additional correlated subquery to ensure the rows to insert do not exist already. The distinct clause simply removes duplicates from the select.

insert into encounter_provider(provider_id, encounter_id, encounter_role_id, creator, date_created, voided, uuid) 
select distinct provider.provider_id, encounter.encounter_id, encounter_role.encounter_role_id, 
	  encounter.creator, encounter.date_created, encounter.voided, encounter.uuid
from encounter as encounter inner join encounter_role as encounter_role 
	on encounter_role.uuid = "a0b03050-c99b-11e0-9572-0800200c9a66"
	inner join provider as provider on encounter.provider_id = provider.person_id
where encounter.encounter_id not in (select encounter_id from encounter_provider) AND
                   NOT EXISTS (SELECT 1 from encounter_provider ep
                               WHERE  ep.provider_id = provider.provider_id AND
                                      ep.encounter_id = encounter.encounter_id AND
                                      ep.encounter_role_id = encounter_role.encounter_role_id )
1 Like