Moves i18n columns from the main table to the i18n table
552247
protected function moveI18nColumns()
    {
        $table     = $this->getTable();
        $i18nTable = $this->i18nTable;

        $i18nValidateParams = [];
        foreach ($this->getI18nColumnNamesFromConfig() as $columnName) {
            if (!$i18nTable->hasColumn($columnName)) {
                if (!$table->hasColumn($columnName)) {
                    throw new EngineException(sprintf('No column named %s found in table %s', $columnName, $table->getName()));
                }

                $column = $table->getColumn($columnName);
                $i18nTable->addColumn(clone $column);

                // validate behavior: move rules associated to the column
                if ($table->hasBehavior('validate')) {
                    $validateBehavior = $table->getBehavior('validate');
                    $params = $validateBehavior->getParametersFromColumnName($columnName);
                    $i18nValidateParams = array_merge($i18nValidateParams, $params);
                    $validateBehavior->removeParametersFromColumnName($columnName);
                }
                // FIXME: also move FKs, and indices on this column
            }

            if ($table->hasColumn($columnName)) {
                $table->removeColumn($columnName);
            }
        }

        // validate behavior
        if (count($i18nValidateParams) > 0) {
            $i18nVbehavior = new ValidateBehavior();
            $i18nVbehavior->setName('validate');
            $i18nVbehavior->setParameters($i18nValidateParams);
            $i18nTable->addBehavior($i18nVbehavior);

            // current table must have almost 1 validation rule
            $validate = $table->getBehavior('validate');
            $validate->addRuleOnPk();
        }
    }
301011
public function up()
    {
        Schema::create('translator_translations', function ($table) {
            $table->increments('id');
            $table->string('locale', 6);
            $table->string('namespace')->default('*');
            $table->string('group');
            $table->string('item');
            $table->text('text');
            $table->boolean('unstable')->default(false);
            $table->boolean('locked')->default(false);
            $table->timestamps();
            $table->foreign('locale')->references('locale')->on('translator_languages');
            $table->unique(['locale', 'namespace', 'group', 'item']);
        });
    }
924650
def migrate1():
    ""

    initial = [
    "create table Chill (version integer);",
    "insert into Chill (version) values (1);",
    "alter table SelectSQL rename to Query;",
    "alter table Node add column template integer references Template (id) on delete set null;",
    "alter table Node add column query integer references Query (id) on delete set null;"
    ]


    cleanup = [
    "drop table SelectSQL_Node;",
    "drop table Template_Node;"
    ]

    c = db.cursor()
    try:
        c.execute("select version from Chill limit 1;")
    except sqlite3.DatabaseError as err:
        pass
    result = c.fetchone()
    if result:
        version = result[0]
        if version == 1:
            current_app.logger.warn("Migration from version 0 to 1 is not needed.")
        else:
            current_app.logger.warn("Migration from version 0 to {0} is not supported.".format(version))
        return

    try:
        for query in initial:
            c.execute(query)
    except sqlite3.DatabaseError as err:
        current_app.logger.error("DatabaseError: %s", err)

    try:
        c.execute(fetch_query_string('select_all_nodes.sql'))
    except sqlite3.DatabaseError as err:
        current_app.logger.error("DatabaseError: %s", err)
    result = c.fetchall()
    if result:
        (result, col_names) = rowify(result, c.description)
        for kw in result:

            try:
                c.execute("""
                update Node set template = (
                select t.id from Template as t
                join Template_Node as tn on ( tn.template_id = t.id )
                join Node as n on ( n.id = tn.node_id )
                where n.id is :node_id
                group by t.id)
                where id is :node_id;
                """, {'node_id':kw['id']})
            except sqlite3.DatabaseError as err:
                current_app.logger.error("DatabaseError: %s", err)

            try:
                c.execute("""
                update Node set query = (
                select s.id from Query as s
                join SelectSQL_Node as sn on ( sn.selectsql_id = s.id )
                join Node as n on ( n.id = sn.node_id )
                where n.id is :node_id
                group by s.id)
                where id is :node_id;
                """, {'node_id':kw['id']})
            except sqlite3.DatabaseError as err:
                current_app.logger.error("DatabaseError: %s", err)
    try:
        for query in cleanup:
            c.execute(query)
    except sqlite3.DatabaseError as err:
        current_app.logger.error("DatabaseError: %s", err)

    db.commit()
