<commit_before>module TotemActiverecord
  module ShellCmds
    class Db < Totem::ShellCmds::Base
      def run
        case @args[0]
        when 'create'    then create
        when 'drop'      then drop
        when 'migrate'   then migrateb
        when 'rollback'  then rollback
        when 'migration' then migration(@args[1])
        else
          puts_usage
        end
      end

      def create
        ActiveRecord::Base.establish_connection(TotemActiverecord.config.merge('database' => nil))
        ActiveRecord::Base.connection.create_database(TotemActiverecord.config['database'])
        ActiveRecord::Base.establish_connection(TotemActiverecord.config)

        return true
      end

      def drop
        ActiveRecord::Base.connection.drop_database(TotemActiverecord.config['database'])

        return true
      end

      def migrate
        ActiveRecord::Migration.verbose = true
        ActiveRecord::Migrator.migrate(TotemActiverecord.migrations_path)

        TotemActiverecord.reconnect

        return true
      end

      def rollback
        ActiveRecord::Migrator.rollback(TotemActiverecord.migrations_path, 1)
        TotemActiverecord.reconnect

        return true
      end

      def migration(name)
        if name.length == 0
          puts "ERROR: You must provide a name for the migration."
          puts
          puts_usage
          return
        end

        timestamp =  Time.now.utc.strftime("%Y%m%d%H%M%S")
        filename = "#{timestamp}_#{name}.rb"
        path = File.join(Totem.root, 'db', 'migrate', filename)
        content = "class #{name.camelize} < ActiveRecord::Migration\nend"

        puts "Creating migration: #{path}"
<commit_msg>Handle white space in migration names.<commit_after>module TotemActiverecord
  module ShellCmds
    class Db < Totem::ShellCmds::Base
      def run
        case @args[0]
        when 'create'    then create
        when 'drop'      then drop
        when 'migrate'   then migrateb
        when 'rollback'  then rollback
        when 'migration' then migration(@args[1])
        else
          puts_usage
        end
      end

      def create
        ActiveRecord::Base.establish_connection(TotemActiverecord.config.merge('database' => nil))
        ActiveRecord::Base.connection.create_database(TotemActiverecord.config['database'])
        ActiveRecord::Base.establish_connection(TotemActiverecord.config)

        return true
      end

      def drop
        ActiveRecord::Base.connection.drop_database(TotemActiverecord.config['database'])

        return true
      end

      def migrate
        ActiveRecord::Migration.verbose = true
        ActiveRecord::Migrator.migrate(TotemActiverecord.migrations_path)

        TotemActiverecord.reconnect

        return true
      end

      def rollback
        ActiveRecord::Migrator.rollback(TotemActiverecord.migrations_path, 1)
        TotemActiverecord.reconnect

        return true
      end

      def migration(name)
        if name.length == 0
          puts "ERROR: You must provide a name for the migration."
          puts
          puts_usage
          return
        end

        name = name.gsub(/\s/,'_')
        timestamp =  Time.now.utc.strftime("%Y%m%d%H%M%S")
        filename = "#{timestamp}_#{name}.rb"
        path = File.join(Totem.root, 'db', 'migrate', filename)
        content = "class #{name.camelize} < ActiveRecord::Migration\nend"

        puts "Creating migration: #{path}"

{'fraction_non_alphanumeric': 0.08877964141122036, 'fraction_numerical': 0.002313475997686524, 'mean_word_length': 2.31957773512476, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '2124886', 'n_tokens_mistral': 1027, 'n_tokens_neox': 964, 'n_words': 213}