public static function get_multiple_create_bits($node_schema, $node_table, $constraints)
 {
     $bits = array();
     foreach ($constraints as $constraint) {
         $bits[] = mysql5_constraint::get_constraint_sql($constraint, FALSE);
         if (strcasecmp($constraint['type'], 'PRIMARY KEY') == 0) {
             // we're adding the PK constraint, so we need to add AUTO_INCREMENT on any affected columns immediately after!
             $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, TRUE);
                     break;
                     // there can only be one AI column per table
                 }
             }
         }
     }
     return $bits;
 }
    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));
    }