private List < DropForeignKeyConstraintChange > generateChildren ( Database database ) { // Make a new list List < DropForeignKeyConstraintChange > childDropChanges = new ArrayList <> ( ) ; try { SnapshotControl control = new SnapshotControl ( database ) ; control . getTypesToInclude ( ) . add ( ForeignKey . class ) ; CatalogAndSchema catalogAndSchema = new CatalogAndSchema ( getBaseTableCatalogName ( ) , getBaseTableSchemaName ( ) ) ; catalogAndSchema = catalogAndSchema . standardize ( database ) ; Table target = SnapshotGeneratorFactory . getInstance ( ) . createSnapshot ( new Table ( catalogAndSchema . getCatalogName ( ) , catalogAndSchema . getSchemaName ( ) , database . correctObjectName ( getBaseTableName ( ) , Table . class ) ) , database ) ; List < ForeignKey > results = ( ( target == null ) ? null : target . getOutgoingForeignKeys ( ) ) ; Set < String > handledConstraints = new HashSet <> ( ) ; if ( ( results != null ) && ( ! results . isEmpty ( ) ) ) { for ( ForeignKey fk : results ) { Table baseTable = fk . getForeignKeyTable ( ) ; String constraintName = fk . getName ( ) ; if ( DatabaseObjectComparatorFactory . getInstance ( ) . isSameObject ( baseTable , target , null , database ) ) { if ( ! handledConstraints . contains ( constraintName ) ) { DropForeignKeyConstraintChange dropForeignKeyConstraintChange = new DropForeignKeyConstraintChange ( ) ; dropForeignKeyConstraintChange . setBaseTableSchemaName ( getBaseTableSchemaName ( ) ) ; dropForeignKeyConstraintChange . setBaseTableName ( baseTableName ) ; dropForeignKeyConstraintChange . setConstraintName ( constraintName ) ; childDropChanges . add ( dropForeignKeyConstraintChange ) ; handledConstraints . add ( constraintName ) ; } } else { throw new UnexpectedLiquibaseException ( "Expected to return only foreign keys for base table name: " + getBaseTableName ( ) + " and got results for table: " + baseTableName ) ; } } } return childDropChanges ; } catch ( DatabaseException | InvalidExampleException e ) { throw new UnexpectedLiquibaseException ( "Failed to find foreign keys for table: " + getBaseTableName ( ) , e ) ; } }
Iterates through all the FOREIGN KEYs of the target table and outputs a list of DropForeignKeyConstraintChanges for a given database type .