Exemplo n.º 1
0
 /**
  * Adds a column to the table object
  * @param string $column_name
  * @param string $type
  * @param array $options
  */
 public function add_column($column_name, $type, $options = array())
 {
     $defaults = array('limit' => NULL, 'precision' => NULL, 'scale' => NULL);
     $options = array_merge($defaults, $options);
     $add_column_sql = Migration::quote_column_name($column_name) . ' ' . Migration::type_to_sql($type, $options['limit'], $options['precision'], $options['scale']);
     $add_column_sql = Migration::add_column_options($add_column_sql, $options);
     array_push($this->columns, $add_column_sql);
 }
Exemplo n.º 2
0
 public function change($column, $options = array())
 {
     //MODIFY [column] column options
     foreach (array('limit', 'precision', 'scale') as $key) {
         $options[$key] = isset($options[$key]) ? $options[$key] : '';
     }
     if (isset($options['type']) && !empty($options['type'])) {
         $type = $options['type'];
     } else {
         $type = \ActivePhp\Base::select_one("SHOW COLUMNS FROM " . $this->quoted_table_name . " LIKE '{$column}'");
         $type = $type["Type"];
     }
     $sql = $this->alter_table_sql() . 'MODIFY COLUMN ' . Migration::quote_column_name($column) . ' ' . Migration::type_to_sql($type, $options['limit'], $options['precision'], $options['scale']);
     $sql = Migration::add_column_options($sql, $options, true);
     array_push($this->columns, $sql);
 }