Module: Moonshadow::Manifest::Rails::Postgresql
- Included in:
- Moonshadow::Manifest::Rails
- Defined in:
- lib/moonshadow/manifest/rails/postgresql.rb
Overview
To use PostgreSQL, add the following recipes calls to your manifest:
recipe :postgresql_server, :postgresql_gem, :postgresql_user, :postgresql_database
Instance Method Summary collapse
-
#postgresql_database ⇒ Object
Create the database from the current
database_environment
. -
#postgresql_gem ⇒ Object
Install the
pg
rubygem and dependencies. -
#postgresql_server ⇒ Object
Installs
postgresql
from apt and enables thepostgresql
service. -
#postgresql_user ⇒ Object
Grant the database user specified in the current
database_environment
permisson to access the database with the supplied password.
Instance Method Details
#postgresql_database ⇒ Object
Create the database from the current database_environment
58 59 60 61 62 63 64 65 66 |
# File 'lib/moonshadow/manifest/rails/postgresql.rb', line 58 def postgresql_database exec "postgresql_database", :command => "/usr/bin/createdb -O #{database_environment[:username]} #{database_environment[:database]}", :unless => "/usr/bin/psql -l | grep #{database_environment[:database]}", :user => 'postgres', :require => exec('postgresql_user'), :before => exec('rake tasks'), :notify => exec('rails_bootstrap') end |
#postgresql_gem ⇒ Object
Install the pg
rubygem and dependencies
43 44 45 46 |
# File 'lib/moonshadow/manifest/rails/postgresql.rb', line 43 def postgresql_gem gem 'pg' gem 'postgres' end |
#postgresql_server ⇒ Object
Installs postgresql
from apt and enables the postgresql
service.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/moonshadow/manifest/rails/postgresql.rb', line 9 def postgresql_server package 'postgresql', :ensure => :installed package 'postgresql-client', :ensure => :installed package 'postgresql-contrib', :ensure => :installed package 'libpq-dev', :ensure => :installed service 'postgresql-8.3', :ensure => :running, :hasstatus => true, :require => [ package('postgresql'), package('postgres'), package('pg') ] #ensure the postgresql key is present on the configuration hash configure(:postgresql => {}) file '/etc/postgresql/8.3/main/pg_hba.conf', :ensure => :present, :content => template(File.join(File.dirname(__FILE__), 'templates', 'pg_hba.conf.erb')), :require => package('postgresql'), :mode => '600', :owner => 'postgres', :group => 'postgres', :notify => service('postgresql-8.3') file '/etc/postgresql/8.3/main/postgresql.conf', :ensure => :present, :content => template(File.join(File.dirname(__FILE__), 'templates', 'postgresql.conf.erb')), :require => package('postgresql'), :mode => '600', :owner => 'postgres', :group => 'postgres', :notify => service('postgresql-8.3') end |
#postgresql_user ⇒ Object
Grant the database user specified in the current database_environment
permisson to access the database with the supplied password
50 51 52 53 54 55 |
# File 'lib/moonshadow/manifest/rails/postgresql.rb', line 50 def postgresql_user psql "CREATE USER #{database_environment[:username]} WITH PASSWORD '#{database_environment[:password]}'", :alias => "postgresql_user", :unless => psql_query('\\\\du') + "| grep #{database_environment[:username]}", :require => service('postgresql-8.3') end |