Ejemplo n.º 1
0
 /**
  * Returns true if table contains given index $name, otherwise false.
  *
  * @param $name  name of the index
  *
  * @return true  if table contains given index $name, otherwise false
  */
 public static function contains_index($node_schema, $node_table, $name)
 {
     $found = false;
     $indexes = format_index::get_table_indexes($node_schema, $node_table);
     foreach ($indexes as $index) {
         if (strcasecmp($index['name'], $name) == 0) {
             $found = true;
             break;
         }
     }
     return $found;
 }
 public static function diff_indexes_table($ofs, $old_schema, $old_table, $new_schema, $new_table)
 {
     // Drop indexes that do not exist in new schema or are modified
     foreach (self::get_drop_indexes($old_schema, $old_table, $new_schema, $new_table) as $index) {
         $ofs->write(mssql10_index::get_drop_sql($new_schema, $new_table, $index));
     }
     // Add new indexes
     if ($old_schema == NULL) {
         foreach (format_index::get_table_indexes($new_schema, $new_table) as $index) {
             $ofs->write(mssql10_index::get_creation_sql($new_schema, $new_table, $index) . "\n");
         }
     } else {
         foreach (self::get_new_indexes($old_schema, $old_table, $new_schema, $new_table) as $index) {
             $ofs->write(mssql10_index::get_creation_sql($new_schema, $new_table, $index) . "\n");
         }
     }
 }
Ejemplo n.º 3
0
 public static function diff_indexes_table_bits($old_schema, $old_table, $new_schema, $new_table)
 {
     $bits = array();
     // Drop indexes that do not exist in new schema or are modified
     foreach (static::get_drop_indexes($old_schema, $old_table, $new_schema, $new_table) as $index) {
         $bits[] = format_index::get_alter_drop_sql($new_schema, $new_table, $index);
     }
     // Add new indexes
     if ($old_schema == null) {
         foreach (format_index::get_table_indexes($new_schema, $new_table) as $index) {
             $bits[] = format_index::get_alter_add_sql($new_schema, $new_table, $index);
         }
     } else {
         foreach (static::get_new_indexes($old_schema, $old_table, $new_schema, $new_table) as $index) {
             $bits[] = format_index::get_alter_add_sql($new_schema, $new_table, $index);
         }
     }
     return $bits;
 }
Ejemplo n.º 4
0
 public static function get_table_index($node_schema, $node_table, $name)
 {
     $indexes = format_index::get_table_indexes($node_schema, $node_table);
     $return_index = NULL;
     foreach ($indexes as $index) {
         if (strcasecmp($index['name'], $name) == 0) {
             if ($return_index === NULL) {
                 $return_index = $index;
             } else {
                 throw new exception("more than one table " . $node_schema['name'] . '.' . $node_table['name'] . " index called " . $name . " found");
             }
         }
     }
     return $return_index;
 }
Ejemplo n.º 5
0
 public static function get_primary_key_name($node_table)
 {
     if (!empty($node_table['primaryKeyName'])) {
         return dbsteward::string_cast($node_table['primaryKeyName']);
     } else {
         return format_index::index_name($node_table['name'], NULL, 'pkey');
     }
 }
Ejemplo n.º 6
0
 /**
  * Returns list of indexes that should be added.
  *
  * @param old_table original table
  * @param new_table new table
  *
  * @return list of indexes that should be added
  */
 public static function get_new_indexes($old_schema, $old_table, $new_schema, $new_table)
 {
     $list = array();
     if ($new_table != null) {
         if ($old_table == null) {
             foreach (format_index::get_table_indexes($new_schema, $new_table) as $index) {
                 $list[] = $index;
             }
         } else {
             foreach (format_index::get_table_indexes($new_schema, $new_table) as $index) {
                 $old_index = dbx::get_table_index($old_schema, $old_table, $index['name']);
                 if (!pgsql8_table::contains_index($old_schema, $old_table, $index['name'])) {
                     $list[] = $index;
                 } else {
                     if (!pgsql8_index::equals($old_index, $index)) {
                         $list[] = $index;
                     }
                 }
             }
         }
     }
     return $list;
 }