class ActiveRecord::Snapshot::FilterTables

Attributes

sql_dump[R]
tables[R]

Public Class Methods

call(*args) click to toggle source
# File lib/active_record/snapshot/commands/filter_tables.rb, line 4
def self.call(*args)
  new(*args).call
end
new(tables:, sql_dump:) click to toggle source
# File lib/active_record/snapshot/commands/filter_tables.rb, line 8
def initialize(tables:, sql_dump:)
  @tables = tables
  @sql_dump = sql_dump
end

Public Instance Methods

call() click to toggle source
# File lib/active_record/snapshot/commands/filter_tables.rb, line 13
def call
  tables.each(&method(:extract_table))
  unify_tables
end

Private Instance Methods

extract_table(table) click to toggle source
# File lib/active_record/snapshot/commands/filter_tables.rb, line 26
      def extract_table(table)
        system(<<~SH)
          sed -ne \\
            '/Table structure for table `#{table}`/,/Table structure for table/p' \\
            #{sql_dump} \\
            > #{table_file(table)}
        SH
      end
table_file(table) click to toggle source
# File lib/active_record/snapshot/commands/filter_tables.rb, line 22
def table_file(table)
  ActiveRecord::Snapshot.config.store.tmp.join("#{table}.sql").to_s
end
unify_tables() click to toggle source
# File lib/active_record/snapshot/commands/filter_tables.rb, line 35
def unify_tables
  all = tables.map(&method(:table_file))
  system("cat #{all.join(" ")} > #{sql_dump}") && FileUtils.rm(all)
end