<commit_before>#!/usr/bin/env ruby

require "mystic"

module Mystic
  module SQL
    class Table
      def column(col_name, kind, opts={})
        self << Column.new({
          :name => col_name,
          :kind => kind.to_sym
        }.merge(opts))
      end
      
      def varchar(name, opts={})
        raise ArgumentError, "VARCHARs require a size." if opts[:size].nil?
        column(name, :varchar, opts)
      end
      
      def char(name, opts={})
        raise ArgumentError, "CHARs require a size." if opts[:size].nil?
        column(name, :char, opts)
      end

      def geometry(col_name, kind, srid, opts={})
        self << SpatialColumn.new({
          :name => col_name,
          :geom_kind => kind,
          :geom_srid => srid
        }.merge(opts)) unless opts.nil?
      end
      
      def index(*columns, opts={})
        opts[:columns] = opts[:columns].merge(columns) unless columns.empty?
        self << Index.new({ :tblname => @name }.merge(opts))
      end
      
      def method_missing(meth, *args, &block)
        column(args[0], meth.to_s, args[1])
      end  
    end
  end
  
  class Migration
    def execute(sql)
      Mystic.execute(sql)
    end
    
    def create_table(name)
      raise ArgumentError, "No block provided." unless block_given?
      table = Mystic::SQL::Table.new(name)
      yield(table)
      Mystic.execute(table.to_sql)
    end
    
    def drop_table(name)
      Mystic.execute("DROP TABLE #{name}")
    end
    
    def create_view(name, sql)<commit_msg>Fix Mystic::SQL::Table#index method invalid syntax<commit_after>#!/usr/bin/env ruby

require "mystic"

module Mystic
  module SQL
    class Table
      def column(col_name, kind, opts={})
        self << Column.new({
          :name => col_name,
          :kind => kind.to_sym
        }.merge(opts))
      end
      
      def varchar(name, opts={})
        raise ArgumentError, "VARCHARs require a size." if opts[:size].nil?
        column(name, :varchar, opts)
      end
      
      def char(name, opts={})
        raise ArgumentError, "CHARs require a size." if opts[:size].nil?
        column(name, :char, opts)
      end

      def geometry(col_name, kind, srid, opts={})
        self << SpatialColumn.new({
          :name => col_name,
          :geom_kind => kind,
          :geom_srid => srid
        }.merge(opts)) unless opts.nil?
      end
      
      def index(*cols)
        opts = cols.delete_at(-1) if cols.last.is_a?(Hash)
        opts ||= {}
        opts[:columns] = cols.concat(opts.delete(:columns) || [])
        self << Index.new({ :tblname => @name }.merge(opts))
      end
      
      def method_missing(meth, *args, &block)
        column(args[0], meth.to_s, args[1])
      end  
    end
  end
  
  class Migration
    def execute(sql)
      Mystic.execute(sql)
    end
    
    def create_table(name)
      raise ArgumentError, "No block provided." unless block_given?
      table = Mystic::SQL::Table.new(name)
      yield(table)
      Mystic.execute(table.to_sql)
    end
    
    def drop_table(name)
      Mystic.execute("DROP TABLE #{name}")
    end
    
    def create_view(name, sql)
{'fraction_non_alphanumeric': 0.12885777919185493, 'fraction_numerical': 0.001590836780146357, 'mean_word_length': 2.0823529411764707, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7462195', 'n_tokens_mistral': 1027, 'n_tokens_neox': 1008, 'n_words': 247}