Class: Brillo::Adapter::Postgres

Inherits:
Base
  • Object
show all
Defined in:
lib/brillo/adapter/postgres.rb

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#dump_structure_and_migrations, #footer, #header, #initialize

Constructor Details

This class inherits a constructor from Brillo::Adapter::Base

Instance Method Details

#load_commandObject



4
5
6
7
8
# File 'lib/brillo/adapter/postgres.rb', line 4

def load_command
  host = config[:host] ? "--host #{config[:host]}" : ""
  password = config[:password] ? "PGPASSWORD=#{config[:password]} " : ""
  "#{password}psql #{host} -U #{config[:username]} #{config[:database]}"
end

pgdump without schema does not set sequences, so we have to do it ourselves, or the first insert into a scrubbed table will fail on duplicate primary key



12
13
14
15
16
17
18
# File 'lib/brillo/adapter/postgres.rb', line 12

def table_footer(klass)
  table_name = klass.table_name
  <<-SQL
    SELECT setval(pg_get_serial_sequence('#{table_name}', 'id'), coalesce(MAX(id),0) + 1, false)
    FROM #{table_name};
  SQL
end