Generate forward operations for changing/creating SQL items.

def _generate_sql(self, keys, changed_keys):
        """
        Generate forward operations for changing/creating SQL items.
        """
        for key in reversed(keys):
            app_label, sql_name = key
            new_item = self.to_sql_graph.nodes[key]
            sql_deps = [n.key for n in self.to_sql_graph.node_map[key].parents]
            reverse_sql = new_item.reverse_sql

            if key in changed_keys:
                operation_cls = AlterSQL
                kwargs = {}
                # in case of replace mode, AlterSQL will hold sql, reverse_sql and
                # state_reverse_sql, the latter one will be used for building state forward
                # instead of reverse_sql.
                if new_item.replace:
                    kwargs['state_reverse_sql'] = reverse_sql
                    reverse_sql = self.from_sql_graph.nodes[key].sql
            else:
                operation_cls = CreateSQL
                kwargs = {'dependencies': list(sql_deps)}

            operation = operation_cls(
                sql_name, new_item.sql, reverse_sql=reverse_sql, **kwargs)
            sql_deps.append(key)
            self.add_sql_operation(app_label, sql_name, operation, sql_deps)