/** * 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"); } } } }
public static function is_renamed_column($old_table, $new_table, $new_column) { if (!is_object($old_table)) { throw new exception("old_table is not an object"); } if (!is_object($new_table)) { throw new exception("new_table is not an object"); } if (!is_object($new_column)) { throw new exception("new_column is not an object"); } // command line switch sanity first and foremost if (dbsteward::$ignore_oldnames) { throw new exception("dbsteward::ignore_oldname option is on, is_renamed_column() should not be getting called"); } $case_sensitive = FALSE; if (dbsteward::$quote_column_names || dbsteward::$quote_all_names || strcasecmp('mysql5', dbsteward::get_sql_format()) == 0) { // do case-sensitive check $new_colname = (string) $new_column['name']; foreach ($old_table->column as $old_column) { $old_colname = (string) $old_column['name']; if (strcasecmp($old_colname, $new_colname) === 0) { if ($old_colname != $new_colname && !isset($new_column['oldColumnName'])) { throw new Exception("Ambiguous operation! It looks like column name case changed between old_column {$old_table['name']}.{$old_colname} and new_column {$new_table['name']}.{$new_colname}"); } break; } } $case_sensitive = TRUE; } // if new_column['oldColumnName'] is not defined, abort checks if (!isset($new_column['oldColumnName'])) { return false; } // definition sanity checks if (sql99_table::contains_column($new_table, $new_column['oldColumnName'], $case_sensitive)) { throw new Exception("oldColumnName panic - table " . $new_table['name'] . " still contains column named " . $new_column['oldColumnName']); } if (!sql99_table::contains_column($old_table, $new_column['oldColumnName'], $case_sensitive)) { throw new Exception("oldColumnName panic - table " . $old_table['name'] . " does not contain column named " . $new_column['oldColumnName']); } // it is a new old named table rename if: // new_column['oldColumnName'] exists in old schema // new_column['oldColumnName'] does not exist in new schema if (sql99_table::contains_column($old_table, $new_column['oldColumnName'], $case_sensitive) && !sql99_table::contains_column($new_table, $new_column['oldColumnName'], $case_sensitive)) { return true; } return false; }
/** * Retrieves an associative array of table options defined for a table * @param SimpleXMLElement $node_schema The schema * @param SimpleXMLElement $node_table The table * @return array Option name => option value */ public static function get_table_options($node_schema, $node_table) { $opts = parent::get_table_options($node_schema, $node_table); if (!mysql5::$use_auto_increment_table_options && array_key_exists('auto_increment', $opts)) { dbsteward::warning('WARNING: Ignoring auto_increment tableOption on table ' . mysql5::get_fully_qualified_table_name($node_schema['name'], $node_table['name'])); dbsteward::warning(' Setting the auto_increment value is unreliable. If you want to use it, pass the --useautoincrementoptions commandline flag'); unset($opts['auto_increment']); } return $opts; }