Commit 0bf0ec05 authored by MARGERY David's avatar MARGERY David
Browse files

Add rake tasks to manage the OAR2 database

parent 709c98db
......@@ -4,7 +4,7 @@ namespace :db do
namespace :oar do
desc "Load seed data into OAR2 database. Use an alternative seed file by setting the SEED environment variable."
task :seed do
fail "You should be executing this with RACK_ENV=test" unless Rails.env == "test"
fail "You should be executing this with RAILS_ENV=test or with SEED pointing to a file" unless Rails.env == "test" && !ENV.has_key?('SEED')
seed = ENV['SEED'] || File.expand_path("../../../spec/fixtures/oar2_2011-01-07.sql", __FILE__)
fail "Can't load seed file located at #{seed.inspect}" unless File.exist?(seed)
cmd = "PGPASSWORD=#{config['password']} psql -U #{config['username']} -h #{config['host']} -p #{config['port'] || 5432} #{config['database']} < \"#{seed}\""
......@@ -12,6 +12,19 @@ namespace :db do
system cmd
end
desc "Drop OAR2 database"
task :drop do
cmd = "export PGPASSWORD=#{config['password']} && dropdb -U #{config['username']} -h #{config['host']} -p #{config['port'] || 5432} #{config['database']}"
puts "Executing " + cmd
system cmd
end
desc "Create OAR2 database (requires sudo)"
task :create do
cmd = "sudo su -c \"createdb -O root oar2_test -E 'UTF8' -T template0\" postgres"
puts "Executing " + cmd
system cmd
end
end
end
......
......@@ -15,6 +15,7 @@ class development {
'oar2_dev':
ensure => present;
}
postgres::database {
'oar2_test':
ensure => present;
......@@ -24,9 +25,16 @@ class development {
user => postgres,
command => "/bin/echo \"CREATE USER root PASSWORD 'oar'; GRANT ALL PRIVILEGES ON *.oar2_dev TO 'root' ;GRANT ALL PRIVILEGES ON *.oar2_test TO 'root' ;\" | /usr/bin/psql ",
unless => "/bin/echo \"SELECT rolname FROM pg_roles;\" | /usr/bin/psql | grep root",
require => Service['postgresql']
require => [Service['postgresql'],Postgres::Database['oar2_test'],Postgres::Database['oar2_dev']]
}
exec{ "give ownership of oar2 databases to root":
user => postgres,
command => "/bin/echo \"ALTER DATABASE oar2_dev OWNER TO root; ALTER DATABASE oar2_test OWNER TO root;\" | /usr/bin/psql ",
unless => "/usr/bin/psql -l | grep oar2 | grep root",
require => Exec["allow connections to postgres for root"]
}
mysql::database {
'g5kapi_dev':
ensure => present;
......
class postgres {
package{
'postgresql':
['postgresql','postgresql-client']:
ensure => installed,
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment