/**
  * @todo should *all* sequences be dropped in stage3, rather than just the shim?
  *       the only reason we don't is because pgsql8 drops in stage 1...
  */
 public static function diff_sequences($ofs1, $ofs3, $old_schema, $new_schema)
 {
     $new_sequences = static::get_sequences($new_schema);
     if ($old_schema != null) {
         $old_sequences = static::get_sequences($old_schema);
     } else {
         $old_sequences = array();
     }
     if (empty($new_sequences)) {
         // there are no sequences in the new schema, so if there used to be sequences,
         // we can just drop the whole shim table
         if (!empty($old_sequences)) {
             $ofs3->write(mysql5_sequence::get_shim_drop_sql());
         }
     } else {
         // there *are* sequences in the new schema, so if there didn't used to be,
         // we need to add the shim in before adding any sequences
         if (empty($old_sequences)) {
             $ofs1->write(mysql5_sequence::get_shim_creation_sql() . "\n\n");
             $ofs1->write(mysql5_sequence::get_creation_sql($new_schema, $new_sequences) . "\n");
         } else {
             // there were schemas in the old schema
             $common_sequences = array();
             // only drop sequences not in the new schema
             $to_drop = array();
             foreach ($old_sequences as $old_seq) {
                 if (static::schema_contains_sequence($new_schema, $old_seq['name'], true)) {
                     // if the sequence *is* in the new schema, then it might have changed
                     $common_sequences[(string) $old_seq['name']] = $old_seq;
                 } else {
                     $to_drop[] = $old_seq;
                 }
             }
             if (!empty($to_drop)) {
                 $ofs1->write(mysql5_sequence::get_drop_sql($old_schema, $to_drop) . "\n\n");
             }
             // only add sequences not in the old schema
             $to_insert = array();
             foreach ($new_sequences as $new_seq) {
                 if (static::schema_contains_sequence($old_schema, $new_seq['name'])) {
                     // there used to be a sequence named $new_seq['name']
                     self::diff_single($ofs1, $common_sequences[(string) $new_seq['name']], $new_seq);
                 } elseif (!dbsteward::$ignore_oldnames && !empty($new_seq['oldSequenceName']) && static::schema_contains_sequence($old_schema, $new_seq['oldSequenceName'])) {
                     // there used to be a sequence named $new_seq['oldSequenceName']
                     self::diff_single($ofs1, $common_sequences[(string) $new_seq['oldSequenceName']], $new_seq);
                 } else {
                     $to_insert[] = $new_seq;
                 }
             }
             if (!empty($to_insert)) {
                 $ofs1->write(mysql5_sequence::get_creation_sql($new_schema, $to_insert) . "\n");
             }
         }
     }
 }
 private function setup_shim()
 {
     $this->pdo->exec($sql = mysql5_sequence::get_shim_drop_sql());
     // echo $sql . "\n\n";
     $this->pdo->exec($sql = mysql5_sequence::get_shim_creation_sql());
     // echo $sql . "\n\n";
 }