Module: Sequel::Postgres::SchemaDataMethods

Defined in:
lib/sequel/extensions/pg_schema_data.rb

Instance Method Summary collapse

Instance Method Details

#dump_schema_data(schema, path, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sequel/extensions/pg_schema_data.rb', line 5

def dump_schema_data(schema, path, options={})
  FileUtils.rm_rf path
  FileUtils.mkpath path

  tables = self.from(Sequel[:information_schema][:tables])
               .where(table_schema: schema.to_s, table_type: 'BASE TABLE')
               .select_map(:table_name)
               .map(&:to_sym)

  tables = tables - options.fetch(:ignore, [])

  tables.each do |table|
    File.write File.join(path, "#{table}.csv"), copy_table(Sequel.qualify(schema, table), format: :csv)
  end
end

#load_schema_data(schema, path) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/sequel/extensions/pg_schema_data.rb', line 21

def load_schema_data(schema, path)
  transaction do
    Dir[File.join(path, '*.csv')].each do |filename|
      table = File.basename filename, '.csv'
      copy_into Sequel.qualify(schema, table), data: File.read(filename), format: :csv
    end
  end
end