Skip to content

Instantly share code, notes, and snippets.

@kikeda1104
Created July 13, 2018 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikeda1104/cdafe195f8089af4a6a44344db03aa56 to your computer and use it in GitHub Desktop.
Save kikeda1104/cdafe195f8089af4a6a44344db03aa56 to your computer and use it in GitHub Desktop.
def call
@conn.exec(ERB.new(erb_template).result(binding))
end
private
def post_initialize(_args)
@conn = Database::Adapter.conn
end
def erb_template
<<-SQL
<% TABLES.each do |table| %>
begin transaction;
delete from <%= table %>
using <%= table %>_copy
where
<%= table %>.id = <%= table %>_copy.id;
insert into <%= table %>
select * from <%= table %>_copy;
end transaction;
<% end %>
SQL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment