コード例 #1
0
    public function testQuoteFKeyTable()
    {
        $xml = <<<XML
<dbsteward>
<schema name="test">
  <table name="test1">
    <column name="col1" type="int" />
  </table>
  <table name="test2">
    <column name="col1" foreignSchema="test" foreignTable="test1" foreignColumn="col1"/>
  </table>
</schema>
</dbsteward>
XML;
        $db_doc = simplexml_load_string($xml);
        $constraints = pgsql8_constraint::get_table_constraints($db_doc, $db_doc->schema, $db_doc->schema->table[1], 'foreignKey');
        $sql = trim(pgsql8_table::get_constraint_sql_change_statement($constraints[0]));
        $expected = 'ADD CONSTRAINT "test2_col1_fkey" FOREIGN KEY ("col1") REFERENCES "test"."test1" ("col1")';
        $this->assertEquals($expected, $sql);
    }
コード例 #2
0
 /**
  * Returns list of constraints that should be added.
  *
  * @param old_table original table
  * @param new_table new table
  * @param type whether primary keys should be processed or other constraints should be processed
  *
  * @return list of constraints that should be added
  */
 private static function get_new_constraints($old_schema, $old_table, $new_schema, $new_table, $type)
 {
     $list = array();
     if ($new_table != null) {
         if ($old_table == null) {
             foreach (pgsql8_constraint::get_table_constraints(dbsteward::$new_database, $new_schema, $new_table, $type) as $constraint) {
                 $list[] = $constraint;
             }
         } else {
             foreach (pgsql8_constraint::get_table_constraints(dbsteward::$new_database, $new_schema, $new_table, $type) as $constraint) {
                 $old_constraint = pgsql8_constraint::get_table_constraint(dbsteward::$old_database, $old_schema, $old_table, $constraint['name']);
                 if (!pgsql8_table::contains_constraint(dbsteward::$old_database, $old_schema, $old_table, $constraint['name']) || !pgsql8_table::constraint_equals($old_constraint, $constraint) || pgsql8_table::constraint_depends_on_renamed_table(dbsteward::$new_database, $constraint)) {
                     $list[] = $constraint;
                 }
             }
         }
     }
     return $list;
 }