/** * Is the specified table in the specified schema renamed? * * @param object $schema * @param object $table * return boolean */ public static function is_renamed_table($schema, $table) { if (!is_object($schema)) { throw new exception("schema is not an object"); } if (!is_object($table)) { throw new exception("table is not an object"); } // command line switch sanity if (dbsteward::$ignore_oldnames) { throw new exception("dbsteward::ignore_oldname option is on, is_renamed_table() should not be getting called"); } // if new_table['oldTableName'] is not defined, abort checks if (!isset($table['oldTableName'])) { return false; } // definition sanity checks if (format_schema::contains_table($schema, $table['oldTableName'])) { throw new Exception("oldTableName panic - new_schema " . $schema['name'] . " still contains table named " . $table['oldTableName']); } $old_schema = sql99_table::get_old_table_schema($schema, $table); if (!is_null($old_schema)) { if (!format_schema::contains_table($old_schema, $table['oldTableName'])) { throw new Exception("oldTableName panic - old_schema " . $old_schema['name'] . " does not contain table named " . $table['oldTableName']); } } // it is a new old named table rename if: // table['oldTableName'] exists in old schema // table['oldTableName'] does not exist in new schema if (format_schema::contains_table($old_schema, $table['oldTableName']) && !format_schema::contains_table($schema, $table['oldTableName'])) { dbsteward::info("NOTICE: " . $table['name'] . " used to be called " . $table['oldTableName']); return true; } return false; }
/** * 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"); } } } }