Module: Support::Database

Defined in:
lib/tasks/support/database.rb

Class Method Summary (collapse)

Class Method Details

+ (Boolean) pg_database_exists?

This doesn't actually say if the database exists or not!

Try it, load a console, drop the database in another terminal, and call this method.

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
# File 'lib/tasks/support/database.rb', line 31

def self.pg_database_exists?
  begin
    ActiveRecord::Base.connection
   # ActiveRecord::Base.connection.disconnect!
  rescue ActiveRecord::NoDatabaseError
    false
  else
    true
  end
end

+ (Object) pg_dump(database_name, table_name, data_directory, dump_filename = nil)

Dump a specific table from a database.



5
6
7
8
9
# File 'lib/tasks/support/database.rb', line 5

def self.pg_dump(database_name, table_name, data_directory, dump_filename = nil)
  dump_filename ||= "/#{table_name}.dump"
  `pg_dump -Fc -t #{table_name} -a #{database_name} -f #{File.join(data_directory, dump_filename)}`
  $?.to_i
end

+ (Object) pg_dump_all(database_name, data_directory, dump_filename)



19
20
21
22
# File 'lib/tasks/support/database.rb', line 19

def self.pg_dump_all(database_name, data_directory, dump_filename)
  `pg_dump -Fc -a #{database_name} -f #{File.join(data_directory, dump_filename)}`
  $?.to_i
end

+ (Object) pg_restore(database_name, table_name, data_directory, dump_filename = nil)

For example:

pg_restore -Fc -d taxonworks_development -t geographic_area_types ~/src/gaz/data/internal/dump/geographic_area_types.dump


13
14
15
16
17
# File 'lib/tasks/support/database.rb', line 13

def self.pg_restore(database_name, table_name, data_directory, dump_filename = nil)
  dump_filename ||= "/#{table_name}.dump"
  `pg_restore -Fc -d #{database_name} -t #{table_name} #{File.join(data_directory, dump_filename)}`
  $?.to_i
end

+ (Object) pg_restore_all(database_name, data_directory, dump_filename)



24
25
26
27
# File 'lib/tasks/support/database.rb', line 24

def self.pg_restore_all(database_name, data_directory, dump_filename)
  `pg_restore -Fc -d #{database_name} #{File.join(data_directory, dump_filename)}`
  $?.to_i
end