623955
public function up()
	{
		if(Schema::hasColumn('001_017_text', 'lang_017'))
		{
			$key = DB::select(DB::raw('SHOW KEYS FROM 001_017_text WHERE Key_name=\'fk01_001_017_text\''));

			if($key != null)
			{
				Schema::table('001_017_text', function (Blueprint $table) {
					$table->dropForeign('fk01_001_017_text');
					$table->dropIndex('fk01_001_017_text');
				});

				Schema::table('001_017_text', function (Blueprint $table) {
					// rename column, function renameColumn doesn't work
					DB::select(DB::raw('ALTER TABLE 001_017_text CHANGE lang_017 lang_id_017 VARCHAR(2) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL'));
					$table->foreign('lang_id_017', 'fk01_001_017_text')->references('id_001')->on('001_001_lang')
						->onDelete('restrict')->onUpdate('cascade');
				});
			}
		}
	}
566592
def _transform_columns(component, inner)
      col_count = component.parent.elements.size

      small_val = component.attr('small')
      large_val = component.attr('large')

      small_size = small_val || column_count
      large_size = large_val || small_val || (column_count / col_count).to_i

      classes = _combine_classes(component, "small-#{small_size} large-#{large_size} columns")

      classes << ' first' unless component.previous_element
      classes << ' last' unless component.next_element

      subrows = component.elements.css(".row").to_a.concat(component.elements.css("row").to_a)
      expander = %{<th class="expander"></th>} if large_size.to_i == column_count && subrows.empty?

      %{<#{INTERIM_TH_TAG} class="#{classes}" #{_pass_through_attributes(component)}><table><tr><th>#{inner}</th>#{expander}</tr></table></#{INTERIM_TH_TAG}>}
    end
1028865
def set_trans(self, trans_vec):
        """"""

        # Column major,  translation components in column 3.
        self.data[3][0] = trans_vec[0]
        self.data[3][1] = trans_vec[1]
        self.data[3][2] = trans_vec[2]
893226
def resizeColumnsToContents(self):
        """"""
        self._autosized_cols = set()
        self._resizeColumnsToContents(self.table_level,
                                      self.table_index, self._max_autosize_ms)
        self._update_layout()
828134
def change_column(column_name, definition)
      attributes = column_attributes(column_name, definition)
      migration.change_column(*attributes)
    end
1015453
protected function translateDelete()
    {
        $build = 'delete from ' . $this->escapeTable(false);

        // build the where statements
        if ($wheres = $this->attr('wheres'))
        {
            $build .= $this->translateWhere($wheres);
        }
    
        // build offset and limit
        if ($this->attr('limit'))
        {
             $build .= $this->translateLimit();
        }

        return $build;
    }
1033755
def to_tables(cols):
  
  tables = OrderedDict()
  for col in cols:
    tname = col["table_name"]
    if tname not in tables:
      tables[tname] = OrderedDict()
    tables[tname][col["column_name"]] = col
  return tables
645199
protected function translateJoins()
    {
        $build = '';

        foreach ($this->attr('joins') as $join) 
        {
            // get the type and table
            $type = $join[0]; $table = $join[1];

            // table 
            if (is_array($table)) 
            {
                reset($table);

                // the table might be a subselect so check that
                // first and compile the select if it is one
                if ($table[key($table)] instanceof Select)
                {
                    $translator = new static;

                    // translate the subselect
                    list($subQuery, $subQueryParameters) = $translator->translate($table[key($table)]);

                    // merge the parameters
                    foreach($subQueryParameters as $parameter)
                    {
                        $this->addParameter($parameter);
                    }

                    return '(' . $subQuery . ') as ' . $this->escape(key($table));
                }
            }

            // start the join
            $build .= ' ' . $type . ' join ' . $this->escape($table) . ' on ';

            // to make nested join conditions possible you can pass an closure
            // wich will create a new query where you can add your nested ons and wheres
            if (!isset($join[3]) && isset($join[2]) && $join[2] instanceof BaseQuery) 
            {
                $subAttributes = $join[2]->attributes();

                $joinConditions = '';

                // remove the first type from the ons
                reset($subAttributes['ons']);
                $subAttributes['ons'][key($subAttributes['ons'])][0] = '';

                foreach($subAttributes['ons'] as $on)
                {
                    list($type, $localKey, $operator, $referenceKey) = $on;
                    $joinConditions .= ' ' . $type . ' ' . $this->escape($localKey) . ' ' . $operator . ' ' . $this->escape($referenceKey);
                }

                $build .= trim($joinConditions);

                // compile the where if set
                if (!empty($subAttributes['wheres']))
                {
                    $build .= ' and ' . substr($this->translateWhere($subAttributes['wheres']), 7);
                }
            }
            else
            {
                // othewise default join
                list($type, $table, $localKey, $operator, $referenceKey) = $join;
                $build .= $this->escape($localKey) . ' ' . $operator . ' ' . $this->escape($referenceKey);
            }
        }

        return $build;
    }
97035
function flattenTranslations(translations) {
  var toReturn = {};

  for (var i in translations) {
    // check if the property is present
    if (!translations.hasOwnProperty(i)) {
      continue;
    } // get the type of the property


    var objType = _typeof(translations[i]); // allow unflattened array of strings


    if (isArray(translations[i])) {
      var count = translations[i].length;

      for (var index = 0; index < count; index++) {
        var itemType = _typeof(translations[i][index]);

        if (itemType !== 'string') {
          console.warn('i18n:', 'currently only arrays of strings are fully supported', translations[i]);
          break;
        }
      }

      toReturn[i] = translations[i];
    } else if (objType == 'object' && objType !== null) {
      var flatObject = flattenTranslations(translations[i]);

      for (var x in flatObject) {
        if (!flatObject.hasOwnProperty(x)) continue;
        toReturn[i + '.' + x] = flatObject[x];
      }
    } else {
      toReturn[i] = translations[i];
    }
  }

  return toReturn;
}
547436
function (name, generator, options) {
            options = options || {};
            var engine = options.engine, charset = options.charset, collate = options.collate;
            if (isUndefined(engine)) {
                engine = this._static.defaultEngine;
            }
            if (isUndefined(charset)) {
                charset = this._static.defaultCharset;
            }
            if (isUndefined(collate)) {
                collate = this._static.defaultCollate;
            }
            generator.columns.forEach(function (c) {
                var t = c.table;
                if (t) {
                    delete c.table;
                    generator.foreignKey([c.name], t, merge({}, c, {name: null, type: "foreignKey"}));
                }
            });
            return format(" %s%s%s%s", this._super(arguments), engine ? " ENGINE=" + engine : "",
                charset ? " DEFAULT CHARSET=" + charset : "", collate ? " DEFAULT COLLATE=" + collate : "");
        }
298625
public function change()
    {
        $table = $this->table('languages');
        $table->addColumn('is_rtl', 'boolean', [
            'default' => false,
            'null' => false,
        ]);
        $table->addColumn('trashed', 'datetime', [
            'default' => null,
            'null' => true,
        ]);
        $table->changeColumn('is_active', 'boolean', [
            'default' => true,
            'null' => false,
        ]);
        $table->renameColumn('short_code', 'code');
        $table->removeColumn('description');
        $table->update();
    }
163184
private function populateTranslations()
    {
        //translations
        $aRelated = $this->owner->getRelatedRecords();
        if (isset($aRelated[$this->relation]) && $aRelated[$this->relation] != null) {
            if (is_array($aRelated[$this->relation])) {
                foreach ($aRelated[$this->relation] as $model) {
                    $this->_models[$model->getAttribute($this->languageField)] = $model;
                }
            } else {
                $model = $aRelated[$this->relation];
                $this->_models[$model->getAttribute($this->languageField)] = $model;
            }
        }
    }
1204026
def append_translated(model, fields):
    ""
    fields = set(fields)
    from modeltranslation.translator import translator
    opts = translator.get_options_for_model(model)
    for key, translated in opts.fields.items():
        if key in fields:
            fields = fields.union(f.name for f in translated)
    return fields
827295
def rename_column(self, model, old_name, new_name):
        """"""
        field = model._meta.fields[old_name]
        if isinstance(field, pw.ForeignKeyField):
            old_name = field.column_name
        self.__del_field__(model, field)
        field.name = field.column_name = new_name
        model._meta.add_field(new_name, field)
        if isinstance(field, pw.ForeignKeyField):
            field.column_name = new_name = field.column_name + '_id'
        self.ops.append(self.migrator.rename_column(model._meta.table_name, old_name, new_name))
        return model