class RedshiftCopier::Copy

Attributes

aws_access_key_id[R]
aws_secret_access_key[R]
copy_command_options[R]
create_sql[R]
db_config[R]
s3_path[R]
schema[R]
table[R]

Public Class Methods

new(args) click to toggle source
# File lib/redshift_copier/copy.rb, line 5
def initialize(args)
  @schema = args.fetch(:schema)
  @table = args.fetch(:table)
  @create_sql = args.fetch(:create_sql)
  @aws_access_key_id = args.fetch(:aws_access_key_id)
  @aws_secret_access_key = args.fetch(:aws_secret_access_key)
  @s3_path = args.fetch(:s3_path)
  @db_config = args.fetch(:db_config)
  @copy_command_options = args.fetch(:copy_command_options, "dateformat 'auto' timeformat 'auto' blanksasnull emptyasnull escape removequotes delimiter ',' ignoreheader 1;")
end

Public Instance Methods

run() click to toggle source
# File lib/redshift_copier/copy.rb, line 16
def run
  drop
  create
  copy
end

Private Instance Methods

connection() click to toggle source
# File lib/redshift_copier/copy.rb, line 50
def connection
  PGconn.connect(db_config)
end
copy() click to toggle source
# File lib/redshift_copier/copy.rb, line 46
def copy
  connection.exec(copy_sql)
end
copy_sql() click to toggle source
# File lib/redshift_copier/copy.rb, line 36
def copy_sql
  "copy #{schema}.#{table} from '#{s3_path}'"\
  " credentials '#{credentials}'"\
  " #{copy_command_options}"
end
create() click to toggle source
# File lib/redshift_copier/copy.rb, line 32
def create
  connection.exec(create_sql)
end
credentials() click to toggle source
# File lib/redshift_copier/copy.rb, line 42
def credentials
  "aws_access_key_id=#{aws_access_key_id};aws_secret_access_key=#{aws_secret_access_key}"
end
drop() click to toggle source
# File lib/redshift_copier/copy.rb, line 24
def drop
  connection.exec(drop_sql)
end
drop_sql() click to toggle source
# File lib/redshift_copier/copy.rb, line 28
def drop_sql
  "drop table if exists #{schema}.#{table};"
end