/** * Outputs statements for creation of new triggers. * * @param writer writer the output should be written to * @param oldSchema original schema * @param newSchema new schema * @param searchPathHelper search path helper */ public static void createTriggers( final PrintWriter writer, final PgSchema oldSchema, final PgSchema newSchema, final SearchPathHelper searchPathHelper) { for (final PgTable newTable : newSchema.getTables()) { final PgTable oldTable; if (oldSchema == null) { oldTable = null; } else { oldTable = oldSchema.getTable(newTable.getName()); } // Add new triggers for (final PgTrigger trigger : getNewTriggers(oldTable, newTable)) { searchPathHelper.outputSearchPath(writer); writer.println(); writer.println(trigger.getCreationSQL()); } } }
/** * Outputs statements for dropping triggers. * * @param writer writer the output should be written to * @param oldSchema original schema * @param newSchema new schema * @param searchPathHelper search path helper */ public static void dropTriggers( final PrintWriter writer, final PgSchema oldSchema, final PgSchema newSchema, final SearchPathHelper searchPathHelper) { for (final PgTable newTable : newSchema.getTables()) { final PgTable oldTable; if (oldSchema == null) { oldTable = null; } else { oldTable = oldSchema.getTable(newTable.getName()); } // Drop triggers that no more exist or are modified for (final PgTrigger trigger : getDropTriggers(oldTable, newTable)) { searchPathHelper.outputSearchPath(writer); writer.println(); writer.println(trigger.getDropSQL()); } } }
/** * Outputs statements for trigger comments that have changed. * * @param writer writer * @param oldSchema old schema * @param newSchema new schema * @param searchPathHelper search path helper */ public static void alterComments( final PrintWriter writer, final PgSchema oldSchema, final PgSchema newSchema, final SearchPathHelper searchPathHelper) { if (oldSchema == null) { return; } for (PgTable oldTable : oldSchema.getTables()) { final PgTable newTable = newSchema.getTable(oldTable.getName()); if (newTable == null) { continue; } for (final PgTrigger oldTrigger : oldTable.getTriggers()) { final PgTrigger newTrigger = newTable.getTrigger(oldTrigger.getName()); if (newTrigger == null) { continue; } if (oldTrigger.getComment() == null && newTrigger.getComment() != null || oldTrigger.getComment() != null && newTrigger.getComment() != null && !oldTrigger.getComment().equals(newTrigger.getComment())) { searchPathHelper.outputSearchPath(writer); writer.println(); writer.print("COMMENT ON TRIGGER "); writer.print(PgDiffUtils.getQuotedName(newTrigger.getName())); writer.print(" ON "); writer.print(PgDiffUtils.getQuotedName(newTrigger.getTableName())); writer.print(" IS "); writer.print(newTrigger.getComment()); writer.println(';'); } else if (oldTrigger.getComment() != null && newTrigger.getComment() == null) { searchPathHelper.outputSearchPath(writer); writer.println(); writer.print("COMMENT ON TRIGGER "); writer.print(PgDiffUtils.getQuotedName(newTrigger.getName())); writer.print(" ON "); writer.print(PgDiffUtils.getQuotedName(newTrigger.getTableName())); writer.println(" IS NULL;"); } } } }