Sha256: 3890b5b0230ca5717c95696b7a0ef856660de6ecfc49cacf03f086d3ad148590

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

#!/usr/bin/env ruby
require "data_sampler"
require "commander/import"
require "logger"

program :version, DataSampler::VERSION
program :description, 'Extract a sample of desired size from a database while ensuring referential integrity.'
default_command :sample

command :sample do |c|
  c.description = 'Extract a sample from the given connection'
  c.option '--adapter NAME', String, 'ActiveRecord adapter to use'
  c.option '--database NAME', String, 'Name of database to sample'
  c.option '--username USER', String, 'Username for connection'
  c.option '--password PASSWORD', String, 'Password for connection'
  c.option '--encoding ENCODING', String, 'Encoding for connection'
  c.option '--socket PATH', String, 'Socket for connection'
  c.option '--rows NUM', Integer, 'Number of rows to sample per table'
  c.option '--log PATH', String, 'Log queries to PATH'
  c.when_called do |args, options|
    options.default \
      :adapter  => 'mysql',
      :database => 'test',
      :username => 'root',
      :encoding => 'utf8',
      :rows     => 1000
    ActiveRecord::Base.logger = Logger.new(options.log) if options.log
    ActiveRecord::Base.establish_connection(options.__hash__).with_connection do |conn|
      puts DataSampler::Sample.new(conn, options.rows).to_sql
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
data_sampler-1.0.0 bin/data_sampler
data_sampler-0.0.6 bin/data_sampler
data_sampler-0.0.5 bin/data_sampler
data_sampler-0.0.4 bin/data_sampler