public static function get_multiple_drop_sql($node_schema, $node_table, $constraints)
 {
     if (count($constraints) == 0) {
         return '';
     }
     $bits = array();
     foreach ($constraints as $constraint) {
         if (strcasecmp($constraint['type'], 'PRIMARY KEY') == 0) {
             // we're dropping the PK constraint, so we need to drop AUTO_INCREMENT on any affected columns first!
             $columns = mysql5_table::primary_key_columns($node_table);
             foreach ($columns as $col) {
                 $node_column = dbx::get_table_column($node_table, $col);
                 if (mysql5_column::is_auto_increment($node_column['type'])) {
                     $bits[] = "MODIFY " . mysql5_column::get_full_definition(dbsteward::$new_database, $node_schema, $node_table, $node_column, FALSE, TRUE, FALSE);
                     break;
                     // there can only be one AI column per table
                 }
             }
         }
         $bits[] = mysql5_constraint::get_constraint_drop_sql($constraint, FALSE);
     }
     $table = mysql5::get_fully_qualified_table_name($node_schema['name'], $node_table['name']);
     return "ALTER TABLE {$table}\n  " . implode(",\n  ", $bits) . ";\n";
 }
    public function testUnique()
    {
        $xml = <<<XML
<dbsteward>
<schema name="public" owner="NOBODY">
  <table name="test" primaryKey="test_id">
    <column name="test_id" type="serial"/>
    <constraint name="test_unique" type="Unique" definition="(`test_id`)"/>
  </table>
</schema>
</dbsteward>
XML;
        $dbs = new SimpleXMLElement($xml);
        $constraints = mysql5_constraint::get_table_constraints($dbs, $dbs->schema, $dbs->schema->table[0]);
        // should contain primary key and unique
        $this->assertEquals(2, count($constraints));
        $this->assertEquals('PRIMARY KEY', $constraints[0]['type']);
        $this->assertEquals('UNIQUE', $constraints[1]['type']);
        $unique = $constraints[1];
        $expected = array('name' => 'test_unique', 'schema_name' => 'public', 'table_name' => 'test', 'type' => 'UNIQUE', 'definition' => '(`test_id`)');
        $this->assertEquals($expected, $unique);
        $expected = "ALTER TABLE `test` ADD UNIQUE INDEX `test_unique` (`test_id`);";
        $this->assertEquals($expected, mysql5_constraint::get_constraint_sql($unique));
        $expected = "ALTER TABLE `test` DROP INDEX `test_unique`;";
        $this->assertEquals($expected, mysql5_constraint::get_constraint_drop_sql($unique));
    }