Bug 1503179

Summary: Liquibase migration fails when activation keys referencing missing products exist
Product: [Community] Candlepin Reporter: Barnaby Court <bcourt>
Component: candlepinAssignee: candlepin-bugs
Status: CLOSED CURRENTRELEASE QA Contact: Katello QA List <katello-qa-list>
Severity: high Docs Contact:
Priority: high    
Version: 2.2CC: bcourt, csnyder, katello-qa-list, lzap, redakkan, skallesh
Target Milestone: ---Keywords: Triaged
Target Release: 2.1   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: candlepin-2.1.7-1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1503176 Environment:
Last Closed: 2017-10-19 18:07:00 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1503176    
Bug Blocks: 1503177    

Description Barnaby Court 2017-10-17 14:00:32 UTC
+++ This bug was initially created as a clone of Bug #1503176 +++

Description of problem:

When migrating from 0.9.54 to 2.x, if a database has activation keys that are referencing products that have been deleted, the migration will fail.  The failure occurs in PerOrgsProductsMigrationTask due to the presence of the records in cp_activationkey_product that reference the missing products.

Version-Release number of selected component (if applicable): 2.x series

How reproducible: Always

Steps to Reproduce:
1. Starting with 0.9.54, create an activation key using a productId that does not exist.
2. Attempt to migrate to candlepin 2.0.

liquibase --driver=org.postgresql.Driver --classpath=/usr/share/java/postgresql-jdbc.jar:/var/lib/tomcat/webapps/candlepin/WEB-INF/classes/ --changeLogFile=db/changelog/changelog-update.xml --url=jdbc:postgresql:candlepin --username=candlepin  --password=<PASSWORD> migrate -Dcommunity=False

Actual results:

Liquibase update Failed: Migration failed for change set db/changelog/20150210094558-perorgproducts-phase-1.xml::20150210094558-35::crog:
     Reason: liquibase.exception.UnexpectedLiquibaseException: liquibase.exception.CustomChangeException: liquibase.exception.DatabaseException: One or more orgs failed data validation

Expected results:

Successful migration