Last active
July 13, 2018 08:42
-
-
Save kikeda1104/da6695ea9d9295cff6c714ec549bc7ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def call | |
@conn.exec(ERB.new(erb_template).result(binding)) | |
end | |
private | |
def post_initialize(args) | |
@iam_role = ENV['iam_role'] | |
@conn = Database::Adapter.conn | |
@directory = Model.to_s.underscore | |
@bucket_name = ENV['bucket_name'] | |
end | |
def erb_template | |
<<-SQL | |
<% TABLES.each do |table| %> | |
copy <%= table %>_copy | |
from 's3://<%= "#{bucket_name}/#{@directory}/#{id}" %>/<%= table %>.txt.' | |
iam_role '<%= @iam_role %>' | |
region 'ap-northeast-1' | |
blanksasnull | |
emptyasnull | |
GZIP | |
delimiter '\t' | |
NULL AS 'NULL' | |
; | |
<% end %> | |
SQL | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment