Class: Cheese::Postgresql

Inherits:
Object
  • Object
show all
Defined in:
lib/database/postgresql.rb

Overview

Create and remove postgresql databases

Constant Summary collapse

SILENCER =
">/dev/null 2>/dev/null"

Class Method Summary collapse

Class Method Details

.create(name) ⇒ Object

create a user and new db



9
10
11
12
13
14
15
16
# File 'lib/database/postgresql.rb', line 9

def self.create(name)
  while
    puts "We need to set a database password for #{name.gsub(".", "_")}."
  end
  
  %x{ su -c "createuser -S -D -R #{name.gsub(".", "_")} -W" postgres }
  %x{ su -c "createdb #{name.gsub(".", "_")}" postgres #{SILENCER} }
end

.remove(name) ⇒ Object

remove a user and new db



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

def self.remove(name)
  %x{ su -c "dropuser #{name.gsub(".", "_")}" postgres #{SILENCER} }
  %x{ su -c "dropdb #{name.gsub(".", "_")}" postgres #{SILENCER} }
end