Skip to content

Commit

Permalink
Merge pull request #9 from Root-App/pedro-add-drop-and-rebuild-from-sql
Browse files Browse the repository at this point in the history
Adds rebuild from sql method.
  • Loading branch information
pbcoronel authored Mar 20, 2018
2 parents 94e325e + f24d80c commit c2b4adb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/amazon/redshift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ def reload_from_sql(sql_string)
end
end

def rebuild_from_sql(sql_string)
count_before = count

@connection.transaction do
@connection.run(_sql_drop_table_statement)
@connection.run(_sql_create_table_as_statement(sql_string))

raise Sequel::Rollback if count < count_before
end
end

def unload_to_bucket(bucket, iam_role)
output_file = _generate_s3_unload_filename(bucket.url)
query = _s3_unload_statement(iam_role, output_file)
Expand Down Expand Up @@ -142,6 +153,15 @@ def _sql_insert_into_statement(sql_string)
"INSERT INTO #{@schema}.#{@table_name}
#{sql_string}"
end

def _sql_drop_table_statement
"DROP TABLE #{@schema}.#{@table_name}"
end

def _sql_create_table_as_statement(sql_string)
"CREATE TABLE #{@schema}.#{@table_name} AS
#{sql_string}"
end
end
end
end

0 comments on commit c2b4adb

Please sign in to comment.