<commit_before>require "kingfisher/migration"

module Kingfisher
  class Migrator
    def initialize(config)
      @config = config
    end

    def run(reporter:)
      ensure_migrations_table_exists
      run_new_migrations(reporter)
    end

    private
    attr_reader :config

    def backend
      config.backend
    end

    def run_new_migrations(reporter)
      new_migrations.each do |migration|
        reporter.report "Migrating #{migration.name}"
        backend.migrate(migration)
      end
    end

    def new_migrations
      all_migrations.
        reject { |migration| migrated.include?(migration.version) }
    end

    def all_migrations
      Dir.
        glob("migrations/*").
        map { |dir| Migration.new(dir) }
    end

    def migrated
      backend.db[:__kingfisher_schema_migrations].map(:version)
    end

    def ensure_migrations_table_exists
      backend.ensure_migrations_table_exists
    end<commit_msg>Migrations should be in order<commit_after>require "kingfisher/migration"

module Kingfisher
  class Migrator
    def initialize(config)
      @config = config
    end

    def run(reporter:)
      ensure_migrations_table_exists
      run_new_migrations(reporter)
    end

    private
    attr_reader :config

    def backend
      config.backend
    end

    def run_new_migrations(reporter)
      new_migrations.each do |migration|
        reporter.report "Migrating #{migration.name}"
        backend.migrate(migration)
      end
    end

    def new_migrations
      all_migrations.
        reject { |migration| migrated.include?(migration.version) }
    end

    def all_migrations
      Dir.
        glob("migrations/*").
        sort.
        map { |dir| Migration.new(dir) }
    end

    def migrated
      backend.db[:__kingfisher_schema_migrations].map(:version)
    end

    def ensure_migrations_table_exists
      backend.ensure_migrations_table_exists
    end
{'fraction_non_alphanumeric': 0.06941544885177453, 'fraction_numerical': 0.0, 'mean_word_length': 2.583177570093458, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3713257', 'n_tokens_mistral': 597, 'n_tokens_neox': 600, 'n_words': 118}