Sha256: 157df2a761d2221e9f20e6c853940957172ba0797e338d6130f5fd658f4baa13

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 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',
      :socket   => '/opt/local/var/run/mysql5/mysqld.sock',
      :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

3 entries across 3 versions & 1 rubygems

Version Path
data_sampler-0.0.3 bin/data_sampler
data_sampler-0.0.2 bin/data_sampler
data_sampler-0.0.1 bin/data_sampler