From cd726937f61be195a68e90599b83762db2e7a079 Mon Sep 17 00:00:00 2001 From: Thomas Schank Date: Thu, 9 Mar 2023 18:37:05 +0100 Subject: [PATCH] Fix data restore and truncate for newer rails versions * ignore ar_internal_metadata similar to schema_migrations --- lib/pg_tasks.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pg_tasks.rb b/lib/pg_tasks.rb index 3e62e48..bcb0937 100644 --- a/lib/pg_tasks.rb +++ b/lib/pg_tasks.rb @@ -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 @@ -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