Class: Brillo::Adapter::Postgres
- Defined in:
- lib/brillo/adapter/postgres.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #load_command ⇒ Object
- #recreate_db ⇒ Object
-
#table_footer(klass) ⇒ Object
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.
Methods inherited from Base
#dump_structure_and_migrations, #footer, #header, #initialize
Methods included from Logger
Constructor Details
This class inherits a constructor from Brillo::Adapter::Base
Instance Method Details
#load_command ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/brillo/adapter/postgres.rb', line 4 def load_command host = config["host"] ? "--host #{config["host"]}" : "" password = config["password"] ? "PGPASSWORD=#{config["password"]} " : "" search_path = config["schema_search_path"] ? "PGOPTIONS=--search_path=#{config["schema_search_path"]} " : "" = password + search_path "#{}psql #{host} -U #{config.fetch("username")} #{config.fetch("database")}" end |
#recreate_db ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/brillo/adapter/postgres.rb', line 22 def recreate_db logger.info "Dropping all connections to #{config[:database]}" ActiveRecord::Base.connection.execute( <<-SQL -- Disconnect all others from the database we are about to drop. -- Without this, the drop will fail and so the load will abort. SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '#{config[:database]}' AND pid <> pg_backend_pid(); SQL ) super end |
#table_footer(klass) ⇒ Object
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
14 15 16 17 18 19 20 |
# File 'lib/brillo/adapter/postgres.rb', line 14 def (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 |