<commit_before>class Combustion::Database
  def self.setup
    silence_stream(STDOUT) do
      reset_database
      load_schema
      migrate
    end
  end

  def self.reset_database
    abcs = ActiveRecord::Base.configurations
    case abcs['test']['adapter']
    when /mysql/
      ActiveRecord::Base.establish_connection(:test)
      ActiveRecord::Base.connection.recreate_database(abcs['test']['database'],
        mysql_creation_options(abcs['test']))
      ActiveRecord::Base.establish_connection(:test)
    when /postgresql/
      ActiveRecord::Base.clear_active_connections!
      drop_database(abcs['test'])
      create_database(abcs['test'])
    when /sqlite/
      dbfile = abcs['test']['database'] || abcs['test']['dbfile']
      File.delete(dbfile) if File.exist?(dbfile)
    when 'sqlserver'
      test = abcs.deep_dup['test']
      test_database = test['database']
      test['database'] = 'master'
      ActiveRecord::Base.establish_connection(test)
      ActiveRecord::Base.connection.recreate_database!(test_database)
    when "oci", "oracle"
      ActiveRecord::Base.establish_connection(:test)
      ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
        ActiveRecord::Base.connection.execute(ddl)
      end
    when 'firebird'
      ActiveRecord::Base.establish_connection(:test)
      ActiveRecord::Base.connection.recreate_database!
    else
      raise "Cannot reset databases for '#{abcs['test']['adapter']}'"
    end
  end

  def self.load_schema
    load "#{Rails.root}/db/schema.rb"
  end

  def self.migrate
    migrator = ActiveRecord::Migrator
    paths    = 'db/migrate/'

    if migrator.respond_to?(:migrations_paths)
      paths    = migrator.migrations_paths
    end

    migrator.migrate paths, nil
  end

  private
<commit_msg>Correctly drop the test db when using sqlite. Include internal/db/migrate migrations in the mix when we run migrations.<commit_after>class Combustion::Database
  def self.setup
    silence_stream(STDOUT) do
      reset_database
      load_schema
      migrate
    end
  end

  def self.reset_database
    abcs = ActiveRecord::Base.configurations
    case abcs['test']['adapter']
    when /mysql/
      ActiveRecord::Base.establish_connection(:test)
      ActiveRecord::Base.connection.recreate_database(abcs['test']['database'],
        mysql_creation_options(abcs['test']))
      ActiveRecord::Base.establish_connection(:test)
    when /postgresql/
      ActiveRecord::Base.clear_active_connections!
      drop_database(abcs['test'])
      create_database(abcs['test'])
    when /sqlite/
      drop_database(abcs['test'])
      create_database(abcs['test'])
    when 'sqlserver'
      test = abcs.deep_dup['test']
      test_database = test['database']
      test['database'] = 'master'
      ActiveRecord::Base.establish_connection(test)
      ActiveRecord::Base.connection.recreate_database!(test_database)
    when "oci", "oracle"
      ActiveRecord::Base.establish_connection(:test)
      ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
        ActiveRecord::Base.connection.execute(ddl)
      end
    when 'firebird'
      ActiveRecord::Base.establish_connection(:test)
      ActiveRecord::Base.connection.recreate_database!
    else
      raise "Cannot reset databases for '#{abcs['test']['adapter']}'"
    end
  end

  def self.load_schema
    load "#{Rails.root}/db/schema.rb"
  end

  def self.migrate
    migrator = ActiveRecord::Migrator
    paths    = Array('db/migrate/')

    if migrator.respond_to?(:migrations_paths)
      paths = migrator.migrations_paths
    end
    # Append the migrations inside the internal app's db/migrate directory
    paths << File.join(Rails.root, 'db/migrate')
    migrator.migrate paths, nil
  end

  private

{'fraction_non_alphanumeric': 0.11897191308956015, 'fraction_numerical': 0.0, 'mean_word_length': 3.5481927710843375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5293971', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1142, 'n_words': 205}