Beispiel #1
0
 /**
  * Does the specified constraint depend on a table
  * that has been renamed in the specified database definition?
  * 
  * @param object $db_doc
  * @param object $constraint
  * @return boolean
  * @throws exception
  */
 public static function constraint_depends_on_renamed_table($db_doc, $constraint)
 {
     if (dbsteward::$ignore_oldnames) {
         // don't check if ignore_oldnames is on
         return FALSE;
     }
     if (strpos($constraint['definition'], 'REFERENCES') !== FALSE) {
         //echo $constraint['schema_name'] . "." . $constraint['table_name'] . "  " . $constraint['name'] . " definition = " . $constraint['definition'] . "\n";
         if (preg_match(static::PATTERN_CONSTRAINT_REFERENCES_TABLE, $constraint['definition'], $matches) > 0) {
             $references_schema_name = $matches[1];
             $references_table_name = $matches[2];
         } else {
             throw new exception("Failed to parse REFERENCES definition for renamed table dependencies");
         }
         $references_schema = dbx::get_schema($db_doc, $references_schema_name);
         if (!$references_schema) {
             throw new exception("constraint references schema '" . $references_schema_name . "' not found in specified db_doc, check caller");
         }
         $references_table = dbx::get_table($references_schema, $references_table_name);
         if (!$references_table) {
             throw new exception("constraint references table '" . $references_table_name . "' not found in specified db_doc, schema " . $references_schema_name . ", check caller");
         }
         if (sql99_diff_tables::is_renamed_table($references_schema, $references_table)) {
             dbsteward::info("NOTICE: constraint " . $constraint['name'] . " for " . $constraint['schema_name'] . "." . $constraint['table_name'] . " references a renamed table -- " . $constraint['definition']);
             return TRUE;
         }
     }
     return FALSE;
 }
 public static function is_renamed_table($schema, $table)
 {
     // a table is also considered renamed if it was moved
     return parent::is_renamed_table($schema, $table) || self::is_moved_table($schema, $table);
 }
Beispiel #3
0
 /**
  * Sanity check table renaming pointers if they have been specified
  * 
  * @param object $old_schema
  * @param object $old_table
  * @param object $new_schema
  * @param object $new_table
  * @throws exception
  */
 public static function renamed_table_check_pointer(&$old_schema, &$old_table, $new_schema, $new_table)
 {
     if (!dbsteward::$ignore_oldnames) {
         if ($new_schema && $new_table && sql99_diff_tables::is_renamed_table($new_schema, $new_table)) {
             if (isset($new_table['oldSchemaName'])) {
                 if (!($old_schema = sql99_table::get_old_table_schema($new_schema, $new_table))) {
                     throw new exception("Sanity failure: " . $new_table['name'] . " has oldSchemaName attribute, but old_schema not found");
                 }
             } else {
                 if (!$old_schema) {
                     throw new exception("Sanity failure: " . $new_table['name'] . " has oldTableName attribute, but passed old_schema is not defined");
                 }
             }
             $old_table = sql99_table::get_old_table($new_schema, $new_table);
             if (!$old_table) {
                 throw new exception("Sanity failure: " . $new_table['name'] . " has oldTableName attribute, but table point not found");
             }
         }
     }
 }