Class: PgMigrate::Util
- Inherits:
-
Object
- Object
- PgMigrate::Util
- Defined in:
- lib/pg_migrate/util.rb
Constant Summary collapse
- LOGGER =
Logging.logger[self]
Class Method Summary collapse
-
.create_conn(args) ⇒ Object
recommended to create all connections via this method, so that we can put NOTICE/CONTEXT into logger instead of stderr.
- .get_conn(connection_options) ⇒ Object
-
.get_db_name(connection_options) ⇒ Object
finds dbname from connection_options.
-
.get_oob_conn(connection_options) ⇒ Object
the ‘out-of-band’ conn is a connection to a database that you aren’t interested in modifying; it’s basically a landing pad so that you can do: DROP DATABSE BLAH; CREATE DATABASE BLAH – for testing.
Class Method Details
.create_conn(args) ⇒ Object
recommended to create all connections via this method, so that we can put NOTICE/CONTEXT into logger instead of stderr
9 10 11 12 13 14 15 16 |
# File 'lib/pg_migrate/util.rb', line 9 def self.create_conn(args) conn = PG::Connection.open(args) conn.set_notice_receiver do |result| #result.res_status(result.result_status) LOGGER.debug result. end return conn end |
.get_conn(connection_options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pg_migrate/util.rb', line 18 def self.get_conn() if ![:pgconn].nil? return [:pgconn] elsif ![:connstring].nil? create_conn([:connstring]) elsif ![:connopts].nil? return create_conn([:connopts]) else return create_conn() end end |
.get_db_name(connection_options) ⇒ Object
finds dbname from connection_options
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pg_migrate/util.rb', line 47 def self.get_db_name() dbname = nil if ![:pgconn].nil? dbname = [:pgconn].db elsif ![:connstring].nil? connstring = [:connstring] bits = connstring.split(" ") bits.each do |bit| if bit.start_with? "dbname=" dbname = bit["dbname=".length..-1] break end end elsif ![:connopts].nil? dbname = [:connopts]["dbname"] else dbname = ["dbname"] end if dbname.nil? raise "db name is null. tried finding dbname in #{connection_options.inspect}" end return dbname end |
.get_oob_conn(connection_options) ⇒ Object
the ‘out-of-band’ conn is a connection to a database that you aren’t interested in modifying; it’s basically a landing pad so that you can do: DROP DATABSE BLAH; CREATE DATABASE BLAH – for testing
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pg_migrate/util.rb', line 33 def self.get_oob_conn() if ![:oob_pgconn].nil? return [:oob_pgconn] elsif ![:oob_connstring].nil? return create_conn([:oob_connstring]) elsif ![:oob_connopts].nil? return create_conn([:oob_connopts]) else return create_conn() end end |