Sha256: 7887f53b0c424401ce352009d60c3a50cf889f2403c5a41dbfa72c2b171dd455

Contents?: true

Size: 1.48 KB

Versions: 11

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module DataMigrate
  class StatusService
    class << self
      def dump(connection = ActiveRecord::Base.connection, stream = $stdout)
        new(connection).dump(stream)
        stream
      end
    end

    def initialize(connection)
      @connection = connection
    end

    def root_folder
      Rails.root
    end

    def dump(stream)
      output(stream)
    end

    private

    def table_name
      DataMigrate::RailsHelper.data_schema_migration.table_name
    end

    def output(stream)
      unless DataMigrate::RailsHelper.data_schema_migration.table_exists?
        stream.puts "Data migrations table does not exist yet."
        return
      end

      # output
      stream.puts "\ndatabase: #{database_name}\n\n"
      stream.puts "#{"Status".center(8)}  #{"Migration ID".ljust(14)}  Migration Name"
      stream.puts "-" * 50
      db_list.each do |status, version, name|
        stream.puts "#{status.center(8)}  #{version.ljust(14)}  #{name}"
      end
      stream.puts
    end

    def database_name
      if Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
        ActiveRecord::Base.connection_db_config.configuration_hash[:database]
      elsif Gem::Dependency.new("railties", "~> 6.1").match?("railties", Gem.loaded_specs["railties"].version)
        ActiveRecord::Base.connection_config[:database]
      end
    end

    def db_list
      DataMigrate::DataMigrator.migrations_status
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
data_migrate-11.2.0 lib/data_migrate/status_service.rb
data_migrate-11.1.0 lib/data_migrate/status_service.rb
data_migrate-11.0.0 lib/data_migrate/status_service.rb
data_migrate-11.0.0.rc3 lib/data_migrate/status_service.rb
data_migrate-11.0.0.rc lib/data_migrate/status_service.rb
data_migrate-9.4.4 lib/data_migrate/status_service.rb
data_migrate-9.4.2 lib/data_migrate/status_service.rb
data_migrate-9.4.1 lib/data_migrate/status_service.rb
data_migrate-9.4.0 lib/data_migrate/status_service.rb
data_migrate-9.3.0 lib/data_migrate/status_service.rb
data_migrate-9.2.0 lib/data_migrate/status_service.rb