Skip to content

Commit

Permalink
Fix data restore and truncate for newer rails versions
Browse files Browse the repository at this point in the history
* ignore ar_internal_metadata similar to schema_migrations
  • Loading branch information
DrTom committed Mar 9, 2023
1 parent 2447979 commit cd72693
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/pg_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class << self

def truncate_tables
ActiveRecord::Base.connection.tap do |connection|
connection.tables.reject { |tn| tn == 'schema_migrations' }
connection.tables.reject{|tn| tn == 'schema_migrations'}
.reject{|tn| tn == 'ar_internal_metadata'}
.join(', ').tap do |tables|
connection.execute " TRUNCATE TABLE #{tables} CASCADE; "
end
Expand Down Expand Up @@ -83,9 +84,12 @@ def data_restore(filename)
shell_filename= Shellwords.escape filename.to_s
list_cmd = "pg_restore -l #{shell_filename}"
pg_list = `#{list_cmd}`
binding.pry
raise "Command #{list_cmd} failed " if $?.exitstatus != 0
restore_list = pg_list.split(/\n/) \
.reject{|l| l =~ /TABLE DATA .* schema_migrations/}.join("\n")
.reject{|l| l =~ /TABLE DATA .* schema_migrations/}
.reject{|l| l =~ /TABLE DATA .* ar_internal_metadata/}
.join("\n")
begin
restore_list_file = Tempfile.new 'pg_restore_list'
restore_list_file.write restore_list
Expand Down

0 comments on commit cd72693

Please sign in to comment.