Module: UffDbLoader::Postgresql

Defined in:
lib/uff_db_loader/postgresql.rb

Class Method Summary collapse

Class Method Details

.create_database(database_name) ⇒ Object



29
30
31
# File 'lib/uff_db_loader/postgresql.rb', line 29

def self.create_database(database_name)
  ActiveRecord::Base.connection.execute("CREATE DATABASE #{database_name};")
end

.default_restore_commandObject



17
18
19
# File 'lib/uff_db_loader/postgresql.rb', line 17

def self.default_restore_command
  "pg_restore"
end

.drop_database(database_name) ⇒ Object



33
34
35
# File 'lib/uff_db_loader/postgresql.rb', line 33

def self.drop_database(database_name)
  ActiveRecord::Base.connection.execute("DROP DATABASE IF EXISTS #{database_name};")
end

.dump_command_templateObject



9
10
11
# File 'lib/uff_db_loader/postgresql.rb', line 9

def self.dump_command_template
  "ssh %user%@%host% \"docker exec -i %container_name% sh -c 'exec pg_dump --username \\$POSTGRES_USER --no-owner --no-acl --format=c %database%'\" > %target%"
end

.dump_extensionObject



5
6
7
# File 'lib/uff_db_loader/postgresql.rb', line 5

def self.dump_extension
  "dump"
end

.list_databasesObject



21
22
23
24
25
26
27
# File 'lib/uff_db_loader/postgresql.rb', line 21

def self.list_databases
  ActiveRecord::Base
    .connection
    .execute("SELECT datname FROM pg_database;")
    .values
    .flatten
end

.restore_command_templateObject



13
14
15
# File 'lib/uff_db_loader/postgresql.rb', line 13

def self.restore_command_template
  "%command% --username postgres --no-owner --no-acl --dbname %database% %file%"
end