Sha256: b458a52a3248f0da22e7ef9987e45763ae09de93c283ddb7dc74d76afae6ac50

Contents?: true

Size: 1.26 KB

Versions: 11

Compression:

Stored size: 1.26 KB

Contents

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::DataSchemaMigration.table_name
    end

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

      # output
      if ActiveRecord.version >= Gem::Version.new('7.0')
        stream.puts "\ndatabase: #{ActiveRecord::Base.connection_db_config.configuration_hash[:database]}\n\n"
      else
        stream.puts "\ndatabase: #{ActiveRecord::Base.connection_config[:database]}\n\n"
      end
      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 db_list
      DataMigrate::DataMigrator.migrations_status
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
data_migrate-9.0.0 lib/data_migrate/status_service_five.rb
data_migrate-8.5.0 lib/data_migrate/status_service_five.rb
data_migrate-8.4.2 lib/data_migrate/status_service_five.rb
data_migrate-8.4.1 lib/data_migrate/status_service_five.rb
data_migrate-8.4.0 lib/data_migrate/status_service_five.rb
data_migrate-8.3.0 lib/data_migrate/status_service_five.rb
data_migrate-8.2.0 lib/data_migrate/status_service_five.rb
data_migrate-8.1.1 lib/data_migrate/status_service_five.rb
data_migrate-8.1.0 lib/data_migrate/status_service_five.rb
data_migrate-8.0.0 lib/data_migrate/status_service_five.rb
data_migrate-8.0.0.rc2 lib/data_migrate/status_service_five.rb