public static function diff_constraints_table($ofs, $old_schema, $old_table, $new_schema, $new_table, $type, $drop_constraints = false) { pgsql8::set_context_replica_set_id($new_table); if ($drop_constraints) { // drop constraints that no longer exist or are modified foreach (self::get_drop_constraints($old_schema, $old_table, $new_schema, $new_table, $type) as $constraint) { $ofs->write(pgsql8_table::get_constraint_drop_sql($constraint) . "\n"); } } else { if (!dbsteward::$ignore_oldnames) { // if it is a renamed table if (pgsql8_diff_tables::is_renamed_table($new_schema, $new_table)) { // remove all constraints and recreate with new table name conventions foreach (pgsql8_constraint::get_table_constraints(dbsteward::$old_database, $old_schema, $old_table, $type) as $constraint) { // rewrite the constraint definer to refer to the new table name // so the constraint by the old name, but part of the new table // will be referenced properly in the drop statement $constraint['schema_name'] = $new_schema['name']; $constraint['table_name'] = $new_table['name']; $ofs->write(pgsql8_table::get_constraint_drop_sql($constraint) . "\n"); } // add all still-define constraints back and any new ones to the table foreach (pgsql8_constraint::get_table_constraints(dbsteward::$new_database, $new_schema, $new_table, $type) as $constraint) { $ofs->write(pgsql8_table::get_constraint_sql($constraint) . "\n"); } // this gets any new constraints as well. // return so that get_new_costraint() doesnt duplicate any new constraints return; } } // add new constraints foreach (self::get_new_constraints($old_schema, $old_table, $new_schema, $new_table, $type) as $constraint) { $ofs->write(pgsql8_table::get_constraint_sql($constraint) . "\n"); } } }